[OLINGO-690] the server actually supports JSON without metadata
Change-Id: Ib9289c9e81c05ed404e71bdc1bc7eb7bbdde7a7c Signed-off-by: Christian Amend <christian.amend@sap.com>
This commit is contained in:
parent
e32034bd54
commit
94b3917f4e
|
@ -50,12 +50,21 @@ public final class ContentType {
|
||||||
private static final String TEXT = "text";
|
private static final String TEXT = "text";
|
||||||
private static final String MULTIPART = "multipart";
|
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 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 = ContentType.create(ContentType.APPLICATION_JSON,
|
||||||
|
PARAMETER_ODATA_METADATA + '=' + VALUE_ODATA_METADATA_MINIMAL);
|
||||||
public static final ContentType JSON_NO_METADATA = ContentType.create(ContentType.APPLICATION_JSON,
|
public static final ContentType JSON_NO_METADATA = ContentType.create(ContentType.APPLICATION_JSON,
|
||||||
"odata.metadata=none");
|
PARAMETER_ODATA_METADATA + '=' + VALUE_ODATA_METADATA_NONE);
|
||||||
public static final ContentType JSON_FULL_METADATA = ContentType.create(ContentType.APPLICATION_JSON,
|
public static final ContentType JSON_FULL_METADATA = ContentType.create(ContentType.APPLICATION_JSON,
|
||||||
"odata.metadata=full");
|
PARAMETER_ODATA_METADATA + '=' + VALUE_ODATA_METADATA_FULL);
|
||||||
|
|
||||||
public static final ContentType APPLICATION_XML = new ContentType(APPLICATION, "xml", null);
|
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 = new ContentType(APPLICATION, "atom+xml", null);
|
||||||
|
@ -63,7 +72,6 @@ public final class ContentType {
|
||||||
public static final ContentType APPLICATION_ATOM_XML_FEED = create(APPLICATION_ATOM_XML, "type=feed");
|
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_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_OCTET_STREAM = new ContentType(APPLICATION, "octet-stream", null);
|
||||||
|
|
||||||
public static final ContentType APPLICATION_XHTML_XML = new ContentType(APPLICATION, "xhtml+xml", 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_MIXED = new ContentType(MULTIPART, "mixed", null);
|
||||||
public static final ContentType MULTIPART_FORM_DATA = new ContentType(MULTIPART, "form-data", 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 type;
|
||||||
private final String subtype;
|
private final String subtype;
|
||||||
private final Map<String, String> parameters;
|
private final Map<String, String> parameters;
|
||||||
|
@ -331,9 +331,9 @@ public final class ContentType {
|
||||||
* (for compare with parameters see {@link #equals(Object)}).</p>
|
* (for compare with parameters see {@link #equals(Object)}).</p>
|
||||||
* @return <code>true</code> if both instances are compatible (see definition above), otherwise <code>false</code>.
|
* @return <code>true</code> if both instances are compatible (see definition above), otherwise <code>false</code>.
|
||||||
*/
|
*/
|
||||||
public boolean isCompatible(final ContentType...otherTypes) {
|
public boolean isCompatible(final ContentType... otherTypes) {
|
||||||
for(final ContentType otherType : otherTypes) {
|
for (final ContentType otherType : otherTypes) {
|
||||||
if(isCompatible(otherType)) {
|
if (isCompatible(otherType)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,99 +51,92 @@ import org.apache.olingo.server.core.uri.UriHelperImpl;
|
||||||
|
|
||||||
public class ODataImpl extends OData {
|
public class ODataImpl extends OData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ODataSerializer createSerializer(final ContentType contentType)
|
public ODataSerializer createSerializer(final ContentType contentType) throws SerializerException {
|
||||||
throws SerializerException {
|
ODataSerializer serializer = null;
|
||||||
ODataSerializer serializer;
|
|
||||||
|
|
||||||
// odata.metadata=none, odata.metadata=minimal, odata.metadata=full
|
if (contentType.isCompatible(ContentType.APPLICATION_JSON)) {
|
||||||
if (contentType.isCompatible(ContentType.APPLICATION_JSON)
|
final String metadata = contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA);
|
||||||
&& ContentType.VALUE_ODATA_METADATA_MINIMAL
|
if (metadata == null
|
||||||
.equals(contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA))) {
|
|| ContentType.VALUE_ODATA_METADATA_MINIMAL.equals(metadata)
|
||||||
serializer = new ODataJsonSerializer(contentType);
|
|| ContentType.VALUE_ODATA_METADATA_NONE.equals(metadata)) {
|
||||||
} else if (contentType.isCompatible(ContentType.APPLICATION_XML)) {
|
serializer = new ODataJsonSerializer(contentType);
|
||||||
serializer = new ODataXmlSerializerImpl();
|
}
|
||||||
} else {
|
} else if (contentType.isCompatible(ContentType.APPLICATION_XML)) {
|
||||||
throw new SerializerException("Unsupported format: "
|
serializer = new ODataXmlSerializerImpl();
|
||||||
+ contentType.toContentTypeString(),
|
}
|
||||||
SerializerException.MessageKeys.UNSUPPORTED_FORMAT,
|
|
||||||
contentType.toContentTypeString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return serializer;
|
if (serializer == null) {
|
||||||
}
|
throw new SerializerException("Unsupported format: " + contentType.toContentTypeString(),
|
||||||
|
SerializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
|
||||||
|
} else {
|
||||||
|
return serializer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FixedFormatSerializer createFixedFormatSerializer() {
|
public FixedFormatSerializer createFixedFormatSerializer() {
|
||||||
return new FixedFormatSerializerImpl();
|
return new FixedFormatSerializerImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ODataHttpHandler createHandler(final ServiceMetadata edm) {
|
public ODataHttpHandler createHandler(final ServiceMetadata edm) {
|
||||||
return new ODataHttpHandlerImpl(this, edm);
|
return new ODataHttpHandlerImpl(this, edm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceMetadata createServiceMetadata(
|
public ServiceMetadata createServiceMetadata(final CsdlEdmProvider edmProvider,
|
||||||
final CsdlEdmProvider edmProvider,
|
final List<EdmxReference> references) {
|
||||||
final List<EdmxReference> references) {
|
return createServiceMetadata(edmProvider, references, null);
|
||||||
return createServiceMetadata(edmProvider, references, null);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceMetadata createServiceMetadata(CsdlEdmProvider edmProvider,
|
public ServiceMetadata createServiceMetadata(final CsdlEdmProvider edmProvider,
|
||||||
List<EdmxReference> references,
|
final List<EdmxReference> references, final ServiceMetadataETagSupport serviceMetadataETagSupport) {
|
||||||
ServiceMetadataETagSupport serviceMetadataETagSupport) {
|
return new ServiceMetadataImpl(edmProvider, references, serviceMetadataETagSupport);
|
||||||
return new ServiceMetadataImpl(edmProvider, references,
|
}
|
||||||
serviceMetadataETagSupport);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FixedFormatDeserializer createFixedFormatDeserializer() {
|
public FixedFormatDeserializer createFixedFormatDeserializer() {
|
||||||
return new FixedFormatDeserializerImpl();
|
return new FixedFormatDeserializerImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UriHelper createUriHelper() {
|
public UriHelper createUriHelper() {
|
||||||
return new UriHelperImpl();
|
return new UriHelperImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ODataDeserializer createDeserializer(final ContentType contentType)
|
public ODataDeserializer createDeserializer(final ContentType contentType) throws DeserializerException {
|
||||||
throws DeserializerException {
|
ODataDeserializer deserializer;
|
||||||
ODataDeserializer deserializer;
|
|
||||||
|
|
||||||
// odata.metadata=none, odata.metadata=minimal, odata.metadata=full
|
if (contentType.isCompatible(ContentType.JSON)) {
|
||||||
if (contentType.isCompatible(ContentType.JSON)) {
|
deserializer = new ODataJsonDeserializer(contentType);
|
||||||
deserializer = new ODataJsonDeserializer(contentType);
|
// } else if(contentType.isCompatible(ContentType.APPLICATION_XML))
|
||||||
// } else if(contentType.isCompatible(ContentType.APPLICATION_XML))
|
// We do not support XML deserialization right now so this must lead
|
||||||
// We do not support XML deserialization right now so this must lead
|
// to an error.
|
||||||
// to an error.
|
// {
|
||||||
// {
|
} else {
|
||||||
} else {
|
throw new DeserializerException("Unsupported format: " + contentType.toContentTypeString(),
|
||||||
throw new DeserializerException("Unsupported format: "
|
DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
|
||||||
+ contentType.toContentTypeString(),
|
}
|
||||||
DeserializerException.MessageKeys.UNSUPPORTED_FORMAT,
|
|
||||||
contentType.toContentTypeString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return deserializer;
|
return deserializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EdmPrimitiveType createPrimitiveTypeInstance(
|
public EdmPrimitiveType createPrimitiveTypeInstance(final EdmPrimitiveTypeKind kind) {
|
||||||
final EdmPrimitiveTypeKind kind) {
|
return EdmPrimitiveTypeFactory.getInstance(kind);
|
||||||
return EdmPrimitiveTypeFactory.getInstance(kind);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ETagHelper createETagHelper() {
|
public ETagHelper createETagHelper() {
|
||||||
return new ETagHelperImpl();
|
return new ETagHelperImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Preferences createPreferences(final Collection<String> preferHeaders) {
|
public Preferences createPreferences(final Collection<String> preferHeaders) {
|
||||||
return new PreferencesImpl(preferHeaders);
|
return new PreferencesImpl(preferHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,36 +23,35 @@ import static org.junit.Assert.assertNotNull;
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
import org.apache.olingo.server.api.OData;
|
import org.apache.olingo.server.api.OData;
|
||||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||||
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
|
|
||||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
|
||||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ODataImplTest {
|
public class ODataImplTest {
|
||||||
|
|
||||||
private final OData odata = OData.newInstance();
|
private final OData odata = OData.newInstance();
|
||||||
|
|
||||||
@Test(expected=SerializerException.class)
|
@Test
|
||||||
public void testJsonSerializerForOdataMetadataNone() throws SerializerException {
|
public void serializerSupportedFormats() throws SerializerException {
|
||||||
odata.createSerializer(ContentType.JSON_NO_METADATA);
|
assertNotNull(odata.createSerializer(ContentType.JSON_NO_METADATA));
|
||||||
}
|
assertNotNull(odata.createSerializer(ContentType.JSON));
|
||||||
|
assertNotNull(odata.createSerializer(ContentType.APPLICATION_JSON));
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected=SerializerException.class)
|
@Test(expected = SerializerException.class)
|
||||||
public void testJsonSerializerForODataMetadataFull() throws SerializerException {
|
public void jsonSerializerForODataMetadataFull() throws SerializerException {
|
||||||
odata.createSerializer(ContentType.JSON_FULL_METADATA);
|
odata.createSerializer(ContentType.JSON_FULL_METADATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateJsonSerializerForODataMetadataMinimal() throws SerializerException {
|
public void deserializerSupportedFormats() throws DeserializerException {
|
||||||
final ODataSerializer serializer = odata.createSerializer(ContentType.JSON);
|
assertNotNull(odata.createDeserializer(ContentType.JSON_NO_METADATA));
|
||||||
|
assertNotNull(odata.createDeserializer(ContentType.JSON));
|
||||||
|
assertNotNull(odata.createDeserializer(ContentType.JSON_FULL_METADATA));
|
||||||
|
assertNotNull(odata.createDeserializer(ContentType.APPLICATION_JSON));
|
||||||
|
}
|
||||||
|
|
||||||
assertNotNull(serializer);
|
@Test(expected = DeserializerException.class)
|
||||||
}
|
public void xmlDeserializer() throws DeserializerException {
|
||||||
|
odata.createDeserializer(ContentType.APPLICATION_XML);
|
||||||
@Test
|
}
|
||||||
public void testCreateJsonDeserialierForODataMetadataMinimal() throws DeserializerException {
|
|
||||||
final ODataDeserializer deserializer = odata.createDeserializer(ContentType.JSON);
|
|
||||||
|
|
||||||
assertNotNull(deserializer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue