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 2020/09/28 08:48:26 UTC

[camel] branch master updated (245ec3e -> 00bba37)

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 245ec3e  Camel-AWS2-Eventbridge: Added test for listRuleNamesByTarget Localstack
     new cd31d93  CAMEL-14499: Optimize to avoid using camel-core-catalog for SendDynamicAware for http components
     new 00bba37  CAMEL-15586: camel-http-vertx - Add support for SendDynamicAware

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:
 components/camel-http-base/pom.xml                 |  6 -----
 .../camel/http/base/HttpSendDynamicAware.java      | 26 ++++++++++++++++------
 .../netty/http/NettyHttpSendDynamicAware.java      | 16 -------------
 .../netty/http/NettyHttpSendDynamicAwareTest.java  |  2 +-
 .../org/apache/camel/send-dynamic/vertx-http}      |  2 +-
 .../vertx/http/VertxHttpSendDynamicAware.java}     |  7 +++---
 .../vertx/http/VertxHttpSendDynamicAwareTest.java} | 16 +++++++------
 .../component/vertx/http/VertxHttpTestSupport.java |  4 ++++
 8 files changed, 38 insertions(+), 41 deletions(-)
 copy components/{camel-netty-http/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/netty-http => camel-vertx-http/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/vertx-http} (50%)
 copy components/{camel-undertow/src/main/java/org/apache/camel/component/undertow/HttpSendDynamicAware.java => camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAware.java} (81%)
 copy components/{camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSendDynamicAwareTest.java => camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAwareTest.java} (74%)


[camel] 01/02: CAMEL-14499: Optimize to avoid using camel-core-catalog for SendDynamicAware for http components

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 cd31d93f646d79ca411b287b80dde206288d9775
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Sep 28 10:37:52 2020 +0200

    CAMEL-14499: Optimize to avoid using camel-core-catalog for SendDynamicAware for http components
---
 components/camel-http-base/pom.xml                 |  6 -----
 .../camel/http/base/HttpSendDynamicAware.java      | 26 ++++++++++++++++------
 .../netty/http/NettyHttpSendDynamicAware.java      | 16 -------------
 .../netty/http/NettyHttpSendDynamicAwareTest.java  |  2 +-
 4 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/components/camel-http-base/pom.xml b/components/camel-http-base/pom.xml
index 566551b..3779222 100644
--- a/components/camel-http-base/pom.xml
+++ b/components/camel-http-base/pom.xml
@@ -43,11 +43,5 @@
             <artifactId>camel-support</artifactId>
         </dependency>
 
-        <!-- needed for dynamic to -->
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-core-catalog</artifactId>
-        </dependency>
-
     </dependencies>
 </project>
