You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ar...@apache.org on 2018/07/26 12:05:11 UTC

olingo-odata4 git commit: [OLINGO-1280]OData V4.0: Client throws exception for Asynchronous Action requests

Repository: olingo-odata4
Updated Branches:
  refs/heads/master 1da33a385 -> e18c6fa18


[OLINGO-1280]OData V4.0: Client throws exception for Asynchronous Action requests


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/e18c6fa1
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/e18c6fa1
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/e18c6fa1

Branch: refs/heads/master
Commit: e18c6fa1841db17c966c3f3dff3e98b9658e1b0c
Parents: 1da33a3
Author: Archana Rai <ar...@sap.com>
Authored: Thu Jul 26 17:34:58 2018 +0530
Committer: Archana Rai <ar...@sap.com>
Committed: Thu Jul 26 17:34:58 2018 +0530

----------------------------------------------------------------------
 .../fit/tecsvc/client/AsyncSupportITCase.java   | 44 +++++++++++++--
 .../invoke/AbstractODataInvokeRequest.java      |  2 +-
 .../request/invoke/ODataInvokeRequestImpl.java  | 59 ++++++++++++++++++++
 3 files changed, 100 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e18c6fa1/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
index 2263e9b..8694605 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
@@ -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.

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e18c6fa1/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
index 8bd3363..5cf9385 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
@@ -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.

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e18c6fa1/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java
index 6d6cc01..f6eaebf 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java
@@ -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;
+    }
+  }
 }