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 <claus.ib...@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()); } }