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 2023/03/07 11:42:52 UTC

[camel] branch camel-3.20.x updated: CAMEL-19113 Platform-http-vertx: consume with comma separated does not work (#9474)

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

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


The following commit(s) were added to refs/heads/camel-3.20.x by this push:
     new 6bde8293b8f CAMEL-19113 Platform-http-vertx: consume with comma separated does not work (#9474)
6bde8293b8f is described below

commit 6bde8293b8f341e4c4798a2830078f8648f81d4d
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Tue Mar 7 12:42:42 2023 +0100

    CAMEL-19113 Platform-http-vertx: consume with comma separated does not work (#9474)
---
 .../http/vertx/VertxPlatformHttpConsumer.java      |  10 +-
 .../VertxPlatformMultipleContentTypeTest.java      | 205 +++++++++++++++++++++
 2 files changed, 213 insertions(+), 2 deletions(-)

diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
index 387bb93a6aa..60876f552a1 100644
--- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
+++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
@@ -112,10 +112,16 @@ public class VertxPlatformHttpConsumer extends DefaultConsumer {
         }
 
         if (getEndpoint().getConsumes() != null) {
-            newRoute.consumes(getEndpoint().getConsumes());
+            //comma separated contentTypes has to be registered one by one
+            for (String c : getEndpoint().getConsumes().split(",")) {
+                newRoute.consumes(c);
+            }
         }
         if (getEndpoint().getProduces() != null) {
-            newRoute.produces(getEndpoint().getProduces());
+            //comma separated contentTypes has to be registered one by one
+            for (String p : getEndpoint().getProduces().split(",")) {
+                newRoute.produces(p);
+            }
         }
 
         newRoute.handler(router.bodyHandler());
diff --git a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformMultipleContentTypeTest.java b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformMultipleContentTypeTest.java
new file mode 100644
index 00000000000..2b7055897c6
--- /dev/null
+++ b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformMultipleContentTypeTest.java
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.platform.http.vertx;
+
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.apache.camel.support.jsse.KeyManagersParameters;
+import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.support.jsse.SSLContextServerParameters;
+import org.apache.camel.support.jsse.TrustManagersParameters;
+import org.apache.camel.test.AvailablePortFinder;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.Matchers.is;
+
+public class VertxPlatformMultipleContentTypeTest {
+    public static SSLContextParameters serverSSLParameters;
+    public static SSLContextParameters clientSSLParameters;
+
+    @BeforeAll
+    public static void setUp() {
+        serverSSLParameters = new SSLContextParameters();
+        clientSSLParameters = new SSLContextParameters();
+
+        KeyStoreParameters keystoreParameters = new KeyStoreParameters();
+        keystoreParameters.setResource("jsse/service.jks");
+        keystoreParameters.setPassword("security");
+
+        KeyManagersParameters serviceSSLKeyManagers = new KeyManagersParameters();
+        serviceSSLKeyManagers.setKeyPassword("security");
+        serviceSSLKeyManagers.setKeyStore(keystoreParameters);
+
+        serverSSLParameters.setKeyManagers(serviceSSLKeyManagers);
+
+        KeyStoreParameters truststoreParameters = new KeyStoreParameters();
+        truststoreParameters.setResource("jsse/truststore.jks");
+        truststoreParameters.setPassword("storepass");
+
+        TrustManagersParameters clientAuthServiceSSLTrustManagers = new TrustManagersParameters();
+        clientAuthServiceSSLTrustManagers.setKeyStore(truststoreParameters);
+        serverSSLParameters.setTrustManagers(clientAuthServiceSSLTrustManagers);
+        SSLContextServerParameters clientAuthSSLContextServerParameters = new SSLContextServerParameters();
+        clientAuthSSLContextServerParameters.setClientAuthentication("REQUIRE");
+        serverSSLParameters.setServerParameters(clientAuthSSLContextServerParameters);
+
+        TrustManagersParameters clientSSLTrustManagers = new TrustManagersParameters();
+        clientSSLTrustManagers.setKeyStore(truststoreParameters);
+        clientSSLParameters.setTrustManagers(clientSSLTrustManagers);
+
+        KeyManagersParameters clientAuthClientSSLKeyManagers = new KeyManagersParameters();
+        clientAuthClientSSLKeyManagers.setKeyPassword("security");
+        clientAuthClientSSLKeyManagers.setKeyStore(keystoreParameters);
+        clientSSLParameters.setKeyManagers(clientAuthClientSSLKeyManagers);
+    }
+
+    @Test
+    public void testMultipleContentTypes() throws Exception {
+        final CamelContext context = createCamelContext();
+
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    restConfiguration().component("platform-http")
+                            .contextPath("/rest");
+
+                    rest().get("/test")
+                            .consumes("application/json,application/xml")
+                            .produces("application/json,application/xml")
+                            .bindingMode(RestBindingMode.auto)
+                            .to("direct:rest");
+
+                    from("direct:rest")
+                            .setBody(simple("Hello"));
+                }
+            });
+
+            context.start();
+
+            RestAssured.given()
+                    .header("Content-Type", "application/json,application/xml")
+                    .get("rest/test")
+                    .then()
+                    .statusCode(415);
+
+        } finally {
+            context.stop();
+        }
+    }
+
+    @Test
+    public void testOneContentType() throws Exception {
+        final CamelContext context = createCamelContext();
+
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    restConfiguration().component("platform-http")
+                            .contextPath("/rest");
+
+                    rest().get("/test")
+                            .consumes("application/json,application/xml")
+                            .produces("application/json,application/xml")
+                            .bindingMode(RestBindingMode.auto)
+                            .to("direct:rest");
+
+                    from("direct:rest")
+                            .setBody(simple("Hello"));
+                }
+            });
+
+            context.start();
+
+            RestAssured.given()
+                    .header("Content-Type", "application/json")
+                    .get("rest/test")
+                    .then()
+                    .statusCode(200)
+                    .body(is("\"Hello\""));
+        } finally {
+            context.stop();
+        }
+    }
+
+    @Test
+    public void testAcceptsOneContentType() throws Exception {
+        final CamelContext context = createCamelContext();
+
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    restConfiguration().component("platform-http")
+                            .contextPath("/rest");
+
+                    rest().get("/test")
+                            .consumes("application/xml,application/json")
+                            .produces("application/xml,application/json")
+                            .bindingMode(RestBindingMode.auto)
+                            .to("direct:rest");
+
+                    from("direct:rest")
+                            .setBody(simple("Hello"));
+                }
+            });
+
+            context.start();
+
+            RestAssured.given()
+                    .header("Content-type", ContentType.XML)
+                    .header("Accept", ContentType.XML)
+                    .get("rest/test")
+                    .then()
+                    .statusCode(200)
+                    .body(is("Hello"));
+        } finally {
+            context.stop();
+        }
+    }
+
+    static CamelContext createCamelContext() throws Exception {
+        return createCamelContext(null);
+    }
+
+    private static CamelContext createCamelContext(ServerConfigurationCustomizer customizer) throws Exception {
+        int port = AvailablePortFinder.getNextAvailable();
+        VertxPlatformHttpServerConfiguration conf = new VertxPlatformHttpServerConfiguration();
+        conf.setBindPort(port);
+
+        RestAssured.port = port;
+
+        if (customizer != null) {
+            customizer.customize(conf);
+        }
+
+        CamelContext context = new DefaultCamelContext();
+        context.addService(new VertxPlatformHttpServer(conf));
+        return context;
+    }
+
+    interface ServerConfigurationCustomizer {
+        void customize(VertxPlatformHttpServerConfiguration configuration);
+    }
+}