[OLINGO-1280]OData V4.0: Client throws exception for Asynchronous Action requests
This commit is contained in:
parent
1da33a3853
commit
e18c6fa184
|
@ -18,10 +18,17 @@
|
|||
*/
|
||||
package org.apache.olingo.fit.tecsvc.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -30,32 +37,34 @@ import java.util.concurrent.TimeoutException;
|
|||
import org.apache.olingo.client.api.ODataClient;
|
||||
import org.apache.olingo.client.api.communication.ODataClientErrorException;
|
||||
import org.apache.olingo.client.api.communication.request.AsyncBatchRequestWrapper;
|
||||
import org.apache.olingo.client.api.communication.request.AsyncRequestWrapper;
|
||||
import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
|
||||
import org.apache.olingo.client.api.communication.request.ODataRequest;
|
||||
import org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest;
|
||||
import org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem;
|
||||
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
|
||||
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
|
||||
import org.apache.olingo.client.api.communication.response.AsyncResponseWrapper;
|
||||
import org.apache.olingo.client.api.communication.response.ODataBatchResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
import org.apache.olingo.client.api.data.ResWrap;
|
||||
import org.apache.olingo.client.api.domain.ClientEntity;
|
||||
import org.apache.olingo.client.api.domain.ClientEntitySet;
|
||||
import org.apache.olingo.client.api.domain.ClientProperty;
|
||||
import org.apache.olingo.client.api.domain.ClientValue;
|
||||
import org.apache.olingo.client.api.uri.URIBuilder;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntityCollection;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.format.PreferenceName;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.apache.olingo.fit.tecsvc.TecSvcConst;
|
||||
import org.junit.Test;
|
||||
|
||||
public final class AsyncSupportITCase extends AbstractParamTecSvcITCase {
|
||||
|
@ -242,6 +251,33 @@ public final class AsyncSupportITCase extends AbstractParamTecSvcITCase {
|
|||
assertEquals("First Resource - positive values",
|
||||
entity.getProperty("PropertyString").getPrimitiveValue().toValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void entityAction() throws Exception {
|
||||
Calendar dateTime = Calendar.getInstance();
|
||||
dateTime.clear();
|
||||
dateTime.set(1012, 2, 0, 0, 0, 0);
|
||||
final Map<String, ClientValue> parameters = Collections.singletonMap(
|
||||
"ParameterDate",
|
||||
(ClientValue) getFactory().newPrimitiveValueBuilder()
|
||||
.setType(EdmPrimitiveTypeKind.Date).setValue(dateTime).build());
|
||||
ODataClient client = getClient();
|
||||
URI uri = client.newURIBuilder(TecSvcConst.BASE_URI)
|
||||
.appendActionCallSegment("AIRTESAllPrimParam").build();
|
||||
|
||||
ODataInvokeRequest<ClientEntity> req = client.getInvokeRequestFactory()
|
||||
.getActionInvokeRequest(uri, ClientEntity.class, parameters);
|
||||
AsyncRequestWrapper<ODataRetrieveResponse<ClientEntity>>
|
||||
asyncReqWrp = client.getAsyncRequestFactory().getAsyncRequestWrapper(req);
|
||||
AsyncResponseWrapper<ODataRetrieveResponse<ClientEntity>>
|
||||
asyncRespWrp = asyncReqWrp.execute();
|
||||
waitTillDone(asyncRespWrp, 5);
|
||||
@SuppressWarnings("unchecked")
|
||||
ODataInvokeResponse<ClientEntity> response = (ODataInvokeResponse<ClientEntity>)asyncRespWrp.getODataResponse();
|
||||
|
||||
assertEquals(HttpStatusCode.CREATED.getStatusCode(), response.getStatusCode());
|
||||
assertEquals(TecSvcConst.BASE_URI +"/ESAllPrim(1)", response.getHeader(HttpHeader.LOCATION).iterator().next());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete with async prefer header but without async support from TecSvc.
|
||||
|
|
|
@ -55,7 +55,7 @@ public abstract class AbstractODataInvokeRequest<T extends ClientInvokeResult>
|
|||
extends AbstractODataBasicRequest<ODataInvokeResponse<T>>
|
||||
implements ODataInvokeRequest<T>, ODataBatchableRequest {
|
||||
|
||||
private final Class<T> reference;
|
||||
protected final Class<T> reference;
|
||||
|
||||
/**
|
||||
* Function parameters.
|
||||
|
|
|
@ -18,10 +18,22 @@
|
|||
*/
|
||||
package org.apache.olingo.client.core.communication.request.invoke;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.olingo.client.api.ODataClient;
|
||||
import org.apache.olingo.client.api.communication.request.invoke.ClientNoContent;
|
||||
import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
|
||||
import org.apache.olingo.client.api.domain.ClientEntity;
|
||||
import org.apache.olingo.client.api.domain.ClientEntitySet;
|
||||
import org.apache.olingo.client.api.domain.ClientInvokeResult;
|
||||
import org.apache.olingo.client.api.domain.ClientProperty;
|
||||
import org.apache.olingo.client.api.http.HttpClientException;
|
||||
import org.apache.olingo.client.api.serialization.ODataDeserializerException;
|
||||
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
|
||||
|
@ -45,4 +57,51 @@ public class ODataInvokeRequestImpl<T extends ClientInvokeResult> extends Abstra
|
|||
protected ContentType getPOSTParameterFormat() {
|
||||
return contentType == null ? getDefaultFormat() : contentType;
|
||||
}
|
||||
/**
|
||||
* Response class about an ODataInvokeRequest.
|
||||
*/
|
||||
protected class ODataInvokeResponseImpl extends AbstractODataResponse implements ODataInvokeResponse<T> {
|
||||
|
||||
private T invokeResult = null;
|
||||
|
||||
private ODataInvokeResponseImpl(final ODataClient odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc }
|
||||
*/
|
||||
@Override
|
||||
public T getBody() {
|
||||
if (invokeResult == null) {
|
||||
try {
|
||||
if (ClientNoContent.class.isAssignableFrom(reference)) {
|
||||
invokeResult = reference.cast(new ClientNoContent());
|
||||
} else {
|
||||
// avoid getContent() twice:IllegalStateException: Content has been consumed
|
||||
final InputStream responseStream = this.payload == null ? res.getEntity().getContent() : this.payload;
|
||||
if (ClientEntitySet.class.isAssignableFrom(reference)) {
|
||||
invokeResult = reference.cast(odataClient.getReader().readEntitySet(responseStream,
|
||||
ContentType.parse(getContentType())));
|
||||
} else if (ClientEntity.class.isAssignableFrom(reference)) {
|
||||
invokeResult = reference.cast(odataClient.getReader().readEntity(responseStream,
|
||||
ContentType.parse(getContentType())));
|
||||
} else if (ClientProperty.class.isAssignableFrom(reference)) {
|
||||
invokeResult = reference.cast(odataClient.getReader().readProperty(responseStream,
|
||||
ContentType.parse(getContentType())));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException(e);
|
||||
} catch (final ODataDeserializerException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
} finally {
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
return invokeResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue