[OLINGO-1333]ODataResponse for delta client throws NPE on Asynchronous calls
This commit is contained in:
parent
f91568e1ab
commit
256b14f02b
|
@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.net.URI;
|
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.AsyncRequestWrapper;
|
||||||
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
|
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
|
||||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataDeltaRequest;
|
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.client.api.uri.URIBuilder;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
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.format.ContentType;
|
||||||
|
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,6 +164,48 @@ public class ConformanceTestITCase extends AbstractTestITCase {
|
||||||
assertTrue(property.hasComplexValue());
|
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).
|
* 11. MAY support asynchronous responses (section 9.1.3).
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.client.core.communication.request.retrieve;
|
package org.apache.olingo.client.core.communication.request.retrieve;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
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.communication.response.ODataRetrieveResponse;
|
||||||
import org.apache.olingo.client.api.data.ResWrap;
|
import org.apache.olingo.client.api.data.ResWrap;
|
||||||
import org.apache.olingo.client.api.domain.ClientDelta;
|
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.client.api.serialization.ODataDeserializerException;
|
||||||
import org.apache.olingo.commons.api.data.Delta;
|
import org.apache.olingo.commons.api.data.Delta;
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
|
@ -63,12 +66,20 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ClientDe
|
||||||
public ClientDelta getBody() {
|
public ClientDelta getBody() {
|
||||||
if (delta == null) {
|
if (delta == null) {
|
||||||
try {
|
try {
|
||||||
|
InputStream content;
|
||||||
|
if(res == null){
|
||||||
|
content = payload;
|
||||||
|
}else{
|
||||||
|
content = res.getEntity().getContent();
|
||||||
|
}
|
||||||
final ResWrap<Delta> resource = odataClient.getDeserializer(ContentType.parse(getContentType())).
|
final ResWrap<Delta> resource = odataClient.getDeserializer(ContentType.parse(getContentType())).
|
||||||
toDelta(getRawResponse());
|
toDelta(content);
|
||||||
|
|
||||||
delta = odataClient.getBinder().getODataDelta(resource);
|
delta = odataClient.getBinder().getODataDelta(resource);
|
||||||
} catch (final ODataDeserializerException e) {
|
} catch (final ODataDeserializerException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new HttpClientException(e);
|
||||||
} finally {
|
} finally {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue