http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java ---------------------------------------------------------------------- diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java index 8a84d95,e953cae..926f74c --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java @@@ -49,29 -69,6 +69,10 @@@ import org.apache.olingo.client.api.dom import org.apache.olingo.client.api.domain.ClientServiceDocument; import org.apache.olingo.client.api.domain.ClientValuable; import org.apache.olingo.client.api.domain.ClientValue; - import org.apache.olingo.client.api.serialization.ODataBinder; +import org.apache.olingo.client.core.domain.ClientAnnotationImpl; +import org.apache.olingo.client.core.domain.ClientDeletedEntityImpl; +import org.apache.olingo.client.core.domain.ClientDeltaLinkImpl; +import org.apache.olingo.client.core.domain.ClientPropertyImpl; - import org.apache.olingo.client.core.uri.URIUtils; - import org.apache.olingo.commons.api.Constants; - import org.apache.olingo.commons.api.data.Annotatable; - import org.apache.olingo.commons.api.data.Annotation; - import org.apache.olingo.commons.api.data.ComplexValue; - import org.apache.olingo.commons.api.data.ContextURL; - import org.apache.olingo.commons.api.data.DeletedEntity; - import org.apache.olingo.commons.api.data.Delta; - import org.apache.olingo.commons.api.data.DeltaLink; - import org.apache.olingo.commons.api.data.Entity; - import org.apache.olingo.commons.api.data.EntityCollection; - import org.apache.olingo.commons.api.data.Link; - import org.apache.olingo.commons.api.data.Linked; - import org.apache.olingo.commons.api.data.Operation; - import org.apache.olingo.commons.api.data.Property; - import org.apache.olingo.commons.api.data.ResWrap; - import org.apache.olingo.commons.api.data.Valuable; - import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmBindingTarget; import org.apache.olingo.commons.api.edm.EdmComplexType; @@@ -90,11 -87,13 +91,9 @@@ import org.apache.olingo.commons.api.ed import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.geo.Geospatial; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.client.core.domain.ClientAnnotationImpl; -import org.apache.olingo.client.core.domain.ClientDeletedEntityImpl; -import org.apache.olingo.client.core.domain.ClientDeltaLinkImpl; -import org.apache.olingo.client.core.domain.ClientPropertyImpl; -import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; +import org.apache.olingo.commons.api.format.ContentType; - import org.apache.olingo.commons.api.serialization.ODataSerializerException; import org.apache.olingo.commons.core.edm.EdmTypeInfo; +import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; - import org.apache.olingo.commons.core.serialization.ContextURLParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java ---------------------------------------------------------------------- diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java index 17436e9,6153cdb..aba9357 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java @@@ -25,16 -25,11 +25,17 @@@ import java.util.Map import org.apache.commons.io.IOUtils; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.data.ServiceDocument; +import org.apache.olingo.client.api.domain.ClientEntity; +import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.client.api.domain.ClientEntitySetIterator; +import org.apache.olingo.client.api.domain.ClientProperty; +import org.apache.olingo.client.api.domain.ClientServiceDocument; +import org.apache.olingo.client.api.domain.ClientValue; import org.apache.olingo.client.api.edm.xml.XMLMetadata; + import org.apache.olingo.client.api.serialization.ODataDeserializerException; import org.apache.olingo.client.api.serialization.ODataReader; import org.apache.olingo.client.core.edm.ClientCsdlEdmProvider; +import org.apache.olingo.commons.api.ODataError; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.Property; @@@ -42,8 -37,13 +43,7 @@@ import org.apache.olingo.commons.api.da import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.provider.CsdlSchema; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; - import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.apache.olingo.commons.core.edm.EdmProviderImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java ---------------------------------------------------------------------- diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java index fe93cb1,584c420..88a433f --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java @@@ -32,11 -32,11 +32,11 @@@ import org.apache.olingo.client.api.ODa import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientLink; import org.apache.olingo.client.api.domain.ClientProperty; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.client.api.serialization.ODataWriter; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.format.ContentType; - import org.apache.olingo.commons.api.serialization.ODataSerializerException; ++import org.apache.olingo.client.api.serialization.ODataSerializerException; public class ODataWriterImpl implements ODataWriter { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java ---------------------------------------------------------------------- diff --cc lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java index e64d158,d3746e1..50af30f --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java @@@ -32,10 -22,20 +32,10 @@@ import org.apache.olingo.client.api.dom import org.apache.olingo.client.core.AbstractTest; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.client.api.domain.ClientEntity; -import org.apache.olingo.client.api.domain.ClientEntitySet; +import org.apache.olingo.commons.api.format.ContentType; - import org.apache.olingo.commons.api.serialization.ODataDeserializerException; + import org.apache.olingo.client.api.serialization.ODataDeserializerException; -import org.apache.olingo.commons.api.format.ODataFormat; import org.junit.Test; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - public class EntitySetTest extends AbstractTest { @Override http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java ---------------------------------------------------------------------- diff --cc lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java index 7fd7c45,93b43df..217f1d1 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java @@@ -18,16 -18,16 +18,16 @@@ */ package org.apache.olingo.client.core.v4; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import org.apache.olingo.client.api.ODataClient; + import org.apache.olingo.client.api.serialization.ODataDeserializerException; import org.apache.olingo.client.core.AbstractTest; import org.apache.olingo.commons.api.ODataError; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; - import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - public class ErrorTest extends AbstractTest { @Override http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java ---------------------------------------------------------------------- diff --cc lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java index 73ae7f1,b0423e7..0ee5471 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java @@@ -30,12 -24,18 +30,12 @@@ import org.apache.olingo.client.api.dom import org.apache.olingo.client.api.domain.ClientComplexValue; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientValue; +import org.apache.olingo.client.core.AbstractTest; +import org.apache.olingo.commons.api.format.ContentType; - import org.apache.olingo.commons.api.serialization.ODataDeserializerException; - import org.apache.olingo.commons.api.serialization.ODataSerializerException; + import org.apache.olingo.client.api.serialization.ODataDeserializerException; + import org.apache.olingo.client.api.serialization.ODataSerializerException; -import org.apache.olingo.commons.api.format.ODataFormat; import org.junit.Test; -import java.io.InputStream; -import java.util.Iterator; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - public class PropertyTest extends AbstractTest { @Override http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java ---------------------------------------------------------------------- diff --cc lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java index 97f6d81,b0a769f..008b165 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java @@@ -18,21 -18,21 +18,21 @@@ */ package org.apache.olingo.client.core.v4; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.net.URI; + import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.data.ServiceDocument; +import org.apache.olingo.client.api.domain.ClientServiceDocument; import org.apache.olingo.client.core.AbstractTest; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.client.api.domain.ClientServiceDocument; +import org.apache.olingo.commons.api.format.ContentType; - import org.apache.olingo.commons.api.serialization.ODataDeserializerException; + import org.apache.olingo.client.api.serialization.ODataDeserializerException; -import org.apache.olingo.commons.api.format.ODataFormat; import org.junit.Test; -import java.net.URI; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - public class ServiceDocumentTest extends AbstractTest { @Override http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/server-api/src/main/java/org/apache/olingo/server/api/OData.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalActionProcessor.java ---------------------------------------------------------------------- diff --cc lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalActionProcessor.java index 1e038b2,d7fc00f..663a7eb --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalActionProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalActionProcessor.java @@@ -77,8 -80,9 +79,8 @@@ public class TechnicalActionProcessor e final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0)) .getAction(); - DeserializerResult deserializerResult = + DeserializerResult deserializerResult = - odata.createDeserializer(ODataFormat.fromContentType(requestFormat)) - .actionParameters(request.getBody(), action); + odata.createDeserializer(requestFormat).actionParameters(request.getBody(), action); EntityCollection collection = dataProvider.processActionEntityCollection(action.getName(), deserializerResult.getActionParameters()); @@@ -90,15 -94,26 +92,25 @@@ throw new ODataApplicationException("The action could not be executed.", HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT); } - final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource()); - final EdmEntityType type = (EdmEntityType) action.getReturnType().getType(); - EntityCollectionSerializerOptions options = EntityCollectionSerializerOptions.with() - .contextURL(isODataMetadataNone(responseFormat) ? null : - getContextUrl(edmEntitySet, type, false)).build(); - response.setContent(odata.createSerializer(requestFormat) - .entityCollection(serviceMetadata, type, collection, options).getContent()); - response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + + final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn(); + if (returnPreference == null || returnPreference == Return.REPRESENTATION) { + final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource()); + final EdmEntityType type = (EdmEntityType) action.getReturnType().getType(); - final ODataFormat format = ODataFormat.fromContentType(responseFormat); + final EntityCollectionSerializerOptions options = EntityCollectionSerializerOptions.with() - .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, type, false)) ++ .contextURL(isODataMetadataNone(responseFormat) ? null : getContextUrl(edmEntitySet, type, false)) + .build(); - response.setContent(odata.createSerializer(format) ++ response.setContent(odata.createSerializer(responseFormat) + .entityCollection(serviceMetadata, type, collection, options).getContent()); + response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + response.setStatusCode(HttpStatusCode.OK.getStatusCode()); + } else { + response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); + } + if (returnPreference != null) { + response.setHeader(HttpHeader.PREFERENCE_APPLIED, + PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString()); + } } @Override @@@ -125,17 -141,32 +137,31 @@@ HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT); } } else { - response.setContent(odata.createSerializer(requestFormat).entity( - serviceMetadata, - type, - entityResult.getEntity(), - EntitySerializerOptions.with() - .contextURL(isODataMetadataNone(responseFormat) ? null : - getContextUrl(edmEntitySet, type, true)).build()) - .getContent()); - response.setStatusCode((entityResult.isCreated() ? HttpStatusCode.CREATED : HttpStatusCode.OK) - .getStatusCode()); - response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn(); + if (returnPreference == null || returnPreference == Return.REPRESENTATION) { - final ODataFormat format = ODataFormat.fromContentType(responseFormat); - response.setContent(odata.createSerializer(format).entity( ++ response.setContent(odata.createSerializer(responseFormat).entity( + serviceMetadata, + type, + entityResult.getEntity(), + EntitySerializerOptions.with() - .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, type, true)) ++ .contextURL(isODataMetadataNone(responseFormat) ? null : getContextUrl(edmEntitySet, type, true)) + .build()) + .getContent()); + response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + response.setStatusCode((entityResult.isCreated() ? HttpStatusCode.CREATED : HttpStatusCode.OK) + .getStatusCode()); + } else { + response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); + } + if (returnPreference != null) { + response.setHeader(HttpHeader.PREFERENCE_APPLIED, + PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString()); + } + if (entityResult.isCreated()) { + response.setHeader(HttpHeader.LOCATION, + request.getRawBaseUri() + '/' - + odata.createUriHelper().buildCanonicalURL(edmEntitySet, entityResult.getEntity())); ++ + odata.createUriHelper().buildCanonicalURL(edmEntitySet, entityResult.getEntity())); + } if (entityResult.getEntity().getETag() != null) { response.setHeader(HttpHeader.ETAG, entityResult.getEntity().getETag()); } @@@ -164,16 -196,25 +190,24 @@@ throw new ODataApplicationException("The action could not be executed.", HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT); } - EdmPrimitiveType type = (EdmPrimitiveType) action.getReturnType().getType(); - ContextURL contextURL = ContextURL.with().type(type).asCollection().build(); - PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextURL).build(); - - SerializerResult result = - odata.createSerializer(requestFormat).primitiveCollection(serviceMetadata, type, property, options); - response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - response.setContent(result.getContent()); - response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn(); + if (returnPreference == null || returnPreference == Return.REPRESENTATION) { + final EdmPrimitiveType type = (EdmPrimitiveType) action.getReturnType().getType(); + final ContextURL contextURL = ContextURL.with().type(type).asCollection().build(); + final PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextURL).build(); + final SerializerResult result = - odata.createSerializer(ODataFormat.fromContentType(responseFormat)) - .primitiveCollection(serviceMetadata, type, property, options); ++ odata.createSerializer(responseFormat).primitiveCollection(serviceMetadata, type, property, options); + response.setContent(result.getContent()); + response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + response.setStatusCode(HttpStatusCode.OK.getStatusCode()); + } else { + response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); + } + if (returnPreference != null) { + response.setHeader(HttpHeader.PREFERENCE_APPLIED, + PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString()); + } } @Override @@@ -197,15 -239,22 +231,22 @@@ HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT); } } else { - ContextURL contextURL = ContextURL.with().type(type).build(); - PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextURL).build(); - - SerializerResult result = odata.createSerializer(requestFormat) - .primitive(serviceMetadata, type, property, options); - - response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - response.setContent(result.getContent()); - response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn(); + if (returnPreference == null || returnPreference == Return.REPRESENTATION) { + final ContextURL contextURL = ContextURL.with().type(type).build(); + final PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextURL).build(); - final SerializerResult result = odata.createSerializer(ODataFormat.fromContentType(responseFormat)) ++ final SerializerResult result = odata.createSerializer(responseFormat) + .primitive(serviceMetadata, type, property, options); + response.setContent(result.getContent()); + response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + response.setStatusCode(HttpStatusCode.OK.getStatusCode()); + } else { + response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); + } + if (returnPreference != null) { + response.setHeader(HttpHeader.PREFERENCE_APPLIED, + PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString()); + } } } @@@ -231,16 -281,25 +272,23 @@@ throw new ODataApplicationException("The action could not be executed.", HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT); } - EdmComplexType type = (EdmComplexType) action.getReturnType().getType(); - ContextURL contextURL = ContextURL.with().type(type).asCollection().build(); - ComplexSerializerOptions options = ComplexSerializerOptions.with().contextURL(contextURL).build(); - - SerializerResult result = - odata.createSerializer(requestFormat).complexCollection(serviceMetadata, type, property, options); -- - response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - response.setContent(result.getContent()); - response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn(); + if (returnPreference == null || returnPreference == Return.REPRESENTATION) { + final EdmComplexType type = (EdmComplexType) action.getReturnType().getType(); + final ContextURL contextURL = ContextURL.with().type(type).asCollection().build(); + final ComplexSerializerOptions options = ComplexSerializerOptions.with().contextURL(contextURL).build(); + final SerializerResult result = - odata.createSerializer(ODataFormat.fromContentType(responseFormat)).complexCollection(serviceMetadata, type, - property, options); ++ odata.createSerializer(responseFormat).complexCollection(serviceMetadata, type, property, options); + response.setContent(result.getContent()); + response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + response.setStatusCode(HttpStatusCode.OK.getStatusCode()); + } else { + response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); + } + if (returnPreference != null) { + response.setHeader(HttpHeader.PREFERENCE_APPLIED, + PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString()); + } } @Override @@@ -264,12 -324,23 +312,22 @@@ HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT); } } else { - ContextURL contextURL = ContextURL.with().type(type).build(); - ComplexSerializerOptions options = ComplexSerializerOptions.with().contextURL(contextURL).build(); - SerializerResult result = odata.createSerializer(requestFormat).complex(serviceMetadata, type, property, options); - response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - response.setContent(result.getContent()); - response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn(); + if (returnPreference == null || returnPreference == Return.REPRESENTATION) { + final ContextURL contextURL = ContextURL.with().type(type).build(); + final ComplexSerializerOptions options = ComplexSerializerOptions.with().contextURL(contextURL).build(); + final SerializerResult result = - odata.createSerializer(ODataFormat.fromContentType(responseFormat)).complex(serviceMetadata, type, property, - options); ++ odata.createSerializer(responseFormat).complex(serviceMetadata, type, property, options); + response.setContent(result.getContent()); + response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + response.setStatusCode(HttpStatusCode.OK.getStatusCode()); + } else { + response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); + } + if (returnPreference != null) { + response.setHeader(HttpHeader.PREFERENCE_APPLIED, + PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString()); + } } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java ---------------------------------------------------------------------- diff --cc lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java index f86646d,807c815..9844d71 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java @@@ -162,10 -164,20 +164,19 @@@ public class TechnicalEntityProcessor e expand = deserializerResult.getExpandTree(); } - response.setContent(serializeEntity(entity, edmEntitySet, edmEntityType, responseFormat, expand, null) - .getContent()); - response.setStatusCode(HttpStatusCode.CREATED.getStatusCode()); - response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn(); + if (returnPreference == null || returnPreference == Return.REPRESENTATION) { - final ODataFormat format = ODataFormat.fromContentType(responseFormat); - response.setContent(serializeEntity(entity, edmEntitySet, edmEntityType, format, expand, null) ++ response.setContent(serializeEntity(entity, edmEntitySet, edmEntityType, responseFormat, expand, null) + .getContent()); + response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + response.setStatusCode(HttpStatusCode.CREATED.getStatusCode()); + } else { + response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); + } + if (returnPreference != null) { + response.setHeader(HttpHeader.PREFERENCE_APPLIED, + PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString()); + } response.setHeader(HttpHeader.LOCATION, request.getRawBaseUri() + '/' + odata.createUriHelper().buildCanonicalURL(edmEntitySet, entity)); if (entity.getETag() != null) { @@@ -208,10 -220,20 +219,19 @@@ dataProvider.update(request.getRawBaseUri(), edmEntitySet, entity, changedEntity, request.getMethod() == HttpMethod.PATCH, false); - response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - response.setContent(serializeEntity(entity, edmEntitySet, edmEntityType, responseFormat, null, null) - .getContent()); - response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn(); + if (returnPreference == null || returnPreference == Return.REPRESENTATION) { + response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - final ODataFormat format = ODataFormat.fromContentType(responseFormat); - response.setContent(serializeEntity(entity, edmEntitySet, edmEntityType, format, null, null) ++ response.setContent(serializeEntity(entity, edmEntitySet, edmEntityType, responseFormat, null, null) + .getContent()); + response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + } else { + response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); + } + if (returnPreference != null) { + response.setHeader(HttpHeader.PREFERENCE_APPLIED, + PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString()); + } if (entity.getETag() != null) { response.setHeader(HttpHeader.ETAG, entity.getETag()); } @@@ -232,10 -254,20 +252,19 @@@ dataProvider.setMedia(entity, odata.createFixedFormatDeserializer().binary(request.getBody()), requestFormat.toContentTypeString()); - response.setContent(serializeEntity(entity, edmEntitySet, edmEntityType, responseFormat, null, null) - .getContent()); - response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn(); + if (returnPreference == null || returnPreference == Return.REPRESENTATION) { - final ODataFormat format = ODataFormat.fromContentType(responseFormat); - response.setContent(serializeEntity(entity, edmEntitySet, edmEntityType, format, null, null) ++ response.setContent(serializeEntity(entity, edmEntitySet, edmEntityType, responseFormat, null, null) + .getContent()); + response.setStatusCode(HttpStatusCode.OK.getStatusCode()); + response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + } else { + response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); + } + if (returnPreference != null) { + response.setHeader(HttpHeader.PREFERENCE_APPLIED, + PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString()); + } if (entity.getETag() != null) { response.setHeader(HttpHeader.ETAG, entity.getETag()); } @@@ -410,12 -443,15 +439,14 @@@ SkipHandler.applySkipSystemQueryHandler(uriInfo.getSkipOption(), entitySet); TopHandler.applyTopSystemQueryOption(uriInfo.getTopOption(), entitySet); - ServerSidePagingHandler.applyServerSidePaging(uriInfo.getSkipTokenOption(), + final Integer pageSize = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getMaxPageSize(); + final Integer serverPageSize = ServerSidePagingHandler.applyServerSidePaging(uriInfo.getSkipTokenOption(), entitySet, edmEntitySet, - request.getRawRequestUri()); + request.getRawRequestUri(), + pageSize); // Apply expand system query option - final ODataFormat format = ODataFormat.fromContentType(requestedContentType); final ExpandOption expand = uriInfo.getExpandOption(); final SelectOption select = uriInfo.getSelectOption(); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java ---------------------------------------------------------------------- diff --cc lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java index 7a31f84,4d1e834..cf4b38e --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java @@@ -303,16 -307,26 +305,25 @@@ public class TechnicalPrimitiveComplexP dataProvider.updateETag(entity); - response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - if (representationType == RepresentationType.VALUE) { - response.setContent( - serializePrimitiveValue(property, edmProperty, (EdmPrimitiveType) edmProperty.getType(), null)); + final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn(); + if (returnPreference == null || returnPreference == Return.REPRESENTATION) { + response.setStatusCode(HttpStatusCode.OK.getStatusCode()); + if (representationType == RepresentationType.VALUE) { + response.setContent( + serializePrimitiveValue(property, edmProperty, (EdmPrimitiveType) edmProperty.getType(), null)); + } else { - final ODataFormat format = ODataFormat.fromContentType(responseFormat); + final SerializerResult result = serializeProperty(entity, edmEntitySet, path, property, edmProperty, - edmProperty.getType(), null, representationType, format, null, null); ++ edmProperty.getType(), null, representationType, responseFormat, null, null); + response.setContent(result.getContent()); + } + response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); } else { - final SerializerResult result = serializeProperty(entity, edmEntitySet, path, property, edmProperty, - edmProperty.getType(), null, representationType, responseFormat, null, null); - response.setContent(result.getContent()); + response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); + } + if (returnPreference != null) { + response.setHeader(HttpHeader.PREFERENCE_APPLIED, + PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString()); } - response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); if (entity.getETag() != null) { response.setHeader(HttpHeader.ETAG, entity.getETag()); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef1fd778/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java ---------------------------------------------------------------------- diff --cc lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java index c9a5f32,ec5a33d..a3f75eb --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java @@@ -726,16 -708,13 +707,13 @@@ public class ODataHandlerTest request.setRawODataPath(path); request.setRawQueryPath(query); - if (headers != null) { - Set<Map.Entry<String, List<String>>> headerSet = headers.entrySet(); - for (Map.Entry<String, List<String>> headerItem : headerSet) { - request.addHeader(headerItem.getKey(), headerItem.getValue()); - } + if (headerName != null) { + request.addHeader(headerName, Collections.singletonList(headerValue)); } - if (request.getHeaders(HttpHeader.CONTENT_TYPE) == null) { + if (headerName != HttpHeader.CONTENT_TYPE) { request.addHeader(HttpHeader.CONTENT_TYPE, Collections.singletonList( - ODataFormat.JSON.getContentType().toContentTypeString())); + ContentType.JSON.toContentTypeString())); } final OData odata = OData.newInstance();