diff --git a/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java b/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java
index 5692ec5..8791f63 100644
--- a/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java
+++ b/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java
@@ -40,7 +40,8 @@ public class HttpSendDynamicAware extends SendDynamicAwareSupport {
 
     @Override
     public boolean isOnlyDynamicQueryParameters() {
-        return false;
+        // we compute our own host:port/path so its okay so say true here
+        return true;
     }
 
     @Override
@@ -68,17 +69,24 @@ public class HttpSendDynamicAware extends SendDynamicAwareSupport {
                 params.remove(k);
             }
             if (path != null) {
+                params.remove("httpUri");
+                params.remove("httpURI");
+                params.remove("path");
                 // httpUri/httpURI contains the host and path, so replace it with just the host as the context-path is dynamic
-                if (params.containsKey("httpUri")) {
-                    params.put("httpUri", host);
-                } else if (params.containsKey("httpURI")) {
-                    params.put("httpURI", host);
-                } else if ("netty-http".equals(getScheme())) {
+                params.remove("httpUri");
+                params.remove("httpURI");
+                if ("netty-http".equals(getScheme())) {
                     // the netty-http stores host,port etc in other fields than httpURI so we can just remove the path parameter
                     params.remove("path");
                 }
             }
-            return asEndpointUri(exchange, entry.getUri(), params);
+
+            // build static url with the known parameters
+            String url = getScheme() + ":" + host;
+            if (!params.isEmpty()) {
+                url += "?" + URISupport.createQueryString(params, false);
+            }
+            return url;
         } else {
             // no need for optimisation
             return null;
@@ -143,6 +151,10 @@ public class HttpSendDynamicAware extends SendDynamicAwareSupport {
                 if (port > 0 && port != 80 && port != 443) {
                     host += ":" + port;
                 }
+                // remove double slash for path
+                while (path.startsWith("//")) {
+                    path = path.substring(1);
+                }
                 if (!httpComponent) {
                     // include scheme for components that are not camel-http
                     String scheme = parse.getScheme();
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpSendDynamicAware.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpSendDynamicAware.java
index 1a9ab7a..74ea26a 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpSendDynamicAware.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpSendDynamicAware.java
@@ -22,20 +22,4 @@ import org.apache.camel.spi.annotations.SendDynamic;
 @SendDynamic("netty-http")
 public class NettyHttpSendDynamicAware extends HttpSendDynamicAware {
 
-    @Override
-    public String[] parseUri(DynamicAwareEntry entry) {
-        // camel-netty parses the uri a bit differently than camel-http-common base class
-
-        String scheme = (String) entry.getProperties().get("protocol");
-        String host = (String) entry.getProperties().get("host");
-        String port = (String) entry.getProperties().get("port");
-        String path = (String) entry.getProperties().get("path");
-
-        String baseUrl = scheme + "://" + host;
-        if (port != null) {
-            baseUrl += ":" + port;
-        }
-        return new String[] { baseUrl, path };
-    }
-
 }
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSendDynamicAwareTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSendDynamicAwareTest.java
index 5fb8b4b..e319db4 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSendDynamicAwareTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSendDynamicAwareTest.java
@@ -35,7 +35,7 @@ public class NettyHttpSendDynamicAwareTest extends BaseNettyTest {
 
         // and there should only be one http endpoint as they are both on same host
         boolean found = context.getEndpointMap()
-                .containsKey("netty-http://http:localhost:" + getPort() + "?throwExceptionOnFailure=false");
+                .containsKey("netty-http://http://localhost:" + getPort() + "?throwExceptionOnFailure=false");
         assertTrue(found, "Should find static uri");
 
         // we only have 2xdirect and 2xnetty-http


[camel] 02/02: CAMEL-15586: camel-http-vertx - Add support for SendDynamicAware

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 00bba37a2dec8d1a618f3d1a87f3c6057bff7ce4
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Sep 28 10:47:40 2020 +0200

    CAMEL-15586: camel-http-vertx - Add support for SendDynamicAware
---
 .../org/apache/camel/send-dynamic/vertx-http       |  2 +
 .../vertx/http/VertxHttpSendDynamicAware.java}     | 20 ++-----
 .../vertx/http/VertxHttpSendDynamicAwareTest.java  | 64 ++++++++++++++++++++++
 .../component/vertx/http/VertxHttpTestSupport.java |  4 ++
 4 files changed, 74 insertions(+), 16 deletions(-)

diff --git a/components/camel-vertx-http/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/vertx-http b/components/camel-vertx-http/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/vertx-http
new file mode 100644
index 0000000..3d4bc48
--- /dev/null
+++ b/components/camel-vertx-http/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/vertx-http
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.vertx.http.VertxHttpSendDynamicAware
diff --git a/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAware.java
similarity index 59%
copy from components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java
copy to components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAware.java
index bbb3c6e..f47f46e 100644
--- a/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java
+++ b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAware.java
@@ -16,22 +16,10 @@
  */
 package org.apache.camel.component.vertx.http;
 
-import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.junit5.CamelTestSupport;
+import org.apache.camel.http.base.HttpSendDynamicAware;
+import org.apache.camel.spi.annotations.SendDynamic;
 
-public class VertxHttpTestSupport extends CamelTestSupport {
+@SendDynamic("vertx-http")
+public class VertxHttpSendDynamicAware extends HttpSendDynamicAware {
 
-    protected final int port = AvailablePortFinder.getNextAvailable();
-
-    protected String getTestServerUrl() {
-        return String.format("http://localhost:%d", port);
-    }
-
-    protected String getTestServerUri() {
-        return String.format("undertow:%s", getTestServerUrl());
-    }
-
-    protected String getProducerUri() {
-        return String.format("vertx-http:http://localhost:%d", port);
-    }
 }
diff --git a/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAwareTest.java b/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAwareTest.java
new file mode 100644
index 0000000..a040d98
--- /dev/null
+++ b/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAwareTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.vertx.http;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class VertxHttpSendDynamicAwareTest extends VertxHttpTestSupport {
+
+    @Test
+    public void testDynamicAware() throws Exception {
+        String out = fluentTemplate.to("direct:moes").withHeader("drink", "beer").request(String.class);
+        assertEquals("Drinking beer", out);
+
+        out = fluentTemplate.to("direct:joes").withHeader("drink", "wine").request(String.class);
+        assertEquals("Drinking wine", out);
+
+        // and there should only be one http endpoint as they are both on same host
+        boolean found = context.getEndpointMap()
+                .containsKey("vertx-http://http://localhost:" + getPort() + "?throwExceptionOnFailure=false");
+        assertTrue(found, "Should find static uri");
+
+        // we only have 2xdirect and 2xVERTX-http
+        assertEquals(4, context.getEndpointMap().size());
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:moes")
+                        .toD("vertx-http:http://localhost:" + getPort()
+                             + "/moes?throwExceptionOnFailure=false&drink=${header.drink}");
+
+                from("direct:joes")
+                        .toD("vertx-http:http://localhost:" + getPort()
+                             + "/joes?throwExceptionOnFailure=false&drink=${header.drink}");
+
+                from("undertow:http://localhost:" + getPort() + "/?matchOnUriPrefix=true")
+                        .transform().simple("Drinking ${header.drink[0]}");
+            }
+        };
+    }
+
+}
diff --git a/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java b/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java
index bbb3c6e..9eee115 100644
--- a/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java
+++ b/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java
@@ -34,4 +34,8 @@ public class VertxHttpTestSupport extends CamelTestSupport {
     protected String getProducerUri() {
         return String.format("vertx-http:http://localhost:%d", port);
     }
+
+    protected int getPort() {
+        return port;
+    }
 }