Repository: olingo-odata4 Updated Branches: refs/heads/master 49b859943 -> 11e040bab
OLINGO-911: using json serializer for response purpose, but this will ever be used to just send the 204 in cases of update and delete Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/11e040ba Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/11e040ba Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/11e040ba Branch: refs/heads/master Commit: 11e040babc550af1061bae37c5feb63aab4a0868 Parents: 49b8599 Author: Ramesh Reddy <[email protected]> Authored: Thu Mar 17 17:34:13 2016 -0500 Committer: Ramesh Reddy <[email protected]> Committed: Thu Mar 17 17:34:13 2016 -0500 ---------------------------------------------------------------------- .../olingo/server/core/ServiceRequest.java | 5 +++++ .../server/core/responses/PropertyResponse.java | 19 +++++++++++++------ .../server/example/TripPinServiceTest.java | 13 ++++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/11e040ba/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java index 6242975..e85d7ba 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java @@ -275,6 +275,11 @@ public abstract class ServiceRequest { SerializerException { return this.odata.createSerializer(getResponseContentType()); } + + public ODataSerializer getSerializer(ContentType type) throws ContentNegotiatorException, + SerializerException { + return this.odata.createSerializer(type); + } public Map<String, String> getPreferences(){ HashMap<String, String> map = new HashMap<String, String>(); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/11e040ba/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java index f9c35ba..290abb5 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java @@ -51,17 +51,24 @@ public class PropertyResponse extends ServiceResponse { public static PropertyResponse getInstance(ServiceRequest request, ODataResponse response, EdmType edmType, ContextURL contextURL, boolean collection) throws ContentNegotiatorException, SerializerException { + + ContentType type = request.getResponseContentType(); + ODataSerializer serializer = null; + if (type.equals(ContentType.TEXT_PLAIN)) { + serializer = request.getSerializer(ContentType.APPLICATION_JSON); + } else { + serializer = request.getSerializer(); + } + if (edmType.getKind() == EdmTypeKind.PRIMITIVE) { PrimitiveSerializerOptions options = request.getSerializerOptions( - PrimitiveSerializerOptions.class, contextURL, false); - ContentType type = request.getResponseContentType(); - return new PropertyResponse(request.getServiceMetaData(), request.getSerializer(), response, + PrimitiveSerializerOptions.class, contextURL, false); + return new PropertyResponse(request.getServiceMetaData(), serializer, response, options, type, collection, request.getPreferences()); } ComplexSerializerOptions options = request.getSerializerOptions(ComplexSerializerOptions.class, - contextURL, false); - ContentType type = request.getResponseContentType(); - return new PropertyResponse(request.getServiceMetaData(), request.getSerializer(), response, + contextURL, false); + return new PropertyResponse(request.getServiceMetaData(), serializer, response, options, type, collection, request.getPreferences()); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/11e040ba/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java index 8bb4d5a..0486439 100644 --- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java +++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java @@ -203,7 +203,18 @@ public class TripPinServiceTest { HttpResponse response = httpGET(baseURL + "/Airlines('AA')/Name/$value", 200); assertEquals("American Airlines", IOUtils.toString(response.getEntity().getContent())); } - + + @Test + public void testUpdateRawValue() throws Exception { + // Note that in-real services must convert raw value (byte[]) to + // the data type it needs to save in in updateProperty method + String editUrl = baseURL + "/Airlines('AF')/Name/$value"; + HttpPut request = new HttpPut(editUrl); + request.setEntity(new StringEntity("Safari")); + HttpResponse response = httpSend(request, 204); + EntityUtils.consumeQuietly(response.getEntity()); + } + @Test @Ignore // TODO: Support geometry types to make this run public void testReadComplexProperty() throws Exception {
