diff --git a/Jenkinsfile.talend b/Jenkinsfile.talend index 444aa398cfe46..024e660ccf4c1 100644 --- a/Jenkinsfile.talend +++ b/Jenkinsfile.talend @@ -48,6 +48,7 @@ org.apache.camel:camel-drill,\ org.apache.camel:camel-dynamic-router,\ org.apache.camel:camel-file,\ org.apache.camel:camel-google-pubsub,\ +org.apache.camel:camel-http-common,\ org.apache.camel:camel-http,\ org.apache.camel:camel-infinispan,\ org.apache.camel:camel-jaxb,\ diff --git a/components/camel-http-common/pom.xml b/components/camel-http-common/pom.xml index d14d2af4d493f..c6e3630c073fa 100644 --- a/components/camel-http-common/pom.xml +++ b/components/camel-http-common/pom.xml @@ -31,8 +31,10 @@ Camel :: HTTP :: Common Camel HTTP common + ${revision} + ${camel-http-common.tesb.version} 2.16.0 diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpCommonEndpoint.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpCommonEndpoint.java index 7ad028318c3b5..6f65939abc366 100644 --- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpCommonEndpoint.java +++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpCommonEndpoint.java @@ -170,7 +170,9 @@ public abstract class HttpCommonEndpoint extends DefaultEndpoint private String proxyHost; @UriParam(label = "producer,proxy", description = "Proxy port to use") private int proxyPort; - @UriParam(label = "producer,proxy", enums = "http,https", description = "Proxy authentication scheme to use") + @UriParam(label = "producer,proxy", enums = "http,https", defaultValue = "http", + description = "Proxy server connection protocol scheme. Defaults to http regardless of the target endpoint scheme," + + " because most corporate HTTP proxies expect a plain HTTP connection on their listener port.") private String proxyAuthScheme; @UriParam(label = "producer,proxy", enums = "Basic,Digest,NTLM", description = "Proxy authentication method to use") private String proxyAuthMethod; diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpConfiguration.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpConfiguration.java index c0a404ab59cc1..de4f1ebc292a5 100644 --- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpConfiguration.java +++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpConfiguration.java @@ -49,7 +49,9 @@ public class HttpConfiguration implements Serializable { private String proxyHost; @Metadata(label = "producer,proxy", description = "Proxy port to use") private int proxyPort; - @Metadata(label = "producer,proxy", enums = "http,https", description = "Authentication scheme to use") + @Metadata(label = "producer,proxy", enums = "http,https", defaultValue = "http", + description = "Proxy server connection protocol scheme. Defaults to http regardless of the target endpoint scheme," + + " because most corporate HTTP proxies expect a plain HTTP connection on their listener port.") private String proxyAuthScheme; @Metadata(label = "producer,proxy", enums = "Basic,Digest,NTLM", description = "Proxy authentication method to use") private String proxyAuthMethod; diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java index 23c4138dcd57a..a146086228095 100644 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java @@ -131,7 +131,9 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa protected Timeout responseTimeout = Timeout.ofMilliseconds(0); // proxy - @Metadata(label = "producer,proxy", enums = "http,https", description = "Proxy authentication protocol scheme") + @Metadata(label = "producer,proxy", enums = "http,https", defaultValue = "http", + description = "Proxy server connection protocol scheme. Defaults to http regardless of the target endpoint scheme," + + " because most corporate HTTP proxies expect a plain HTTP connection on their listener port.") protected String proxyAuthScheme; @Metadata(label = "producer,proxy", enums = "Basic,Digest,NTLM", description = "Proxy authentication method to use") protected String proxyAuthMethod; @@ -222,7 +224,7 @@ protected HttpClientConfigurer createHttpClientConfigurer(Map pa } HttpCredentialsHelper credentialsProvider = new HttpCredentialsHelper(); configurer = configureBasicAuthentication(parameters, configurer, credentialsProvider); - configurer = configureHttpProxy(parameters, configurer, secure, credentialsProvider); + configurer = configureHttpProxy(parameters, configurer, credentialsProvider); configurer = configureOAuth2Authentication(parameters, configurer); return configurer; @@ -270,12 +272,12 @@ private HttpClientConfigurer configureBasicAuthentication( } private HttpClientConfigurer configureHttpProxy( - Map parameters, HttpClientConfigurer configurer, boolean secure, + Map parameters, HttpClientConfigurer configurer, HttpCredentialsHelper credentialsProvider) { String proxyAuthScheme = getParameter(parameters, "proxyAuthScheme", String.class, getProxyAuthScheme()); if (proxyAuthScheme == null) { - // fallback and use either http or https depending on secure - proxyAuthScheme = secure ? "https" : "http"; + // proxy connection itself uses http by default regardless of the target endpoint scheme + proxyAuthScheme = "http"; } String proxyAuthHost = getParameter(parameters, "proxyAuthHost", String.class, getProxyAuthHost()); Integer proxyAuthPort = getParameter(parameters, "proxyAuthPort", Integer.class, getProxyAuthPort()); diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java index d973ef3ca12b0..8113e5ef2f493 100644 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java @@ -29,7 +29,6 @@ import org.apache.camel.Producer; import org.apache.camel.api.management.ManagedAttribute; import org.apache.camel.api.management.ManagedResource; -import org.apache.camel.http.base.HttpHelper; import org.apache.camel.http.base.cookie.CookieHandler; import org.apache.camel.http.common.HttpCommonEndpoint; import org.apache.camel.spi.Metadata; @@ -255,9 +254,9 @@ protected HttpClient createHttpClient() { String host = getCamelContext().getGlobalOption("http.proxyHost"); int port = Integer.parseInt(getCamelContext().getGlobalOption("http.proxyPort")); String scheme = getCamelContext().getGlobalOption("http.proxyScheme"); - // fallback and use either http or https depending on secure + // proxy connection uses http by default regardless of the target endpoint scheme if (scheme == null) { - scheme = HttpHelper.isSecureConnection(getEndpointUri()) ? "https" : "http"; + scheme = "http"; } LOG.debug( "CamelContext properties http.proxyHost, http.proxyPort, and http.proxyScheme detected. Using http proxy host: {} port: {} scheme: {}", diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyServerTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyServerTest.java index baa2ce1f52355..4029874a72d73 100644 --- a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyServerTest.java +++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyServerTest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.http; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -26,6 +27,8 @@ import org.apache.camel.component.http.interceptor.RequestProxyBasicAuth; import org.apache.camel.component.http.interceptor.ResponseProxyBasicUnauthorized; import org.apache.camel.util.URISupport; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.HttpRequestInterceptor; import org.apache.hc.core5.http.HttpResponseInterceptor; import org.apache.hc.core5.http.impl.bootstrap.HttpServer; @@ -36,6 +39,7 @@ import org.junit.jupiter.api.Test; import static org.apache.camel.component.http.HttpMethods.GET; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; public class HttpProxyServerTest extends BaseHttpTest { @@ -129,6 +133,30 @@ public void httpGetWithProxyOnComponent() { assertExchange(exchange); } + @Test + public void httpsTargetWithProxyDefaultsToHttpProxyScheme() throws Exception { + // CAMEL-24632: proxy scheme must default to "http" regardless of the target endpoint scheme + HttpEndpoint endpoint = context.getEndpoint( + "https://www.example.com?proxyHost=myproxy&proxyPort=8080", HttpEndpoint.class); + + HttpClientConfigurer configurer = endpoint.getHttpClientConfigurer(); + assertThat(configurer).isNotNull(); + + HttpClientBuilder builder = HttpClientBuilder.create(); + configurer.configureHttpClient(builder); + + Field proxyField = HttpClientBuilder.class.getDeclaredField("proxy"); + proxyField.setAccessible(true); + HttpHost proxy = (HttpHost) proxyField.get(builder); + + assertThat(proxy).isNotNull(); + assertThat(proxy.getHostName()).isEqualTo("myproxy"); + assertThat(proxy.getPort()).isEqualTo(8080); + assertThat(proxy.getSchemeName()) + .as("Proxy scheme must be http even when the target endpoint is https") + .isEqualTo("http"); + } + private String getHost() { return "127.0.0.1"; } diff --git a/pom.xml b/pom.xml index f425c4869d91c..5ba8ce03faccd 100644 --- a/pom.xml +++ b/pom.xml @@ -138,7 +138,8 @@ 4.8.1.20250320 4.8.1.20250320 4.8.1.20260608 - 4.8.1.20250320 + 4.8.1.20260909 + 4.8.1.20260909 4.8.1.20260608 4.8.1.20250320 4.8.1.20260608 @@ -179,8 +180,8 @@ 4.8.1.20250320 4.8.1.20250320 4.8.1.20250320 - 4.8.1.20260608 - 4.8.1.20260608 + 4.8.1.20260909 + 4.8.1.20260909 4.8.1.20250320 4.8.1.20250320 4.8.1.20250320