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 2022/08/14 15:03:34 UTC

[camel] branch camel-3.14.x updated (e0fa71d8052 -> 10542a61e3a)

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

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


    from e0fa71d8052 CAMEL-18379: camel-mail - Skip file attachments with empty file names. Thanks to Richard Vigniel for reporting.
     new 4d9216633e4 HttpSendDynamicAware not optimizing for http:hostname[:port][/resourceUri][?options]
     new 6d12b5e7fb1 HttpSendDynamicAware not optimizing for http:hostname\[:port\]\[/resourceUri\]\[\?options\]
     new 10542a61e3a Regen for commit 4766731eb75c27249bf790a61056d08156f865a5 (#8160)

The 3 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:
 .../camel/http/base/HttpSendDynamicAware.java      |  10 ++
 .../HttpSendDynamicAwareUriWithoutSlashTest.java   | 113 +++++++++++++++++++++
 2 files changed, 123 insertions(+)
 create mode 100644 components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java


[camel] 02/03: HttpSendDynamicAware not optimizing for http:hostname\[:port\]\[/resourceUri\]\[\?options\]

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

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

commit 6d12b5e7fb15b8b4c6b81c2dabca56020aa047c9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Aug 13 20:51:42 2022 +0200

    HttpSendDynamicAware not optimizing for http:hostname\[:port\]\[/resourceUri\]\[\?options\]
---
 .../camel/http/base/HttpSendDynamicAware.java      | 10 ++++++++
 .../HttpSendDynamicAwareUriWithoutSlashTest.java   | 29 ++++++++++++++--------
 2 files changed, 29 insertions(+), 10 deletions(-)

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 b9675cc0287..e476bc923c7 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
@@ -153,6 +153,16 @@ public class HttpSendDynamicAware extends SendDynamicAwareSupport {
             }
         }
 
+        // must include :// in scheme to be parsable via java.net.URI
+        int colon = u.indexOf(':');
+        if (colon != -1) {
+            String before = StringHelper.before(u, ":");
+            String after = StringHelper.after(u, ":");
+            if (!after.startsWith("//")) {
+                u = before + "://" + after;
+            }
+        }
+
         // favour using java.net.URI for parsing into host, context-path and authority
         try {
             URI parse = new URI(u);
diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java
index be8bd1a3906..bfb3e9c9e12 100644
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java
@@ -1,3 +1,19 @@
+/*
+ * 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.http;
 
 import java.util.Map;
@@ -82,18 +98,11 @@ public class HttpSendDynamicAwareUriWithoutSlashTest extends BaseHttpTest {
         out = fluentTemplate.to("direct:usersDrinkWithoutSlash").withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "moes").build()).send();
         assertEquals("a user", out.getMessage().getBody(String.class));
 
-        /*
-            Using http:hostname[:port][/resourceUri][?options] as documented https://camel.apache.org/components/3.18.x/http-component.html stops the optimization
-            
-            org.apache.camel.http.base.HttpSendDynamicAware Line 158 breaks the logic
-                
-                URI parse = new URI(u);   
-         */
+        // and there should only be one http endpoint as they are both on same host
         Map<String, Endpoint> endpointMap = context.getEndpointMap();
-        assertTrue(endpointMap.containsKey("http://localhost:" + localServer.getLocalPort() + "/users/joes"), "Not optimized");
-        assertTrue(endpointMap.containsKey("http://localhost:" + localServer.getLocalPort() + "/users/moes"), "Not optimized");
+        assertTrue(endpointMap.containsKey("http://localhost:" + localServer.getLocalPort()), "Should find static uri");
         assertTrue(endpointMap.containsKey("direct://usersDrink"), "Should find direct");
         assertTrue(endpointMap.containsKey("direct://usersDrinkWithoutSlash"), "Should find direct");
-        assertEquals(4, endpointMap.size());
+        assertEquals(3, endpointMap.size());
     }
 }


