From 5b32c3acbf026140b39b308d7fc3b56a145f8947 Mon Sep 17 00:00:00 2001 From: Archana Rai Date: Tue, 26 Mar 2019 16:33:14 +0530 Subject: [PATCH] [OLINGO-1315]OData v4.0:Client: API to return HTTP Request details --- .../java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java | 4 +++- .../core/communication/request/AbstractODataBasicRequest.java | 2 +- .../communication/request/cud/ODataDeleteRequestImpl.java | 2 +- .../request/cud/ODataEntityCreateRequestImpl.java | 2 +- .../request/cud/ODataEntityUpdateRequestImpl.java | 2 +- .../request/cud/ODataPropertyUpdateRequestImpl.java | 2 +- .../request/cud/ODataReferenceAddingRequestImpl.java | 2 +- .../request/cud/ODataValueUpdateRequestImpl.java | 2 +- .../request/invoke/AbstractODataInvokeRequest.java | 2 +- .../request/retrieve/AbstractODataRetrieveRequest.java | 2 +- .../core/communication/response/AbstractODataResponse.java | 2 +- 11 files changed, 13 insertions(+), 11 deletions(-) diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java index 0cfb1635a..8e303ba56 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java @@ -84,6 +84,7 @@ import org.apache.olingo.client.api.uri.FilterFactory; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.client.api.uri.URIFilter; import org.apache.olingo.client.core.ODataClientFactory; +import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmActionImport; @@ -538,7 +539,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase { newEntity); assertNotNull(createRequest); final ODataEntityCreateResponse createResponse = createRequest.execute(); - + assertNotNull(createRequest.getHttpRequest()); + assertNotNull(((AbstractODataBasicRequest)createRequest).getPayload()); assertEquals(HttpStatusCode.CREATED.getStatusCode(), createResponse.getStatusCode()); assertEquals(SERVICE_URI + ES_ALL_PRIM + "(1)", createResponse.getHeader(HttpHeader.LOCATION).iterator().next()); final ClientEntity createdEntity = createResponse.getBody(); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataBasicRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataBasicRequest.java index 5435f7f42..29b74040a 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataBasicRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataBasicRequest.java @@ -81,7 +81,7 @@ public abstract class AbstractODataBasicRequest * * @return InputStream for entire payload. */ - protected abstract InputStream getPayload(); + public abstract InputStream getPayload(); /** * Serializes the full request into the given batch request. diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java index 245c9b548..7ff866e31 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java @@ -50,7 +50,7 @@ public class ODataDeleteRequestImpl extends AbstractODataBasicRequest } @Override - protected InputStream getPayload() { + public InputStream getPayload() { try { return odataClient.getWriter().writeEntity(entity, ContentType.parse(getContentType())); } catch (final ODataSerializerException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java index 2ddefbbfe..35b9deca5 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java @@ -75,7 +75,7 @@ public class ODataEntityUpdateRequestImpl } @Override - protected InputStream getPayload() { + public InputStream getPayload() { try { return odataClient.getWriter().writeEntity(changes, ContentType.parse(getContentType())); } catch (final ODataSerializerException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java index d7882b403..da889b4fa 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java @@ -84,7 +84,7 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest protected abstract ContentType getPOSTParameterFormat(); @Override - protected InputStream getPayload() { + public InputStream getPayload() { if (!this.parameters.isEmpty() && this.method == HttpMethod.POST) { // Additional, non-binding parameters MUST be sent as JSON final ClientEntity tmp = odataClient.getObjectFactory().newEntity(null); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java index 1896dcd31..feec21118 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java @@ -54,7 +54,7 @@ public abstract class AbstractODataRetrieveRequest * This kind of request doesn't have any payload: null will be returned. */ @Override - protected InputStream getPayload() { + public InputStream getPayload() { return null; } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java index 94460d942..5052e9157 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java @@ -256,7 +256,7 @@ public abstract class AbstractODataResponse implements ODataResponse { throw new NoContentException(); } - if (payload == null && batchInfo.isValidBatch()) { + if (payload == null && batchInfo != null && batchInfo.isValidBatch()) { // get input stream till the end of item payload = new PipedInputStream();