You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/08/15 05:43:38 UTC

[camel] branch master updated (8996859 -> 74e9af3)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 8996859  Fixed CS
     new 895dee3  CAMEL-13852: Support OData action's
     new dcf2160  CAMEL-13852: checkstyle fixes
     new f0bcf14  CAMEL-13852: use default timeout in tests
     new 8a6ec55  CAMEL-13852: document actions
     new 6d3ccf5  CAMEL-13852: refactoring remove duplicated code
     new 74e9af3  CAMEL-13852: use constants for http status code

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/olingo4/api/Olingo4App.java    | 10 +++
 .../component/olingo4/api/impl/Olingo4AppImpl.java | 76 +++++++++++++++-------
 .../camel/component/olingo4/Olingo4AppAPITest.java | 73 +++++++++++++++++++++
 .../camel-olingo4/camel-olingo4-component/pom.xml  |  1 +
 .../src/main/docs/olingo4-component.adoc           | 16 +++++
 .../src/signatures/olingo-api-signature.txt        |  1 +
 .../olingo4/Olingo4ComponentProducerTest.java      | 21 ++++++
 7 files changed, 173 insertions(+), 25 deletions(-)


[camel] 05/06: CAMEL-13852: refactoring remove duplicated code

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 6d3ccf5641af3ee27f08b6b1d8a824656c9f2342
Author: Marc Giger <gi...@gmx.ch>
AuthorDate: Wed Aug 14 19:58:55 2019 +0200

    CAMEL-13852: refactoring remove duplicated code
---
 .../component/olingo4/api/impl/Olingo4AppImpl.java | 75 ++++++++++++----------
 1 file changed, 40 insertions(+), 35 deletions(-)