[camel] 03/03: Regen for commit 4766731eb75c27249bf790a61056d08156f865a5 (#8160)

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

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

commit 10542a61e3a5c46a7ab3ac9b82c89f58b57bf21f
Author: github-actions[bot] <41...@users.noreply.github.com>
AuthorDate: Sun Aug 14 09:10:58 2022 +0200

    Regen for commit 4766731eb75c27249bf790a61056d08156f865a5 (#8160)
    
    Signed-off-by: GitHub <no...@github.com>
    
    Signed-off-by: GitHub <no...@github.com>
    Co-authored-by: davsclaus <da...@users.noreply.github.com>
---
 .../HttpSendDynamicAwareUriWithoutSlashTest.java   | 29 +++++++++++++---------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java
index bfb3e9c9e12..250f276c51a 100644
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.http;
 
 import java.util.Map;
+
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.RoutesBuilder;
@@ -40,9 +41,9 @@ public class HttpSendDynamicAwareUriWithoutSlashTest extends BaseHttpTest {
     @Override
     public void setUp() throws Exception {
         localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor())
-            .setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory())
-            .setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext())
-            .registerHandler("/users/*", new BasicValidationHandler("GET", null, null, "a user")).create();
+                .setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory())
+                .setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext())
+                .registerHandler("/users/*", new BasicValidationHandler("GET", null, null, "a user")).create();
         localServer.start();
 
         super.setUp();
@@ -64,22 +65,24 @@ public class HttpSendDynamicAwareUriWithoutSlashTest extends BaseHttpTest {
             @Override
             public void configure() throws Exception {
                 from("direct:usersDrink")
-                    .toD("http://localhost:" + localServer.getLocalPort()
-                        + "/users/${exchangeProperty.user}");
+                        .toD("http://localhost:" + localServer.getLocalPort()
+                             + "/users/${exchangeProperty.user}");
 
                 from("direct:usersDrinkWithoutSlash")
-                    .toD("http:localhost:" + localServer.getLocalPort()
-                        + "/users/${exchangeProperty.user}");
+                        .toD("http:localhost:" + localServer.getLocalPort()
+                             + "/users/${exchangeProperty.user}");
             }
         };
     }
 
     @Test
     public void testDynamicAware() throws Exception {
-        Exchange out = fluentTemplate.to("direct:usersDrink").withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "joes").build()).send();
+        Exchange out = fluentTemplate.to("direct:usersDrink")
+                .withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "joes").build()).send();
         assertEquals("a user", out.getMessage().getBody(String.class));
 
-        out = fluentTemplate.to("direct:usersDrink").withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "moes").build()).send();
+        out = fluentTemplate.to("direct:usersDrink")
+                .withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "moes").build()).send();
         assertEquals("a user", out.getMessage().getBody(String.class));
 
         // and there should only be one http endpoint as they are both on same host
@@ -89,13 +92,15 @@ public class HttpSendDynamicAwareUriWithoutSlashTest extends BaseHttpTest {
         assertTrue(endpointMap.containsKey("direct://usersDrinkWithoutSlash"), "Should find direct");
         assertEquals(3, endpointMap.size());
     }
-    
+
     @Test
     public void testDynamicAwareWithoutSlash() throws Exception {
-        Exchange out = fluentTemplate.to("direct:usersDrinkWithoutSlash").withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "joes").build()).send();
+        Exchange out = fluentTemplate.to("direct:usersDrinkWithoutSlash")
+                .withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "joes").build()).send();
         assertEquals("a user", out.getMessage().getBody(String.class));
 
-        out = fluentTemplate.to("direct:usersDrinkWithoutSlash").withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "moes").build()).send();
+        out = fluentTemplate.to("direct:usersDrinkWithoutSlash")
+                .withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "moes").build()).send();
         assertEquals("a user", out.getMessage().getBody(String.class));
 
         // and there should only be one http endpoint as they are both on same host


[camel] 01/03: HttpSendDynamicAware not optimizing for http:hostname[:port][/resourceUri][?options]

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

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

