You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/10/30 10:47:56 UTC

[camel-quarkus] branch master updated (44d18e8 -> ac1ef8f)

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

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


    from 44d18e8  Fix #270 TarfileTest can fail on exotic platforms
     new b208492  Fix #220 platform-http component should return 204 for success and no body
     new ac1ef8f  Fix #299 Use Camel's async processor in platform-http

The 2 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:
 .../http/runtime/QuarkusPlatformHttpConsumer.java  | 52 ++++++++++++++++------
 .../platform/http/it/PlatformHttpRouteBuilder.java | 11 +++++
 .../component/http/server/it/PlatformHttpTest.java | 36 +++++++++++++++
 3 files changed, 85 insertions(+), 14 deletions(-)


[camel-quarkus] 02/02: Fix #299 Use Camel's async processor in platform-http

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

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

commit ac1ef8f2344a51599efc4a48d48b07f8fb3d96c3
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Wed Oct 30 09:44:22 2019 +0100

    Fix #299 Use Camel's async processor in platform-http
---
 .../http/runtime/QuarkusPlatformHttpConsumer.java        | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java
index 051805c..b9bfa99 100644
--- a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java
+++ b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java
@@ -111,13 +111,21 @@ public class QuarkusPlatformHttpConsumer extends DefaultConsumer {
 
         newRoute.handler(
             ctx -> {
+                Exchange exchg = null;
                 try {
-                    final Exchange e = toExchange(ctx);
-                    getProcessor().process(e);
-                    writeResponse(ctx, e, getEndpoint().getHeaderFilterStrategy());
+                    final Exchange exchange = exchg = toExchange(ctx);
+                    createUoW(exchange);
+                    getAsyncProcessor().process(
+                        exchange,
+                        doneSync -> writeResponse(ctx, exchange, getEndpoint().getHeaderFilterStrategy())
+                    );
                 } catch (Exception e) {
-                    LOG.debugf(e, "Could not handle '%s'", path);
                     ctx.fail(e);
+                    getExceptionHandler().handleException("Failed handling platform-http endpoint " + path, exchg, e);
+                } finally {
+                    if (exchg != null) {
+                        doneUoW(exchg);
+                    }
                 }
             }
         );


[camel-quarkus] 01/02: Fix #220 platform-http component should return 204 for success and no body

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

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

commit b20849240e73559f761cadc0f64f098f4283590f
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Tue Oct 29 12:31:15 2019 +0100

    Fix #220 platform-http component should return 204 for success and no body
---
 .../http/runtime/QuarkusPlatformHttpConsumer.java  | 36 ++++++++++++++++------
 .../platform/http/it/PlatformHttpRouteBuilder.java | 11 +++++++
 .../component/http/server/it/PlatformHttpTest.java | 36 ++++++++++++++++++++++
 3 files changed, 73 insertions(+), 10 deletions(-)

diff --git a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java
index 46886d1..051805c 100644
--- a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java
+++ b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java
@@ -152,11 +152,8 @@ public class QuarkusPlatformHttpConsumer extends DefaultConsumer {
 
     static Object toHttpResponse(HttpServerResponse response, Message message, HeaderFilterStrategy headerFilterStrategy) {
         final Exchange exchange = message.getExchange();
-        final boolean failed = exchange.isFailed();
-        final int defaultCode = failed ? 500 : 200;
-
-        final int code = message.getHeader(Exchange.HTTP_RESPONSE_CODE, defaultCode, int.class);
 
+        final int code = determineResponseCode(exchange, message.getBody());
         response.setStatusCode(code);
 
         final TypeConverter tc = exchange.getContext().getTypeConverter();
@@ -220,18 +217,37 @@ public class QuarkusPlatformHttpConsumer extends DefaultConsumer {
         return body;
     }
 
+    /*
+     * Copied from org.apache.camel.http.common.DefaultHttpBinding.determineResponseCode(Exchange, Object)
+     * If DefaultHttpBinding.determineResponseCode(Exchange, Object) is moved to a module without the servlet-api
+     * dependency we could eventually consume it from there.
+     */
+    static int determineResponseCode(Exchange camelExchange, Object body) {
+        boolean failed = camelExchange.isFailed();
+        int defaultCode = failed ? 500 : 200;
+
+        Message message = camelExchange.getMessage();
+        Integer currentCode = message.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
+        int codeToUse = currentCode == null ? defaultCode : currentCode;
+
+        if (codeToUse != 500) {
+            if ((body == null) || (body instanceof String && ((String) body).trim().isEmpty())) {
+                // no content
+                codeToUse = currentCode == null ? 204 : currentCode;
+            }
+        }
+
+        return codeToUse;
+    }
+
     static void writeResponse(RoutingContext ctx, Exchange camelExchange, HeaderFilterStrategy headerFilterStrategy) {
         final Object body = toHttpResponse(ctx.response(), camelExchange.getMessage(), headerFilterStrategy);
 
         final HttpServerResponse response = ctx.response();
         if (body == null) {
             LOG.tracef("No payload to send as reply for exchange: %s", camelExchange);
-            response.putHeader("Content-Type", "text/plain; charset=utf-8");
-            response.end("No response available");
-            return;
-        }
-
-        if (body instanceof String) {
+            response.end();
+        } else if (body instanceof String) {
             response.end((String) body);
         } else if (body instanceof InputStream) {
             final byte[] bytes = new byte[4096];
diff --git a/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java b/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java
index e023020..82cdef9 100644
--- a/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java
+++ b/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java
@@ -87,5 +87,16 @@ public class PlatformHttpRouteBuilder extends RouteBuilder {
         from("platform-http:/platform-http/produces?httpMethodRestrict=POST&produces=text/plain")
             .setBody(simple("Hello ${body}"));
 
+        /* 204 tests */
+        from("platform-http:/platform-http/null-body")
+            .setBody(constant(null));
+        from("platform-http:/platform-http/empty-string-body")
+            .setBody().constant("");
+        from("platform-http:/platform-http/some-string")
+            .setBody().constant("No Content");
+        from("platform-http:/platform-http/empty-string-200")
+            .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200))
+            .setBody().constant("");
+
     }
 }
diff --git a/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java b/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java
index e95747c..fade646 100644
--- a/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java
+++ b/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java
@@ -198,4 +198,40 @@ class PlatformHttpTest {
             .then()
             .statusCode(299);
     }
+
+
+    @Test
+    public void code204Null() throws Exception {
+        RestAssured.given()
+            .get("/platform-http/null-body")
+            .then()
+            .statusCode(204);
+    }
+
+    @Test
+    public void code204EmptyString() throws Exception {
+        RestAssured.given()
+            .get("/platform-http/empty-string-body")
+            .then()
+            .statusCode(204);
+    }
+
+    @Test
+    public void code204SomeString() throws Exception {
+        RestAssured.given()
+            .get("/platform-http/some-string")
+            .then()
+            .statusCode(200)
+            .body(equalTo("No Content"));
+    }
+
+    @Test
+    public void code200EmptyString() throws Exception {
+        RestAssured.given()
+            .get("/platform-http/empty-string-200")
+            .then()
+            .statusCode(200)
+            .body(equalTo(""));
+    }
+
 }