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:27 UTC

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

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