commit 4d9216633e4aa052051753124fa0c3819c8d3601
Author: Jeroen Bellen <je...@aviobook.aero>
AuthorDate: Fri Aug 12 12:32:07 2022 +0200

    HttpSendDynamicAware not optimizing for http:hostname[:port][/resourceUri][?options]
---
 .../HttpSendDynamicAwareUriWithoutSlashTest.java   | 99 ++++++++++++++++++++++
 1 file changed, 99 insertions(+)

diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java
new file mode 100644
index 00000000000..be8bd1a3906
--- /dev/null
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareUriWithoutSlashTest.java
@@ -0,0 +1,99 @@
+package org.apache.camel.component.http;
+
+import java.util.Map;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.ExchangeBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.handler.BasicValidationHandler;
+import org.apache.http.impl.bootstrap.HttpServer;
+import org.apache.http.impl.bootstrap.ServerBootstrap;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class HttpSendDynamicAwareUriWithoutSlashTest extends BaseHttpTest {
+
+    private HttpServer localServer;
+
+    @BeforeEach
+    @Override
+    public void setUp() throws Exception {
+        localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor())
+            .setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory())
+            .setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext())
+            .registerHandler("/users/*", new BasicValidationHandler("GET", null, null, "a user")).create();
+        localServer.start();
+
+        super.setUp();
+    }
+
+    @AfterEach
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        if (localServer != null) {
+            localServer.stop();
+        }
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:usersDrink")
+                    .toD("http://localhost:" + localServer.getLocalPort()
+                        + "/users/${exchangeProperty.user}");
+
+                from("direct:usersDrinkWithoutSlash")
+                    .toD("http:localhost:" + localServer.getLocalPort()
+                        + "/users/${exchangeProperty.user}");
+            }
+        };
+    }
+
+    @Test
+    public void testDynamicAware() throws Exception {
+        Exchange out = fluentTemplate.to("direct:usersDrink").withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "joes").build()).send();
+        assertEquals("a user", out.getMessage().getBody(String.class));
+
+        out = fluentTemplate.to("direct:usersDrink").withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "moes").build()).send();
+        assertEquals("a user", out.getMessage().getBody(String.class));
+
+        // and there should only be one http endpoint as they are both on same host
+        Map<String, Endpoint> endpointMap = context.getEndpointMap();
+        assertTrue(endpointMap.containsKey("http://localhost:" + localServer.getLocalPort()), "Should find static uri");
+        assertTrue(endpointMap.containsKey("direct://usersDrink"), "Should find direct");
+        assertTrue(endpointMap.containsKey("direct://usersDrinkWithoutSlash"), "Should find direct");
+        assertEquals(3, endpointMap.size());
+    }
+    
+    @Test
+    public void testDynamicAwareWithoutSlash() throws Exception {
+        Exchange out = fluentTemplate.to("direct:usersDrinkWithoutSlash").withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "joes").build()).send();
+        assertEquals("a user", out.getMessage().getBody(String.class));
+
+        out = fluentTemplate.to("direct:usersDrinkWithoutSlash").withExchange(ExchangeBuilder.anExchange(context).withProperty("user", "moes").build()).send();
+        assertEquals("a user", out.getMessage().getBody(String.class));
+
+        /*
+            Using http:hostname[:port][/resourceUri][?options] as documented https://camel.apache.org/components/3.18.x/http-component.html stops the optimization
+            
+            org.apache.camel.http.base.HttpSendDynamicAware Line 158 breaks the logic
+                
+                URI parse = new URI(u);   
+         */
+        Map<String, Endpoint> endpointMap = context.getEndpointMap();
+        assertTrue(endpointMap.containsKey("http://localhost:" + localServer.getLocalPort() + "/users/joes"), "Not optimized");
+        assertTrue(endpointMap.containsKey("http://localhost:" + localServer.getLocalPort() + "/users/moes"), "Not optimized");
+        assertTrue(endpointMap.containsKey("direct://usersDrink"), "Should find direct");
+        assertTrue(endpointMap.containsKey("direct://usersDrinkWithoutSlash"), "Should find direct");
+        assertEquals(4, endpointMap.size());
+    }
+}