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 2023/08/22 10:55:17 UTC
[camel] branch camel-3.x updated: CAMEL-19760: netty-http:prevent the usage of proxy protocol in producer endpoint (#11165)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.x by this push:
new c0e0beb42ed CAMEL-19760: netty-http:prevent the usage of proxy protocol in producer endpoint (#11165)
c0e0beb42ed is described below
commit c0e0beb42ed446854b2942ec357d8e11a44268f6
Author: Luigi De Masi <55...@users.noreply.github.com>
AuthorDate: Tue Aug 22 12:54:30 2023 +0200
CAMEL-19760: netty-http:prevent the usage of proxy protocol in producer endpoint (#11165)
---
.../component/netty/http/NettyHttpEndpoint.java | 12 +++++
.../netty/http/NettyHttpProducerProxyModeTest.java | 59 ++++++++++++++++++++++
.../org/apache/camel/impl/engine/RouteService.java | 4 +-
3 files changed, 73 insertions(+), 2 deletions(-)
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 65b41a1cc45..172143816c4 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
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.netty.http;
+import java.net.URI;
import java.util.Map;
import org.apache.camel.AsyncEndpoint;
@@ -49,6 +50,7 @@ import org.slf4j.LoggerFactory;
public class NettyHttpEndpoint extends NettyEndpoint implements AsyncEndpoint, HeaderFilterStrategyAware {
private static final Logger LOG = LoggerFactory.getLogger(NettyHttpEndpoint.class);
+ static final String PROXY_NOT_SUPPORTED_MESSAGE = "Netty Http Producer does not support proxy mode";
@UriParam
private NettyHttpConfiguration configuration;
@@ -103,6 +105,10 @@ public class NettyHttpEndpoint extends NettyEndpoint implements AsyncEndpoint, H
@Override
public Producer createProducer() throws Exception {
+ if (isProxyProtocol()) {
+ doFail(new IllegalArgumentException(PROXY_NOT_SUPPORTED_MESSAGE));
+ }
+
Producer answer = new NettyHttpProducer(this, getConfiguration());
if (getConfiguration().isSynchronous()) {
return new SynchronousDelegateProducer(answer);
@@ -246,4 +252,10 @@ public class NettyHttpEndpoint extends NettyEndpoint implements AsyncEndpoint, H
}
}
}
+
+ private boolean isProxyProtocol() {
+ URI baseUri = URI.create(getEndpointBaseUri());
+ String protocol = baseUri.getScheme();
+ return protocol != null && protocol.equalsIgnoreCase("proxy");
+ }
}
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerProxyModeTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerProxyModeTest.java
new file mode 100644
index 00000000000..6d56debcee3
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerProxyModeTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.FailedToStartRouteException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.camel.component.netty.http.NettyHttpEndpoint.PROXY_NOT_SUPPORTED_MESSAGE;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class NettyHttpProducerProxyModeTest extends CamelTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ private static final int port = AvailablePortFinder.getNextAvailable();
+
+ @Test
+ public void testProxyNotSupported() throws Exception {
+
+ context.addRoutes(new RouteBuilder() {
+
+ @Override
+ public void configure() {
+ from("direct:start")
+ .routeId("proxy-producer")
+ .to("netty-http:proxy://localhost:" + port + "/foo");
+ }
+ });
+
+ FailedToStartRouteException thrown = assertThrows(FailedToStartRouteException.class, () -> {
+ context.start();
+ }, PROXY_NOT_SUPPORTED_MESSAGE);
+
+ assertNotNull(thrown.getMessage());
+ assertTrue(thrown.getMessage().contains(PROXY_NOT_SUPPORTED_MESSAGE));
+ }
+}
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java
index ec116756b53..228b90e6aab 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java
@@ -120,7 +120,7 @@ public class RouteService extends ChildServiceSupport {
try {
doWarmUp();
} catch (Exception e) {
- throw new FailedToStartRouteException(getId(), route.getDescription(), e);
+ throw new FailedToStartRouteException(getId(), e.getLocalizedMessage(), e);
}
}
@@ -129,7 +129,7 @@ public class RouteService extends ChildServiceSupport {
try {
doSetup();
} catch (Exception e) {
- throw new FailedToStartRouteException(getId(), route.getDescription(), e);
+ throw new FailedToStartRouteException(getId(), e.getLocalizedMessage(), e);
}
}
}