diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
index bfdebe3f9..57f73df40 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
@@ -49,21 +49,29 @@ public final class ContentType {
private static final String APPLICATION = "application";
private static final String TEXT = "text";
private static final String MULTIPART = "multipart";
-
+
+ public static final String PARAMETER_CHARSET = "charset";
+ public static final String PARAMETER_IEEE754_COMPATIBLE = "IEEE754Compatible";
+ public static final String PARAMETER_ODATA_METADATA = "odata.metadata";
+
+ public static final String VALUE_ODATA_METADATA_NONE = "none";
+ public static final String VALUE_ODATA_METADATA_MINIMAL = "minimal";
+ public static final String VALUE_ODATA_METADATA_FULL = "full";
+
public static final ContentType APPLICATION_JSON = new ContentType(APPLICATION, "json", null);
- public static final ContentType JSON = ContentType.create(ContentType.APPLICATION_JSON, "odata.metadata=minimal");
- public static final ContentType JSON_NO_METADATA = ContentType.create(ContentType.APPLICATION_JSON,
- "odata.metadata=none");
- public static final ContentType JSON_FULL_METADATA = ContentType.create(ContentType.APPLICATION_JSON,
- "odata.metadata=full");
-
+ public static final ContentType JSON = ContentType.create(ContentType.APPLICATION_JSON,
+ PARAMETER_ODATA_METADATA + '=' + VALUE_ODATA_METADATA_MINIMAL);
+ public static final ContentType JSON_NO_METADATA = ContentType.create(ContentType.APPLICATION_JSON,
+ PARAMETER_ODATA_METADATA + '=' + VALUE_ODATA_METADATA_NONE);
+ public static final ContentType JSON_FULL_METADATA = ContentType.create(ContentType.APPLICATION_JSON,
+ PARAMETER_ODATA_METADATA + '=' + VALUE_ODATA_METADATA_FULL);
+
public static final ContentType APPLICATION_XML = new ContentType(APPLICATION, "xml", null);
public static final ContentType APPLICATION_ATOM_XML = new ContentType(APPLICATION, "atom+xml", null);
public static final ContentType APPLICATION_ATOM_XML_ENTRY = create(APPLICATION_ATOM_XML, "type=entry");
public static final ContentType APPLICATION_ATOM_XML_FEED = create(APPLICATION_ATOM_XML, "type=feed");
public static final ContentType APPLICATION_ATOM_SVC = new ContentType(APPLICATION, "atomsvc+xml", null);
-
public static final ContentType APPLICATION_OCTET_STREAM = new ContentType(APPLICATION, "octet-stream", null);
public static final ContentType APPLICATION_XHTML_XML = new ContentType(APPLICATION, "xhtml+xml", null);
@@ -81,14 +89,6 @@ public final class ContentType {
public static final ContentType MULTIPART_MIXED = new ContentType(MULTIPART, "mixed", null);
public static final ContentType MULTIPART_FORM_DATA = new ContentType(MULTIPART, "form-data", null);
- public static final String PARAMETER_CHARSET = "charset";
- public static final String PARAMETER_IEEE754_COMPATIBLE = "IEEE754Compatible";
- public static final String PARAMETER_ODATA_METADATA = "odata.metadata";
-
- public static final String VALUE_ODATA_METADATA_NONE = "none";
- public static final String VALUE_ODATA_METADATA_MINIMAL = "minimal";
- public static final String VALUE_ODATA_METADATA_FULL = "full";
-
private final String type;
private final String subtype;
private final Map {@link ContentType}s are compatible
* if type
and subtype
have the same value.
true
if both instances are compatible (see definition above), otherwise false
.
*/
- public boolean isCompatible(final ContentType...otherTypes) {
- for(final ContentType otherType : otherTypes) {
- if(isCompatible(otherType)) {
+ public boolean isCompatible(final ContentType... otherTypes) {
+ for (final ContentType otherType : otherTypes) {
+ if (isCompatible(otherType)) {
return true;
}
}
-
+
return false;
}
-
+
/**
* Checks whether both strings are equal ignoring the case of the strings.
*
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
index 8d4100557..b4c414b70 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
@@ -51,99 +51,92 @@ import org.apache.olingo.server.core.uri.UriHelperImpl;
public class ODataImpl extends OData {
- @Override
- public ODataSerializer createSerializer(final ContentType contentType)
- throws SerializerException {
- ODataSerializer serializer;
+ @Override
+ public ODataSerializer createSerializer(final ContentType contentType) throws SerializerException {
+ ODataSerializer serializer = null;
- // odata.metadata=none, odata.metadata=minimal, odata.metadata=full
- if (contentType.isCompatible(ContentType.APPLICATION_JSON)
- && ContentType.VALUE_ODATA_METADATA_MINIMAL
- .equals(contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA))) {
- serializer = new ODataJsonSerializer(contentType);
- } else if (contentType.isCompatible(ContentType.APPLICATION_XML)) {
- serializer = new ODataXmlSerializerImpl();
- } else {
- throw new SerializerException("Unsupported format: "
- + contentType.toContentTypeString(),
- SerializerException.MessageKeys.UNSUPPORTED_FORMAT,
- contentType.toContentTypeString());
- }
+ if (contentType.isCompatible(ContentType.APPLICATION_JSON)) {
+ final String metadata = contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA);
+ if (metadata == null
+ || ContentType.VALUE_ODATA_METADATA_MINIMAL.equals(metadata)
+ || ContentType.VALUE_ODATA_METADATA_NONE.equals(metadata)) {
+ serializer = new ODataJsonSerializer(contentType);
+ }
+ } else if (contentType.isCompatible(ContentType.APPLICATION_XML)) {
+ serializer = new ODataXmlSerializerImpl();
+ }
- return serializer;
- }
+ if (serializer == null) {
+ throw new SerializerException("Unsupported format: " + contentType.toContentTypeString(),
+ SerializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
+ } else {
+ return serializer;
+ }
+ }
- @Override
- public FixedFormatSerializer createFixedFormatSerializer() {
- return new FixedFormatSerializerImpl();
- }
+ @Override
+ public FixedFormatSerializer createFixedFormatSerializer() {
+ return new FixedFormatSerializerImpl();
+ }
- @Override
- public ODataHttpHandler createHandler(final ServiceMetadata edm) {
- return new ODataHttpHandlerImpl(this, edm);
- }
+ @Override
+ public ODataHttpHandler createHandler(final ServiceMetadata edm) {
+ return new ODataHttpHandlerImpl(this, edm);
+ }
- @Override
- public ServiceMetadata createServiceMetadata(
- final CsdlEdmProvider edmProvider,
- final List