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 90a9143a7c6b6aee1607b9453bdf772391155b82
Author: Peter Palaga <[email protected]>
AuthorDate: Fri Oct 25 12:59:33 2019 +0200

    Fix #326 platform-http should return 415 for an unaccepted content type
---
 .../platform/http/PlatformHttpComponent.java       |  2 ++
 .../platform/http/PlatformHttpEndpoint.java        | 24 ++++++++++++++++++++++
 .../http/runtime/QuarkusPlatformHttpConsumer.java  |  8 ++++++--
 .../platform/http/it/PlatformHttpRouteBuilder.java |  3 +++
 .../component/http/server/it/PlatformHttpTest.java | 24 +++++++++++++++++++---
 5 files changed, 56 insertions(+), 5 deletions(-)

diff --git 
a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
 
b/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
index c9764ba..22565b7 100644
--- 
a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
+++ 
b/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
@@ -143,6 +143,8 @@ public class PlatformHttpComponent extends DefaultComponent 
implements RestConsu
 
         PlatformHttpEndpoint endpoint = camelContext.getEndpoint(url, 
PlatformHttpEndpoint.class);
         setProperties(camelContext, endpoint, parameters);
+        endpoint.setConsumes(consumes);
+        endpoint.setProduces(produces);
 
         // configure consumer properties
         Consumer consumer = endpoint.createConsumer(processor);
diff --git 
a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java
 
b/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java
index f7d7c3a..5f8056d 100644
--- 
a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java
+++ 
b/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java
@@ -44,6 +44,14 @@ public class PlatformHttpEndpoint extends DefaultEndpoint 
implements AsyncEndpoi
             + " If no methods are specified, all methods will be served.")
     private String httpMethodRestrict;
 
+    @UriParam(label = "consumer", description = "The content type this 
endpoint accepts as an input, such as"
+            + " application/xml or application/json. <code>null</code> or 
<code>&#42;/&#42;</code> mean no restriction.")
+    private String consumes;
+
+    @UriParam(label = "consumer", description = "The content type this 
endpoint produces, such as"
+        + " application/xml or application/json.")
+    private String produces;
+
     @UriParam(label = "consumer,advanced", description = "A comma or 
whitespace separated list of file extensions."
             + " Uploads having these extensions will be stored locally."
             + " Null value or asterisk (*) will allow all files.")
@@ -108,6 +116,22 @@ public class PlatformHttpEndpoint extends DefaultEndpoint 
implements AsyncEndpoi
         this.fileNameExtWhitelist = fileNameExtWhitelist;
     }
 
+    public String getConsumes() {
+        return consumes;
+    }
+
+    public void setConsumes(String consumes) {
+        this.consumes = consumes;
+    }
+
+    public String getProduces() {
+        return produces;
+    }
+
+    public void setProduces(String produces) {
+        this.produces = produces;
+    }
+
     @Override
     protected void doStart() throws Exception {
         super.doStart();
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 5f30a39..fd3beb8 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
@@ -92,13 +92,17 @@ public class QuarkusPlatformHttpConsumer extends 
DefaultConsumer {
     protected void doStart() throws Exception {
         super.doStart();
 
-        final String path = getEndpoint().getPath();
+        final PlatformHttpEndpoint endpoint = getEndpoint();
+        final String path = endpoint.getPath();
         final Route newRoute = router.route(path);
 
-        final Set<Method> methods = 
Method.parseList(getEndpoint().getHttpMethodRestrict());
+        final Set<Method> methods = 
Method.parseList(endpoint.getHttpMethodRestrict());
         if (!methods.equals(Method.getAll())) {
             methods.stream().forEach(m -> 
newRoute.method(HttpMethod.valueOf(m.name())));
         }
+        if (endpoint.getConsumes() != null) {
+            newRoute.consumes(endpoint.getConsumes());
+        }
 
         handlers.forEach(newRoute::handler);
 
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 5ddf310..d6b6bd0 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
@@ -81,5 +81,8 @@ public class PlatformHttpRouteBuilder extends RouteBuilder {
             .to("log:response-code")
             .setHeader(Exchange.HTTP_RESPONSE_CODE).constant(299);
 
+        
from("platform-http:/platform-http/consumes?httpMethodRestrict=POST&consumes=text/plain")
+            .setBody(simple("Hello ${body}"));
+
     }
 }
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 d1eba8f..ced99c7 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
@@ -62,13 +62,31 @@ class PlatformHttpTest {
             .then().body(equalTo("POST: /rest-post"));
     }
 
-    @Disabled("See https://github.com/apache/camel-quarkus/issues/326";)
     @Test
-    public void restConsumes() throws Throwable {
+    public void consumes() throws Throwable {
         RestAssured.given()
             .contentType("application/json")
             .post("/platform-http/rest-post")
-            .then().statusCode(415);
+            .then()
+            .statusCode(415);
+
+        RestAssured.given()
+            .contentType("text/plain")
+            .post("/platform-http/rest-post")
+            .then()
+            .statusCode(200);
+
+        RestAssured.given()
+            .contentType("application/json")
+            .post("/platform-http/consumes")
+            .then()
+            .statusCode(415);
+
+        RestAssured.given()
+            .contentType("text/plain")
+            .post("/platform-http/consumes")
+            .then()
+            .statusCode(200);
     }
 
     @Test

Reply via email to