diff --git a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
index e1b8c8b..bf0b2ed 100644
--- a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
+++ b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
@@ -512,59 +512,33 @@ public final class Olingo4AppImpl implements Olingo4App {
     }
 
     private AbstractHttpEntity writeContent(final Edm edm, final UriInfo uriInfo, final Object content) throws ODataException {
-        InputStream requestStream = null;
-        AbstractHttpEntity httpEntity = null;
+        AbstractHttpEntity httpEntity;
+
         if (uriInfo.getKind() == UriInfoKind.resource) {
             // any resource entity
             List<UriResource> listResource = uriInfo.getUriResourceParts();
             UriResourceKind lastResourceKind = listResource.get(listResource.size() - 1).getKind();
             switch (lastResourceKind) {
             case action:
-                if (content == null) {
-                    requestStream = new ByteArrayInputStream(new byte[0]);
-                } else if (content instanceof ClientEntity) {
-                    requestStream = odataWriter.writeEntity((ClientEntity)content, getResourceContentType(uriInfo));
-                } else if (content instanceof String) {
-                    httpEntity = new StringEntity((String) content, org.apache.http.entity.ContentType.APPLICATION_JSON);
-                    httpEntity.setChunked(false);
-                    return httpEntity;
+                if (content == null) { // actions may have no input
+                    httpEntity = new ByteArrayEntity(new byte[0]);
                 } else {
-                    throw new ODataException("Unsupported content type: " + content);
+                    httpEntity = writeContent(uriInfo, content);
                 }
                 break;
             case entitySet:
-                if (content instanceof ClientEntity) {
-                    requestStream = odataWriter.writeEntity((ClientEntity)content, getResourceContentType(uriInfo));
-                } else if (content instanceof String) {
-                    httpEntity = new StringEntity((String) content, org.apache.http.entity.ContentType.APPLICATION_JSON);
-                    httpEntity.setChunked(false);
-                    return httpEntity;
-                } else {
-                    throw new ODataException("Unsupported content type: " + content);
-                }
+                httpEntity = writeContent(uriInfo, content);
                 break;
             default:
                 throw new ODataException("Unsupported resource type: " + lastResourceKind);
             }
-            try {
-                httpEntity = new ByteArrayEntity(IOUtils.toByteArray(requestStream));
-            } catch (IOException e) {
-                throw new ODataException("Error during converting input stream to byte array", e);
-            }
-            httpEntity.setChunked(false);
-
         } else if (uriInfo.getKind() == UriInfoKind.batch) {
             final String boundary = BOUNDARY_PREFIX + UUID.randomUUID();
             final String contentHeader = BATCH_CONTENT_TYPE + BOUNDARY_PARAMETER + boundary;
-            final List<Olingo4BatchRequest> batchParts = (List<Olingo4BatchRequest>)content;
+            final List<Olingo4BatchRequest> batchParts = (List<Olingo4BatchRequest>) content;
 
-            requestStream = serializeBatchRequest(edm, batchParts, BOUNDARY_DOUBLE_DASH + boundary);
-            try {
-                httpEntity = new ByteArrayEntity(IOUtils.toByteArray(requestStream));
-            } catch (IOException e) {
-                throw new ODataException("Error during converting input stream to byte array", e);
-            }
-            httpEntity.setChunked(false);
+            final InputStream requestStream = serializeBatchRequest(edm, batchParts, BOUNDARY_DOUBLE_DASH + boundary);
+            httpEntity = writeContent(requestStream);
             httpEntity.setContentType(contentHeader);
         } else {
             throw new ODataException("Unsupported resource type: " + uriInfo.getKind().name());
@@ -573,6 +547,37 @@ public final class Olingo4AppImpl implements Olingo4App {
         return httpEntity;
     }
 
+    private AbstractHttpEntity writeContent(UriInfo uriInfo, Object content) throws ODataException {
+        AbstractHttpEntity httpEntity;
+
+        if (content instanceof ClientEntity) {
+            final InputStream requestStream = odataWriter.writeEntity((ClientEntity) content, getResourceContentType(uriInfo));
+            httpEntity = writeContent(requestStream);
+        } else if (content instanceof String) {
+            httpEntity = new StringEntity((String) content, org.apache.http.entity.ContentType.APPLICATION_JSON);
+        } else {
+            throw new ODataException("Unsupported content type: " + content);
+        }
+
+        httpEntity.setChunked(false);
+
+        return httpEntity;
+    }
+
+    private AbstractHttpEntity writeContent(InputStream inputStream) throws ODataException {
+        AbstractHttpEntity httpEntity;
+        
+        try {
+            httpEntity = new ByteArrayEntity(IOUtils.toByteArray(inputStream));
+        } catch (IOException e) {
+            throw new ODataException("Error during converting input stream to byte array", e);
+        }
+
+        httpEntity.setChunked(false);
+
+        return httpEntity;
+    }
+
     private InputStream serializeBatchRequest(final Edm edm, final List<Olingo4BatchRequest> batchParts, String boundary) throws ODataException {
         final ByteArrayOutputStream batchRequestHeaderOutputStream = new ByteArrayOutputStream();
 


[camel] 03/06: CAMEL-13852: use default timeout in tests

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f0bcf14c7f2bfa155c9c4e25b0dc003a9d124245
Author: Marc Giger <gi...@gmx.ch>
AuthorDate: Sun Aug 11 15:25:08 2019 +0200

    CAMEL-13852: use default timeout in tests
---
 .../java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java  | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java b/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
index 2261414..e8385a8 100644
--- a/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
+++ b/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
@@ -419,7 +419,7 @@ public class Olingo4AppAPITest {
         final TestOlingo4ResponseHandler<HttpStatusCode> responseHandler = new TestOlingo4ResponseHandler<>();
         olingoApp.action(edm, TEST_UNBOUND_ACTION_RESETDATASOURCE, null, null, responseHandler);
 
-        final HttpStatusCode statusCode = responseHandler.await(15, TimeUnit.MINUTES);
+        final HttpStatusCode statusCode = responseHandler.await();
         assertEquals(204, statusCode.getStatusCode());
     }
 
@@ -432,7 +432,7 @@ public class Olingo4AppAPITest {
         final TestOlingo4ResponseHandler<HttpStatusCode> responseHandler = new TestOlingo4ResponseHandler<>();
         olingoApp.action(edm, TEST_BOUND_ACTION_PEOPLE_SHARETRIP, null, clientEntity, responseHandler);
 
-        final HttpStatusCode statusCode = responseHandler.await(15, TimeUnit.MINUTES);
+        final HttpStatusCode statusCode = responseHandler.await();
         assertEquals(204, statusCode.getStatusCode());
     }
 
@@ -474,7 +474,7 @@ public class Olingo4AppAPITest {
         final TestOlingo4ResponseHandler<ClientEntity> actionResponseHandler = new TestOlingo4ResponseHandler<>();
         olingoApp.action(edm, TEST_BOUND_ACTION_PEOPLE_SHARETRIP, null, clientEntity, actionResponseHandler);
 
-        final ClientEntity result = actionResponseHandler.await(15, TimeUnit.MINUTES);
+        final ClientEntity result = actionResponseHandler.await();
         assertEquals("lewisblack", result.getProperty("UserName").getValue().toString());
     }
 


[camel] 06/06: CAMEL-13852: use constants for http status code

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 74e9af30469d0a820438e11912862d8ef0e874c3
Author: Marc Giger <gi...@gmx.ch>
AuthorDate: Wed Aug 14 20:06:47 2019 +0200

    CAMEL-13852: use constants for http status code
---
 .../org/apache/camel/component/olingo4/Olingo4AppAPITest.java     | 8 ++++----
 .../camel/component/olingo4/Olingo4ComponentProducerTest.java     | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java b/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
index e8385a8..7422298 100644
--- a/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
+++ b/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
@@ -420,7 +420,7 @@ public class Olingo4AppAPITest {
         olingoApp.action(edm, TEST_UNBOUND_ACTION_RESETDATASOURCE, null, null, responseHandler);
 
         final HttpStatusCode statusCode = responseHandler.await();
-        assertEquals(204, statusCode.getStatusCode());
+        assertEquals(HttpStatusCode.NO_CONTENT, statusCode);
     }
 
     @Test
@@ -433,7 +433,7 @@ public class Olingo4AppAPITest {
         olingoApp.action(edm, TEST_BOUND_ACTION_PEOPLE_SHARETRIP, null, clientEntity, responseHandler);
 
         final HttpStatusCode statusCode = responseHandler.await();
-        assertEquals(204, statusCode.getStatusCode());
+        assertEquals(HttpStatusCode.NO_CONTENT, statusCode);
     }
 
 
@@ -447,13 +447,13 @@ public class Olingo4AppAPITest {
         httpClientBuilder.addInterceptorFirst(new HttpResponseInterceptor() {
             @Override
             public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
-                if (response.getStatusLine().getStatusCode() == 204) {
+                if (response.getStatusLine().getStatusCode() == HttpStatusCode.NO_CONTENT.getStatusCode()) {
                     try {
                         response.setEntity(
                                 new InputStreamEntity(
                                         odataWriter.writeEntity(createEntity(), ContentType.JSON),
                                         org.apache.http.entity.ContentType.parse(ContentType.JSON.toContentTypeString())));
-                        response.setStatusCode(200);
+                        response.setStatusCode(HttpStatusCode.OK.getStatusCode());
                     } catch (ODataSerializerException e) {
                         throw new IOException(e);
                     }
diff --git a/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentProducerTest.java b/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentProducerTest.java
index 13a1de6..46e899e 100644
--- a/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentProducerTest.java
+++ b/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentProducerTest.java
@@ -276,7 +276,7 @@ public class Olingo4ComponentProducerTest extends AbstractOlingo4TestSupport {
     @Test
     public void testUnboundActionRequest() throws Exception {
         final HttpStatusCode status = requestBody("direct:unbound-action-ResetDataSource", null);
-        assertEquals(204, status.getStatusCode());
+        assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode());
     }
 
     @Test
@@ -286,7 +286,7 @@ public class Olingo4ComponentProducerTest extends AbstractOlingo4TestSupport {
         clientEntity.getProperties().add(objFactory.newPrimitiveProperty("tripId", objFactory.newPrimitiveValueBuilder().buildInt32(0)));
 
         final HttpStatusCode status = requestBody("direct:bound-action-people", clientEntity);
-        assertEquals(204, status.getStatusCode());
+        assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode());
     }
 
     @SuppressWarnings("unchecked")


[camel] 01/06: CAMEL-13852: Support OData action's

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 895dee3d9fe5fbc0f07afc1e12cbd2f9450a330b
Author: Marc Giger <gi...@gmx.ch>
AuthorDate: Sun Aug 11 14:08:01 2019 +0200

    CAMEL-13852: Support OData action's
---
 .../camel/component/olingo4/api/Olingo4App.java    | 10 +++
 .../component/olingo4/api/impl/Olingo4AppImpl.java | 31 ++++++---
 .../camel/component/olingo4/Olingo4AppAPITest.java | 73 ++++++++++++++++++++++
 .../camel-olingo4/camel-olingo4-component/pom.xml  |  1 +
 .../src/signatures/olingo-api-signature.txt        |  1 +
 .../olingo4/Olingo4ComponentProducerTest.java      | 21 +++++++
 6 files changed, 129 insertions(+), 8 deletions(-)

diff --git a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/Olingo4App.java b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/Olingo4App.java
index 3863c1b..0649a7c 100644
--- a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/Olingo4App.java
+++ b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/Olingo4App.java
@@ -149,4 +149,14 @@ public interface Olingo4App {
      * @param responseHandler callback handler
      */
     void batch(Edm edm, Map<String, String> endpointHttpHeaders, Object data, Olingo4ResponseHandler<List<Olingo4BatchResponse>> responseHandler);
+
+    /**
+     * Calls a OData action
+     * @param edm service Edm
+     * @param resourcePath resource path to action
+     * @param endpointHttpHeaders HTTP Headers to add/override the component versions
+     * @param data action data
+     * @param responseHandler {@link org.apache.olingo.client.api.domain.ClientEntity} callback handler
+     */
+    <T> void action(Edm edm, String resourcePath, Map<String, String> endpointHttpHeaders, Object data, Olingo4ResponseHandler<T> responseHandler);
 }
diff --git a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
index c59e562..84ef1e3 100644
--- a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
+++ b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
@@ -40,14 +40,7 @@ import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.LineIterator;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.http.Consts;
-import org.apache.http.Header;
-import org.apache.http.HttpException;
-import org.apache.http.HttpHeaders;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpResponseFactory;
-import org.apache.http.HttpVersion;
-import org.apache.http.StatusLine;
+import org.apache.http.*;
 import org.apache.http.client.entity.DecompressingEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpDelete;
@@ -60,6 +53,7 @@ import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.config.MessageConstraints;
 import org.apache.http.entity.AbstractHttpEntity;
+import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.DefaultHttpResponseFactory;
@@ -311,6 +305,13 @@ public final class Olingo4AppImpl implements Olingo4App {
         writeContent(edm, new HttpPost(createUri(SegmentType.BATCH.getValue(), null)), uriInfo, data, endpointHttpHeaders, responseHandler);
     }
 
+    @Override
+    public <T> void action(final Edm edm, final String resourcePath, final Map<String, String> endpointHttpHeaders, final Object data, final Olingo4ResponseHandler<T> responseHandler) {
+        final UriInfo uriInfo = parseUri(edm, resourcePath, null, serviceUri);
+
+        writeContent(edm, new HttpPost(createUri(resourcePath, null)), uriInfo, data, endpointHttpHeaders, responseHandler);
+    }
+
     private ContentType getResourceContentType(UriInfo uriInfo) {
         ContentType resourceContentType;
         switch (uriInfo.getKind()) {
@@ -478,6 +479,7 @@ public final class Olingo4AppImpl implements Olingo4App {
                             List<UriResource> listResource = uriInfo.getUriResourceParts();
                             UriResourceKind lastResourceKind = listResource.get(listResource.size() - 1).getKind();
                             switch (lastResourceKind) {
+                            case action:
                             case entitySet:
                                 ClientEntity entity = odataReader.readEntity(result.getEntity().getContent(),
                                                                              ContentType.parse(result.getEntity().getContentType().getValue()));
@@ -511,6 +513,19 @@ public final class Olingo4AppImpl implements Olingo4App {
             List<UriResource> listResource = uriInfo.getUriResourceParts();
             UriResourceKind lastResourceKind = listResource.get(listResource.size() - 1).getKind();
             switch (lastResourceKind) {
+            case action:
+                if (content == null) {
+                    requestStream = new ByteArrayInputStream(new byte[0]);
+                } else if (content instanceof ClientEntity) {
+                    requestStream = odataWriter.writeEntity((ClientEntity)content, getResourceContentType(uriInfo));
+                } else if (content instanceof String) {
+                    httpEntity = new StringEntity((String) content, org.apache.http.entity.ContentType.APPLICATION_JSON);
+                    httpEntity.setChunked(false);
+                    return httpEntity;
+                } else {
+                    throw new ODataException("Unsupported content type: " + content);
+                }
+                break;
             case entitySet:
                 if (content instanceof ClientEntity) {
                     requestStream = odataWriter.writeEntity((ClientEntity)content, getResourceContentType(uriInfo));
diff --git a/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java b/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
index 728cb2d..86ebfc6 100644
--- a/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
+++ b/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
@@ -39,11 +39,16 @@ import org.apache.camel.component.olingo4.api.batch.Olingo4BatchRequest;
 import org.apache.camel.component.olingo4.api.batch.Olingo4BatchResponse;
 import org.apache.camel.component.olingo4.api.batch.Operation;
 import org.apache.camel.component.olingo4.api.impl.Olingo4AppImpl;
+import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseInterceptor;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.ExecutionContext;
@@ -60,6 +65,8 @@ import org.apache.olingo.client.api.domain.ClientProperty;
 import org.apache.olingo.client.api.domain.ClientServiceDocument;
 import org.apache.olingo.client.api.domain.ClientValue;
 import org.apache.olingo.client.api.serialization.ODataReader;
+import org.apache.olingo.client.api.serialization.ODataSerializerException;
+import org.apache.olingo.client.api.serialization.ODataWriter;
 import org.apache.olingo.client.core.ODataClientFactory;
 import org.apache.olingo.commons.api.Constants;
 import org.apache.olingo.commons.api.edm.Edm;
@@ -98,6 +105,8 @@ public class Olingo4AppAPITest {
     private static final String TEST_AIRPORTS_COMPLEX_PROPERTY = TEST_AIRPORT + "/Location";
     private static final String TEST_AIRPORTS_SIMPLE_PROPERTY_VALUE = TEST_AIRPORTS_SIMPLE_PROPERTY + "/$value";
     private static final String COUNT_OPTION = "/$count";
+    private static final String TEST_UNBOUND_ACTION_RESETDATASOURCE = "ResetDataSource";
+    private static final String TEST_BOUND_ACTION_PEOPLE_SHARETRIP = TEST_PEOPLE +"/Microsoft.OData.Service.Sample.TrippinInMemory.Models.ShareTrip";
 
     private static final String TEST_SERVICE_BASE_URL = "http://services.odata.org/TripPinRESTierService";
     private static final ContentType TEST_FORMAT = ContentType.APPLICATION_JSON;
@@ -405,6 +414,70 @@ public class Olingo4AppAPITest {
         assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), responseParts.get(7).getStatusCode());
     }
 
+    @Test
+    public void testUnboundActionRequest() throws Exception {
+        final TestOlingo4ResponseHandler<HttpStatusCode> responseHandler = new TestOlingo4ResponseHandler<>();
+        olingoApp.action(edm, TEST_UNBOUND_ACTION_RESETDATASOURCE, null, null, responseHandler);
+
+        final HttpStatusCode statusCode = responseHandler.await(15, TimeUnit.MINUTES);
+        assertEquals(204, statusCode.getStatusCode());
+    }
+
+    @Test
+    public void testBoundActionRequest() throws Exception {
+        final ClientEntity clientEntity = objFactory.newEntity(null);
+        clientEntity.getProperties().add(objFactory.newPrimitiveProperty("userName", objFactory.newPrimitiveValueBuilder().buildString("scottketchum")));
+        clientEntity.getProperties().add(objFactory.newPrimitiveProperty("tripId", objFactory.newPrimitiveValueBuilder().buildInt32(0)));
+
+        final TestOlingo4ResponseHandler<HttpStatusCode> responseHandler = new TestOlingo4ResponseHandler<>();
+        olingoApp.action(edm, TEST_BOUND_ACTION_PEOPLE_SHARETRIP, null, clientEntity, responseHandler);
+
+        final HttpStatusCode statusCode = responseHandler.await(15, TimeUnit.MINUTES);
+        assertEquals(204, statusCode.getStatusCode());
+    }
+
+
+    // Unfortunately there is no action that returns a client entity. So we fake one
+    @Test
+    public void testBoundActionRequestWithClientEntityResponse() throws Exception {
+        final ODataClient odataClient = ODataClientFactory.getClient();
+        final ODataWriter odataWriter = odataClient.getWriter();
+
+        final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
+        httpClientBuilder.addInterceptorFirst(new HttpResponseInterceptor() {
+            @Override
+            public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
+                if (response.getStatusLine().getStatusCode() == 204) {
+                    try {
+                        response.setEntity(
+                                new InputStreamEntity(
+                                        odataWriter.writeEntity(createEntity(), ContentType.JSON),
+                                        org.apache.http.entity.ContentType.parse(ContentType.JSON.toContentTypeString())));
+                        response.setStatusCode(200);
+                    } catch (ODataSerializerException e) {
+                        throw new IOException(e);
+                    }
+                }
+            }
+        });
+        final Olingo4App olingoApp = new Olingo4AppImpl(getRealServiceUrl(TEST_SERVICE_BASE_URL), httpClientBuilder);
+        olingoApp.setContentType(TEST_FORMAT_STRING);
+
+        final TestOlingo4ResponseHandler<Edm> responseHandler = new TestOlingo4ResponseHandler<>();
+        olingoApp.read(null, Constants.METADATA, null, null, responseHandler);
+        final Edm edm = responseHandler.await();
+
+        final ClientEntity clientEntity = objFactory.newEntity(null);
+        clientEntity.getProperties().add(objFactory.newPrimitiveProperty("userName", objFactory.newPrimitiveValueBuilder().buildString("scottketchum")));
+        clientEntity.getProperties().add(objFactory.newPrimitiveProperty("tripId", objFactory.newPrimitiveValueBuilder().buildInt32(0)));
+
+        final TestOlingo4ResponseHandler<ClientEntity> actionResponseHandler = new TestOlingo4ResponseHandler<>();
+        olingoApp.action(edm, TEST_BOUND_ACTION_PEOPLE_SHARETRIP, null, clientEntity, actionResponseHandler);
+
+        final ClientEntity result = actionResponseHandler.await(15, TimeUnit.MINUTES);
+        assertEquals("lewisblack", result.getProperty("UserName").getValue().toString());
+    }
+
     private ClientEntity createEntity() {
         ClientEntity clientEntity = objFactory.newEntity(null);
 
diff --git a/components/camel-olingo4/camel-olingo4-component/pom.xml b/components/camel-olingo4/camel-olingo4-component/pom.xml
index adcd6af..0f14877 100644
--- a/components/camel-olingo4/camel-olingo4-component/pom.xml
+++ b/components/camel-olingo4/camel-olingo4-component/pom.xml
@@ -149,6 +149,7 @@
                                         <nullableOption>endpointHttpHeaders</nullableOption>
                                         <nullableOption>edm</nullableOption>
                                         <nullableOption>responseHandler</nullableOption>
+                                        <nullableOption>data</nullableOption>
                                     </nullableOptions>
                                 </api>
                             </apis>
diff --git a/components/camel-olingo4/camel-olingo4-component/src/signatures/olingo-api-signature.txt b/components/camel-olingo4/camel-olingo4-component/src/signatures/olingo-api-signature.txt
index fb941e6..66a2110 100644
--- a/components/camel-olingo4/camel-olingo4-component/src/signatures/olingo-api-signature.txt
+++ b/components/camel-olingo4/camel-olingo4-component/src/signatures/olingo-api-signature.txt
@@ -6,3 +6,4 @@ void update(org.apache.olingo.commons.api.edm.Edm edm, String resourcePath, java
 void patch(org.apache.olingo.commons.api.edm.Edm edm, String resourcePath, java.util.Map<String, String> endpointHttpHeaders, Object data, org.apache.camel.component.olingo4.api.Olingo4ResponseHandler responseHandler);
 void merge(org.apache.olingo.commons.api.edm.Edm edm, String resourcePath, java.util.Map<String, String> endpointHttpHeaders, Object data, org.apache.camel.component.olingo4.api.Olingo4ResponseHandler responseHandler);
 void batch(org.apache.olingo.commons.api.edm.Edm edm, java.util.Map<String, String> endpointHttpHeaders, Object data, org.apache.camel.component.olingo4.api.Olingo4ResponseHandler responseHandler);
+void action(org.apache.olingo.commons.api.edm.Edm edm, String resourcePath, java.util.Map<String, String> endpointHttpHeaders, Object data, org.apache.camel.component.olingo4.api.Olingo4ResponseHandler responseHandler);
diff --git a/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentProducerTest.java b/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentProducerTest.java
index 2493b94..13a1de6 100644
--- a/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentProducerTest.java
+++ b/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentProducerTest.java
@@ -273,6 +273,22 @@ public class Olingo4ComponentProducerTest extends AbstractOlingo4TestSupport {
         LOG.info("Read deleted entity error: {}", error.getMessage());
     }
 
+    @Test
+    public void testUnboundActionRequest() throws Exception {
+        final HttpStatusCode status = requestBody("direct:unbound-action-ResetDataSource", null);
+        assertEquals(204, status.getStatusCode());
+    }
+
+    @Test
+    public void testBoundActionRequest() throws Exception {
+        final ClientEntity clientEntity = objFactory.newEntity(null);
+        clientEntity.getProperties().add(objFactory.newPrimitiveProperty("userName", objFactory.newPrimitiveValueBuilder().buildString("scottketchum")));
+        clientEntity.getProperties().add(objFactory.newPrimitiveProperty("tripId", objFactory.newPrimitiveValueBuilder().buildInt32(0)));
+
+        final HttpStatusCode status = requestBody("direct:bound-action-people", clientEntity);
+        assertEquals(204, status.getStatusCode());
+    }
+
     @SuppressWarnings("unchecked")
     @Test
     public void testEndpointHttpHeaders() throws Exception {
@@ -425,6 +441,11 @@ public class Olingo4ComponentProducerTest extends AbstractOlingo4TestSupport {
                 from("direct:read-people-nofilterseen").to("olingo4://read/" + PEOPLE).to("mock:producer-noalreadyseen");
 
                 from("direct:read-people-filterseen").to("olingo4://read/" + PEOPLE + "?filterAlreadySeen=true").to("mock:producer-alreadyseen");
+
+                // test routes action's
+                from("direct:unbound-action-ResetDataSource").to("olingo4://action/ResetDataSource");
+
+                from("direct:bound-action-people").to("olingo4://action/" + TEST_PEOPLE + "/Microsoft.OData.Service.Sample.TrippinInMemory.Models.ShareTrip");
             }
         };
     }


[camel] 04/06: CAMEL-13852: document actions

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 8a6ec5505223ce05daec4e7540409f29d74e852c
Author: Marc Giger <gi...@gmx.ch>
AuthorDate: Wed Aug 14 18:48:16 2019 +0200

    CAMEL-13852: document actions
---
 .../src/main/docs/olingo4-component.adoc                 | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/components/camel-olingo4/camel-olingo4-component/src/main/docs/olingo4-component.adoc b/components/camel-olingo4/camel-olingo4-component/src/main/docs/olingo4-component.adoc
index 5951da4..8aca8ab 100644
--- a/components/camel-olingo4/camel-olingo4-component/src/main/docs/olingo4-component.adoc
+++ b/components/camel-olingo4/camel-olingo4-component/src/main/docs/olingo4-component.adoc
@@ -191,6 +191,9 @@ org.apache.olingo.commons.api.http.HttpStatusCode for other OData resources
 |read |queryParams, resourcePath, endpointHttpHeaders |GET |Depends on OData resource being queried as described next
 
 |update |data, resourcePath, endpointHttpHeaders |PUT |org.apache.olingo.commons.api.http.HttpStatusCode
+
+|action |data, resourcePath, endpointHttpHeaders |POST |org.apache.olingo.client.api.domain.ClientEntity for action's
+that have a "ReturnType" defined org.apache.olingo.commons.api.http.HttpStatusCode otherwise
 |=======================================================================
 
 == Endpoint HTTP Headers
@@ -295,3 +298,16 @@ The following route creates People entity using the
 from("direct:...")
     .to("olingo4://create/People");
 ------------------------------------------------------------
+
+
+
+The following route calls an odata action using the *ClientEntity* in the body message. The body message may be null for
+actions that don't expect an input.
+
+
+
+[source,java]
+------------------------------------------------------------
+from("direct:...")
+    .to("olingo4://action/People");
+------------------------------------------------------------


[camel] 02/06: CAMEL-13852: checkstyle fixes

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit dcf2160135a134259f57c37a04474b0838d15134
Author: Marc Giger <gi...@gmx.ch>
AuthorDate: Sun Aug 11 15:13:08 2019 +0200

    CAMEL-13852: checkstyle fixes
---
 .../camel/component/olingo4/api/impl/Olingo4AppImpl.java       | 10 ++++++++--
 .../org/apache/camel/component/olingo4/Olingo4AppAPITest.java  |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
index 84ef1e3..e1b8c8b 100644
--- a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
+++ b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
@@ -40,7 +40,14 @@ import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.LineIterator;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.http.*;
+import org.apache.http.Consts;
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseFactory;
+import org.apache.http.HttpVersion;
+import org.apache.http.StatusLine;
 import org.apache.http.client.entity.DecompressingEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpDelete;
@@ -53,7 +60,6 @@ import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.config.MessageConstraints;
 import org.apache.http.entity.AbstractHttpEntity;
-import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.DefaultHttpResponseFactory;
diff --git a/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java b/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
index 86ebfc6..2261414 100644
--- a/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
+++ b/components/camel-olingo4/camel-olingo4-api/src/test/java/org/apache/camel/component/olingo4/Olingo4AppAPITest.java
@@ -106,7 +106,7 @@ public class Olingo4AppAPITest {
     private static final String TEST_AIRPORTS_SIMPLE_PROPERTY_VALUE = TEST_AIRPORTS_SIMPLE_PROPERTY + "/$value";
     private static final String COUNT_OPTION = "/$count";
     private static final String TEST_UNBOUND_ACTION_RESETDATASOURCE = "ResetDataSource";
-    private static final String TEST_BOUND_ACTION_PEOPLE_SHARETRIP = TEST_PEOPLE +"/Microsoft.OData.Service.Sample.TrippinInMemory.Models.ShareTrip";
+    private static final String TEST_BOUND_ACTION_PEOPLE_SHARETRIP = TEST_PEOPLE + "/Microsoft.OData.Service.Sample.TrippinInMemory.Models.ShareTrip";
 
     private static final String TEST_SERVICE_BASE_URL = "http://services.odata.org/TripPinRESTierService";
     private static final ContentType TEST_FORMAT = ContentType.APPLICATION_JSON;