This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 8bd7c2ed53b7 CAMEL-26487: camel-netty-http - include the endpoint
options in the endpoint URI (#28863)
8bd7c2ed53b7 is described below
commit 8bd7c2ed53b7c7b41c519d008d1fbb67a28fed6e
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Nov 3 12:53:33 2026 +0100
CAMEL-26487: camel-netty-http - include the endpoint options in the
endpoint URI (#28863)
Signed-off-by: Claus Ibsen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../netty/http/HttpClientInitializerFactory.java | 2 +-
.../component/netty/http/NettyHttpComponent.java | 5 +-
.../component/netty/http/NettyHttpEndpoint.java | 17 ++++-
.../component/netty/http/NettyHttpHelper.java | 2 +-
.../netty/http/ManagedNettyEndpointTest.java | 5 +-
.../NettyHttpEndpointDifferentOptionsTest.java | 85 ++++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 23 ++++++
7 files changed, 133 insertions(+), 6 deletions(-)
diff --git
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
index e3a8648a7048..ea24bfe9ca0b 100644
---
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
+++
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
@@ -171,7 +171,7 @@ public class HttpClientInitializerFactory extends
ClientInitializerFactory {
if (producer.getConfiguration().getSslHandler() != null) {
return producer.getConfiguration().getSslHandler();
} else if (sslContext != null) {
- URI uri = new URI(producer.getEndpoint().getEndpointUri());
+ URI uri = new URI(producer.getEndpoint().getAddressUri());
SSLEngine engine = sslContext.createSSLEngine(uri.getHost(),
uri.getPort());
engine.setUseClientMode(true);
SSLParameters sslParameters = engine.getSSLParameters();
diff --git
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
index a0fe50fc9634..2daec35a64e8 100644
---
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
+++
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
@@ -179,7 +179,10 @@ public class NettyHttpComponent extends NettyComponent
String addressUri = URISupport.createRemainingURI(u,
parameters).toString();
- NettyHttpEndpoint answer = new NettyHttpEndpoint(addressUri, this,
config);
+ // the endpoint uri is the full uri with the endpoint options, so
endpoints that differ only in their options
+ // are not equal, and the address uri is the http address to call
+ NettyHttpEndpoint answer = new NettyHttpEndpoint(uri, this, config);
+ answer.setAddressUri(addressUri);
answer.getConfiguration().setMuteException(muteException);
setProperties(answer, parameters);
diff --git
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
index 1e9eb8548fc8..c160c004622c 100644
---
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
+++
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
@@ -91,6 +91,8 @@ public class NettyHttpEndpoint extends NettyEndpoint
implements HeaderFilterStra
static final String PROXY_NOT_SUPPORTED_MESSAGE = "Netty Http Producer
does not support proxy mode";
private OAuthHttpSecuritySupport oauthHttpSecurity;
+ // the http address: scheme, host, port, path and the query parameters
that are not endpoint options
+ private String addressUri;
@UriParam
private NettyHttpConfiguration configuration;
@@ -349,8 +351,21 @@ public class NettyHttpEndpoint extends NettyEndpoint
implements HeaderFilterStra
oauthHttpSecurity = OAuthHttpSecuritySupport.create(getCamelContext(),
oauthProfile);
}
+ /**
+ * The HTTP address of this endpoint, which the producer sends its
requests to: the scheme, host, port and path, and
+ * the query parameters that are not endpoint options.
+ */
+ public String getAddressUri() {
+ return addressUri != null ? addressUri : getEndpointUri();
+ }
+
+ void setAddressUri(String addressUri) {
+ this.addressUri = addressUri;
+ }
+
private boolean isProxyProtocol() {
- URI baseUri = URI.create(getEndpointBaseUri());
+ String address = getAddressUri();
+ URI baseUri = URI.create(StringHelper.before(address, "?", address));
String protocol = baseUri.getScheme();
return protocol != null && protocol.equalsIgnoreCase("proxy");
}
diff --git
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
index f8e4e14dfe32..75154da88bd2 100644
---
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
+++
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
@@ -183,7 +183,7 @@ public final class NettyHttpHelper {
// rest producer may provide an override url to be used which we
should discard if using (hence the remove)
String uri = (String)
exchange.getIn().removeHeader(Exchange.REST_HTTP_URI);
if (uri == null) {
- uri = endpoint.getEndpointUri();
+ uri = endpoint.getAddressUri();
}
// NOTE: property placeholders are resolved at build time on the
endpoint uri written in the route,
diff --git
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/ManagedNettyEndpointTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/ManagedNettyEndpointTest.java
index 6912655ef3e9..e402eb21743f 100644
---
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/ManagedNettyEndpointTest.java
+++
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/ManagedNettyEndpointTest.java
@@ -30,6 +30,7 @@ import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
@DisabledOnOs(OS.AIX)
public class ManagedNettyEndpointTest extends BaseNettyTestSupport {
@@ -64,8 +65,8 @@ public class ManagedNettyEndpointTest extends
BaseNettyTestSupport {
ObjectName on = ObjectName
.getInstance("org.apache.camel:context=" +
context.getManagementName()
- + ",type=endpoints,name=\"http://0.0.0.0:" +
getPort() + "/foo\"");
- mbeanServer.isRegistered(on);
+ +
",type=endpoints,name=\"netty-http://http://0.0.0.0:" + getPort() + "/foo\"");
+ assertTrue(mbeanServer.isRegistered(on));
// should only be 2 endpoints in JMX
Set<ObjectName> set = getMBeanServer()
diff --git
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpEndpointDifferentOptionsTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpEndpointDifferentOptionsTest.java
new file mode 100644
index 000000000000..5b08a1c993bc
--- /dev/null
+++
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpEndpointDifferentOptionsTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.netty.http;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.camel.test.junit6.TestSupport.assertIsInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class NettyHttpEndpointDifferentOptionsTest extends
BaseNettyTestSupport {
+
+ @Test
+ public void testEndpointsWithDifferentOptionsAreNotEqual() {
+ Endpoint plain =
context.getEndpoint("netty-http:http://localhost:{{port}}/foo?bar=123");
+ Endpoint option =
context.getEndpoint("netty-http:http://localhost:{{port}}/foo?bar=123&throwExceptionOnFailure=false");
+
+ assertNotEquals(plain, option);
+ assertNotEquals(plain.getEndpointUri(), option.getEndpointUri());
+
+ // both send to the same address, which keeps the query parameters
that are not endpoint options
+ String url = "http://localhost:" + getPort() + "/foo?bar=123";
+ assertEquals(url, NettyHttpHelper.createURL(new
DefaultExchange(context), (NettyHttpEndpoint) plain));
+ assertEquals(url, NettyHttpHelper.createURL(new
DefaultExchange(context), (NettyHttpEndpoint) option));
+ }
+
+ @Test
+ public void testProducerTemplateUsesTheOptionsOfEachEndpoint() {
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () ->
template.requestBody("netty-http:http://localhost:{{port}}/fail", "Hello
World", String.class));
+ NettyHttpOperationFailedException cause =
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+ assertEquals(500, cause.getStatusCode());
+
+ // the same address with another option is another endpoint, with a
producer of its own
+ String out =
template.requestBody("netty-http:http://localhost:{{port}}/fail?throwExceptionOnFailure=false",
+ "Hello World", String.class);
+ assertEquals("Failed", out);
+ }
+
+ @Test
+ public void testToDUsesTheOptionsOfEachEndpoint() {
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> template.requestBodyAndHeader("direct:start", "Hello
World", "throwOnFailure", "true", String.class));
+ NettyHttpOperationFailedException cause =
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+ assertEquals(500, cause.getStatusCode());
+
+ String out = template.requestBodyAndHeader("direct:start", "Hello
World", "throwOnFailure", "false", String.class);
+ assertEquals("Failed", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("netty-http:http://0.0.0.0:{{port}}/fail")
+ .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500))
+ .transform().constant("Failed");
+
+ from("direct:start")
+
.toD("netty-http:http://localhost:{{port}}/fail?throwExceptionOnFailure=${header.throwOnFailure}");
+ }
+ };
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index e303f1dbb4d2..5a71f0252288 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -3762,6 +3762,29 @@ anything): a reader that needs mark support has to wrap
the stream, for example
When `securityConfiguration` is set on the `NettyHttpComponent`, each endpoint
now receives an independent copy of the configuration. Modifying
`securityConfiguration.*` options on an endpoint URI no longer alters the
component-level configuration or other endpoints.
+=== camel-netty-http - the endpoint URI includes the endpoint options
+
+The endpoint URI of a `netty-http` endpoint (`Endpoint.getEndpointUri()`) is
now its full URI, with the component
+scheme and the endpoint options, as for `netty` and most other components. For
example, the endpoint
+`netty-http:http://localhost:8080/foo?throwExceptionOnFailure=false` now has
the endpoint URI
+`netty-http://http://localhost:8080/foo?throwExceptionOnFailure=false`.
Before, it was `http://localhost:8080/foo`.
+
+Endpoints whose URIs differ only in their options are therefore no longer
equal, and each of them gets its own
+producer when a `ProducerTemplate`, `toD` or another EIP with a dynamic URI
sends to them. Before, these endpoints used
+the producer of the endpoint that was used first, with the options of that
endpoint.
+
+The request is still sent to the same HTTP address, which
`NettyHttpEndpoint.getAddressUri()` returns. The new endpoint
+URI shows in:
+
+* the name of an auto-mocked endpoint, for example
`mock:netty-http:http://localhost:8080/foo` instead of
+ `mock:http:localhost:8080/foo`. A `mockEndpoints` pattern such as `http*` no
longer matches a `netty-http` endpoint,
+ and `netty-http*` does.
+* the name of the endpoint in JMX, for example
`netty-http://http://0.0.0.0:8080/foo`.
+* the `CamelToEndpoint` exchange property.
+* tracing: a `netty-http` endpoint now gets the span decorator of `netty-http`
instead of the one of `http` or
+ `https`, and the include and exclude patterns are matched against the new
endpoint URI.
+* the `endpointName` tag of the Micrometer exchange event metrics.
+
=== camel-netty - hostnameVerification verifies the host instead of failing
`hostnameVerification=true` on a `netty` producer, or on a consumer with
`clientMode=true`, now checks that the