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 7286241dc548 CAMEL-24379: Fix AS2 client ignoring custom 
HostnameVerifier
7286241dc548 is described below

commit 7286241dc548857c413170ccd0910e2efa0f03f4
Author: Torsten Mielke <[email protected]>
AuthorDate: Tue Aug 11 16:22:10 2026 +0200

    CAMEL-24379: Fix AS2 client ignoring custom HostnameVerifier
    
    When a custom HostnameVerifier (e.g. NoopHostnameVerifier) was configured
    on the AS2 endpoint, it was silently ignored. The DefaultClientTlsStrategy
    defaulted to HostnameVerificationPolicy.BOTH, which causes the JDK trust
    manager to enforce hostname verification during the TLS handshake before the
    custom HostnameVerifier runs. Fix by using HostnameVerificationPolicy.CLIENT
    so hostname verification is delegated entirely to the provided verifier.
    
    Closes #25446
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .../camel/component/as2/api/AS2ClientConnection.java     |  3 ++-
 .../component/as2/MendelsonSslEndpointManualTest.java    | 16 +++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git 
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientConnection.java
 
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientConnection.java
index 2d2d4bc8f8f5..dafaa6c63d2b 100644
--- 
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientConnection.java
+++ 
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientConnection.java
@@ -42,6 +42,7 @@ import org.apache.hc.client5.http.io.ConnectionEndpoint;
 import org.apache.hc.client5.http.io.LeaseRequest;
 import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
 import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
+import org.apache.hc.client5.http.ssl.HostnameVerificationPolicy;
 import org.apache.hc.client5.http.ssl.TlsSocketStrategy;
 import org.apache.hc.core5.http.*;
 import org.apache.hc.core5.http.config.Http1Config;
@@ -136,7 +137,7 @@ public class AS2ClientConnection {
             if (hostnameVerifier == null) {
                 tlsStrategy = new DefaultClientTlsStrategy(sslContext);
             } else {
-                tlsStrategy = new DefaultClientTlsStrategy(sslContext, 
hostnameVerifier);
+                tlsStrategy = new DefaultClientTlsStrategy(sslContext, 
HostnameVerificationPolicy.CLIENT, hostnameVerifier);
             }
             builder.setTlsSocketStrategy(tlsStrategy);
         }
diff --git 
a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/MendelsonSslEndpointManualTest.java
 
b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/MendelsonSslEndpointManualTest.java
index e9438f0a8dcc..196a3aae4808 100644
--- 
a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/MendelsonSslEndpointManualTest.java
+++ 
b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/MendelsonSslEndpointManualTest.java
@@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory;
  * committed with @Disabled annotation due to the test can bring dependency on 
3rd party resource.
  */
 @Disabled("Run this test manually")
-public class MendelsonSslEndpointManualTest extends AbstractAS2ITSupport {
+class MendelsonSslEndpointManualTest extends AbstractAS2ITSupport {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(MendelsonSslEndpointManualTest.class);
     private static HostnameVerifier hostnameVerifier;
@@ -51,7 +51,7 @@ public class MendelsonSslEndpointManualTest extends 
AbstractAS2ITSupport {
     private static final Properties props = new Properties();
 
     @BeforeAll
-    public static void setupTest() {
+    static void setupTest() {
         TestSupport.loadExternalPropertiesQuietly(props, 
MendelsonSslEndpointManualTest.class.getClassLoader(),
                 "test-server.properties");
 
@@ -66,7 +66,7 @@ public class MendelsonSslEndpointManualTest extends 
AbstractAS2ITSupport {
     }
 
     @Test
-    public void testCreateEndpointAndSendViaHTTPS() throws Exception {
+    void testCreateEndpointAndSendViaHTTPS() throws Exception {
         CamelContext camelContext = new DefaultCamelContext();
         camelContext.start();
 
@@ -89,7 +89,6 @@ public class MendelsonSslEndpointManualTest extends 
AbstractAS2ITSupport {
         endpointConfiguration.setAs2From(props.getProperty("as2.as2from"));
         endpointConfiguration.setFrom(props.getProperty("as2.from"));
         endpointConfiguration.setSubject(props.getProperty("as2.subject"));
-        
endpointConfiguration.setSigningAlgorithm(AS2SignatureAlgorithm.MD2WITHRSA);
         
endpointConfiguration.setEdiMessageTransferEncoding(props.getProperty("as2.transfer.encoding"));
         
endpointConfiguration.setAttachedFileName(props.getProperty("as2.attached.filename"));
 
@@ -113,10 +112,17 @@ public class MendelsonSslEndpointManualTest extends 
AbstractAS2ITSupport {
                 = camelContext.createProducerTemplate().request(endpoint,
                         exchange -> 
exchange.getIn().setBody(props.getProperty("as2.edi.message")));
         Throwable cause = out.getException();
-        Assertions.assertNull(cause);
+        Assertions.assertNull(cause, () -> "AS2 send failed; root cause: " + 
getRootCause(cause));
         LOG.debug(
                 "Sending done. If you used Mendelson settings for connection, 
" +
                   "you can check your message in 
http://testas2.mendelson-e-c.com:8080/webas2/ " +
                   "Login guest, password guest");
     }
+
+    private static Throwable getRootCause(Throwable t) {
+        while (t.getCause() != null) {
+            t = t.getCause();
+        }
+        return t;
+    }
 }

Reply via email to