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/13 18:56:25 UTC

[camel] branch camel-3.18.x updated (c91ff359a14 -> 59ef5950a17)

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

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


    from c91ff359a14 CAMEL-18388: camel-jbang - add directory option to init to save to this folder
     new 5dcf4a1d385 HttpSendDynamicAware not optimizing for http:hostname[:port][/resourceUri][?options]
     new 59ef5950a17 HttpSendDynamicAware not optimizing for http:hostname\[:port\]\[/resourceUri\]\[\?options\]

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


[camel] 01/02: 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.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5dcf4a1d3854d6065463ebe0eb559555ed0d6c26
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());
+    }
+}


[camel] 02/02: 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.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 59ef5950a1720c5b45587da689205605c7eb385d
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());
     }
 }