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

This commit is contained in:
Ramesh Reddy 2016-03-17 17:34:13 -05:00
parent 49b8599432
commit 11e040babc
3 changed files with 30 additions and 7 deletions

View File

@ -276,6 +276,11 @@ public abstract class ServiceRequest {
return this.odata.createSerializer(getResponseContentType()); return this.odata.createSerializer(getResponseContentType());
} }
public ODataSerializer getSerializer(ContentType type) throws ContentNegotiatorException,
SerializerException {
return this.odata.createSerializer(type);
}
public Map<String, String> getPreferences(){ public Map<String, String> getPreferences(){
HashMap<String, String> map = new HashMap<String, String>(); HashMap<String, String> map = new HashMap<String, String>();
List<String> headers = request.getHeaders(HttpHeader.PREFER); List<String> headers = request.getHeaders(HttpHeader.PREFER);

View File

@ -51,17 +51,24 @@ public class PropertyResponse extends ServiceResponse {
public static PropertyResponse getInstance(ServiceRequest request, ODataResponse response, public static PropertyResponse getInstance(ServiceRequest request, ODataResponse response,
EdmType edmType, ContextURL contextURL, boolean collection) throws ContentNegotiatorException, EdmType edmType, ContextURL contextURL, boolean collection) throws ContentNegotiatorException,
SerializerException { 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) { if (edmType.getKind() == EdmTypeKind.PRIMITIVE) {
PrimitiveSerializerOptions options = request.getSerializerOptions( PrimitiveSerializerOptions options = request.getSerializerOptions(
PrimitiveSerializerOptions.class, contextURL, false); PrimitiveSerializerOptions.class, contextURL, false);
ContentType type = request.getResponseContentType(); return new PropertyResponse(request.getServiceMetaData(), serializer, response,
return new PropertyResponse(request.getServiceMetaData(), request.getSerializer(), response,
options, type, collection, request.getPreferences()); options, type, collection, request.getPreferences());
} }
ComplexSerializerOptions options = request.getSerializerOptions(ComplexSerializerOptions.class, ComplexSerializerOptions options = request.getSerializerOptions(ComplexSerializerOptions.class,
contextURL, false); contextURL, false);
ContentType type = request.getResponseContentType(); return new PropertyResponse(request.getServiceMetaData(), serializer, response,
return new PropertyResponse(request.getServiceMetaData(), request.getSerializer(), response,
options, type, collection, request.getPreferences()); options, type, collection, request.getPreferences());
} }

View File

@ -204,6 +204,17 @@ public class TripPinServiceTest {
assertEquals("American Airlines", IOUtils.toString(response.getEntity().getContent())); 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 @Test @Ignore
// TODO: Support geometry types to make this run // TODO: Support geometry types to make this run
public void testReadComplexProperty() throws Exception { public void testReadComplexProperty() throws Exception {