This is an automated email from the ASF dual-hosted git repository. archanarai pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git
The following commit(s) were added to refs/heads/master by this push: new 256b14f [OLINGO-1333]ODataResponse for delta client throws NPE on Asynchronous calls 256b14f is described below commit 256b14f02ba4763e0cf741710b705b987b4e98d5 Author: Archana Rai <archana....@sap.com> AuthorDate: Tue Mar 26 17:05:59 2019 +0530 [OLINGO-1333]ODataResponse for delta client throws NPE on Asynchronous calls --- .../olingo/fit/base/ConformanceTestITCase.java | 45 +++++++++++++++++++++- .../request/retrieve/ODataDeltaRequestImpl.java | 13 ++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/fit/src/test/java/org/apache/olingo/fit/base/ConformanceTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/base/ConformanceTestITCase.java index 7e08428..23215a3 100644 --- a/fit/src/test/java/org/apache/olingo/fit/base/ConformanceTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/base/ConformanceTestITCase.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue; import java.net.URI; +import org.apache.olingo.client.api.communication.request.AsyncRequestFactory; import org.apache.olingo.client.api.communication.request.AsyncRequestWrapper; import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataDeltaRequest; @@ -41,8 +42,8 @@ import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.http.HttpHeader; import org.junit.Test; /** @@ -163,6 +164,48 @@ public class ConformanceTestITCase extends AbstractTestITCase { assertTrue(property.hasComplexValue()); } + + /** + * 10. MAY support deleted entities, link entities, deleted link entities in a delta response for asynch req. + */ + @Test + public void itemAsynch10() { + + final ODataEntitySetRequest<ClientEntitySet> req = client.getRetrieveRequestFactory().getEntitySetRequest( + client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").build()); + req.setPrefer(client.newPreferences().trackChanges()); + + final ClientEntitySet customers = req.execute().getBody(); + assertNotNull(customers); + assertNotNull(customers.getDeltaLink()); + + final ODataDeltaRequest deltaReq = client.getRetrieveRequestFactory().getDeltaRequest(customers.getDeltaLink()); + + AsyncRequestFactory asyncRequestFactory = client.getAsyncRequestFactory(); + AsyncRequestWrapper<ODataRetrieveResponse<ClientDelta>> asyncRequestWrapper = + asyncRequestFactory + .<ODataRetrieveResponse<ClientDelta>>getAsyncRequestWrapper(deltaReq); + + AsyncResponseWrapper<ODataRetrieveResponse<ClientDelta>> responseWrapper = + asyncRequestWrapper + .execute(); + if (responseWrapper.isPreferenceApplied()) { + int waitInSec = 5; + while (!responseWrapper.isDone()) { + try { + Thread.sleep(waitInSec); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + boolean done = responseWrapper.isDone(); + ODataRetrieveResponse<ClientDelta> res = responseWrapper.getODataResponse(); + ClientDelta delta = res.getBody(); // NPE !!! + assertNotNull(delta); + } + /** * 11. MAY support asynchronous responses (section 9.1.3). */ diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java index 7485ad4..629e158 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java @@ -18,6 +18,8 @@ */ package org.apache.olingo.client.core.communication.request.retrieve; +import java.io.IOException; +import java.io.InputStream; import java.net.URI; import org.apache.http.HttpResponse; @@ -27,6 +29,7 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataDeltaReq import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.data.ResWrap; import org.apache.olingo.client.api.domain.ClientDelta; +import org.apache.olingo.client.api.http.HttpClientException; import org.apache.olingo.client.api.serialization.ODataDeserializerException; import org.apache.olingo.commons.api.data.Delta; import org.apache.olingo.commons.api.format.ContentType; @@ -63,12 +66,20 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ClientDe public ClientDelta getBody() { if (delta == null) { try { + InputStream content; + if(res == null){ + content = payload; + }else{ + content = res.getEntity().getContent(); + } final ResWrap<Delta> resource = odataClient.getDeserializer(ContentType.parse(getContentType())). - toDelta(getRawResponse()); + toDelta(content); delta = odataClient.getBinder().getODataDelta(resource); } catch (final ODataDeserializerException e) { throw new IllegalArgumentException(e); + } catch (IOException e) { + throw new HttpClientException(e); } finally { this.close(); }