This is an automated email from the ASF dual-hosted git repository.

apupier 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 bb3a1bb45927 camel-cxf - stabilize flaky BindException in SSL 
jaxrs/jaxws tests
bb3a1bb45927 is described below

commit bb3a1bb4592772fc49d7bcd9e58e1747df25a091
Author: AurĂ©lien Pupier <[email protected]>
AuthorDate: Fri Oct 30 14:21:36 2026 +0100

    camel-cxf - stabilize flaky BindException in SSL jaxrs/jaxws tests
    
    Missing fix from the previous commit (7eab79adfeb9): the SSL tests in
    camel-cxf-spring-rest and camel-cxf-spring-soap still relied on the shared
    static CXFTestSupport SSL port and the CXFTestSupport.sslPort system 
property.
    
    Root cause
    ----------
    CXFTestSupport.SSL_PORT was allocated once at class-load time, long before 
the
    Spring context started the Undertow HTTPS listener, and was shared by every
    SSL test class of the JVM. The window between reserving the port and binding
    it was therefore large, and a surefire rerun of a failed test in the same 
JVM
    reused the very same port.
    
    Fix
    ---
    Each SSL test class now:
    
    1. Allocates its own port with AvailablePortFinder.find() in
       createApplicationContext(), i.e. as late as possible and just before the
       Spring context binds it. A rerun of the test gets a fresh port.
    
    2. Publishes it under a class-specific system property (e.g.
       SslTest.sslPort) which the Spring XML configuration references.
    
    3. Clears the property and releases the port in doPostTearDown().
    
    Affected classes:
      camel-cxf-spring-rest: CxfRsSslProducerTest, CxfRsSslAsyncProducerTest,
                             CxfRsGlobalSslProducerTest
      camel-cxf-spring-soap: SslTest, SslGlobalTest
    
    Also:
    - remove the now unused CXFTestSupport.getSslPort()
    - remove the dead CxfRsSpring*SslProducer.xml copies in camel-cxf-rest, they
      are not loaded by any test of that module (only the copies in
      camel-cxf-spring-rest are)
    - remove dead code in SslTest/SslGlobalTest (unused JAXWS_SERVER_ADDRESS
      constants and empty @BeforeAll/@AfterAll)
    
    Co-authored-by: IBM Bob 2.2.1
    Signed-off-by: AurĂ©lien Pupier <[email protected]>
---
 .../camel/component/cxf/common/CXFTestSupport.java |  5 --
 .../cxf/jaxrs/CxfRsSpringGlobalSslProducer.xml     | 96 ----------------------
 .../cxf/jaxrs/CxfRsSpringSslAsyncProducer.xml      | 96 ----------------------
 .../component/cxf/jaxrs/CxfRsSpringSslProducer.xml | 96 ----------------------
 .../cxf/jaxrs/CxfRsGlobalSslProducerTest.java      | 24 +++++-
 .../cxf/jaxrs/CxfRsSslAsyncProducerTest.java       | 24 +++++-
 .../component/cxf/jaxrs/CxfRsSslProducerTest.java  | 24 +++++-
 .../cxf/jaxrs/CxfRsSpringGlobalSslProducer.xml     |  6 +-
 .../cxf/jaxrs/CxfRsSpringSslAsyncProducer.xml      |  6 +-
 .../component/cxf/jaxrs/CxfRsSpringSslProducer.xml |  6 +-
 .../camel/component/cxf/ssl/SslGlobalTest.java     | 24 +++++-
 .../apache/camel/component/cxf/ssl/SslTest.java    | 38 +++++----
 .../camel/component/cxf/CxfGlobalSslContext.xml    |  4 +-
 .../apache/camel/component/cxf/CxfSslContext.xml   |  4 +-
 14 files changed, 118 insertions(+), 335 deletions(-)

diff --git 
a/components/camel-cxf/camel-cxf-common/src/test/java/org/apache/camel/component/cxf/common/CXFTestSupport.java
 
b/components/camel-cxf/camel-cxf-common/src/test/java/org/apache/camel/component/cxf/common/CXFTestSupport.java
index 64dc441ed98e..6d79bb12fe13 100644
--- 
a/components/camel-cxf/camel-cxf-common/src/test/java/org/apache/camel/component/cxf/common/CXFTestSupport.java
+++ 
b/components/camel-cxf/camel-cxf-common/src/test/java/org/apache/camel/component/cxf/common/CXFTestSupport.java
@@ -30,7 +30,6 @@ public final class CXFTestSupport {
     static final AvailablePortFinder.Port PORT5 = AvailablePortFinder.find();
     static final AvailablePortFinder.Port PORT6 = AvailablePortFinder.find();
     static final AvailablePortFinder.Port PORT7 = AvailablePortFinder.find();
-    static final AvailablePortFinder.Port SSL_PORT = 
AvailablePortFinder.find();
 
     static {
         //set them as system properties so Spring can use the property 
placeholder
@@ -42,7 +41,6 @@ public final class CXFTestSupport {
         System.setProperty("CXFTestSupport.port5", PORT5.toString());
         System.setProperty("CXFTestSupport.port6", PORT6.toString());
         System.setProperty("CXFTestSupport.port7", PORT7.toString());
-        System.setProperty("CXFTestSupport.sslPort", SSL_PORT.toString());
     }
 
     private CXFTestSupport() {
@@ -82,7 +80,4 @@ public final class CXFTestSupport {
         return PORT7.getPort();
     }
 
-    public static int getSslPort() {
-        return SSL_PORT.getPort();
-    }
 }
diff --git 
a/components/camel-cxf/camel-cxf-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringGlobalSslProducer.xml
 
b/components/camel-cxf/camel-cxf-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringGlobalSslProducer.xml
deleted file mode 100644
index 3e2804b01e7d..000000000000
--- 
a/components/camel-cxf/camel-cxf-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringGlobalSslProducer.xml
+++ /dev/null
@@ -1,96 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
-    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.
-
--->
-<beans xmlns="http://www.springframework.org/schema/beans";
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-       xmlns:cxf="http://camel.apache.org/schema/cxf";
-       xmlns:jaxrs="http://cxf.apache.org/jaxrs";
-       xmlns:sec="http://cxf.apache.org/configuration/security";
-       
xmlns:httpj="http://cxf.apache.org/transports/http-undertow/configuration";
-       xsi:schemaLocation="
-       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
-       http://camel.apache.org/schema/cxf 
http://camel.apache.org/schema/cxf/camel-cxf.xsd
-       http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
-       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
-       http://cxf.apache.org/configuration/security 
http://cxf.apache.org/schemas/configuration/security.xsd
-       http://cxf.apache.org/transports/http-undertow/configuration 
http://cxf.apache.org/schemas/configuration/http-undertow.xsd
-    ">
-    <bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
-
-    <import resource="classpath:META-INF/cxf/cxf.xml"/>
-
-    <httpj:engine-factory bus="cxf">
-        <!-- you just need to specify the TLS Server configuration for the 
certain port -->
-        <httpj:engine port="${CXFTestSupport.sslPort}">
-            <httpj:tlsServerParameters>
-                <sec:keyManagers keyPassword="changeit">
-                    <sec:keyStore type="JKS" password="changeit"
-                                  resource="/ssl/keystore-server.jks"/>
-                </sec:keyManagers>
-                <sec:clientAuthentication want="false" required="false"/>
-            </httpj:tlsServerParameters>
-        </httpj:engine>
-    </httpj:engine-factory>
-
-    <jaxrs:server id="restService"
-                  
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/";
-                  staticSubresourceResolution="true">
-        <jaxrs:serviceBeans>
-            <ref bean="customerService"/>
-        </jaxrs:serviceBeans>
-    </jaxrs:server>
-
-    <sslContextParameters xmlns="http://camel.apache.org/schema/spring";
-                          id="wrongSslContext">
-        <trustManagers>
-            <keyStore type="JKS" resource="/ssl/truststore-wrong.jks"
-                      password="changeit"/>
-        </trustManagers>
-    </sslContextParameters>
-    <sslContextParameters xmlns="http://camel.apache.org/schema/spring";
-                          id="mySslContext">
-        <trustManagers>
-            <keyStore type="JKS" resource="/ssl/truststore-client.jks"
-                      password="changeit"/>
-        </trustManagers>
-    </sslContextParameters>
-
-    <bean id="defaultHostnameVerifier"
-          
class="org.apache.cxf.transport.https.httpclient.DefaultHostnameVerifier"/>
-
-    <bean id="customerService" 
class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"/>
-
-    <cxf:rsClient id="rsClientHttp" 
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/"/>
-
-    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
-        <route>
-            <from uri="direct://trust"/>
-            <to 
uri="cxfrs://bean://rsClientHttp?hostnameVerifier=#defaultHostnameVerifier&amp;synchronous=true"/>
-        </route>
-        <route>
-            <from uri="direct://wrongTrust"/>
-            <to 
uri="cxfrs://bean://rsClientHttp?sslContextParameters=#wrongSslContext&amp;hostnameVerifier=#defaultHostnameVerifier&amp;synchronous=true"/>
-        </route>
-        <route>
-            <from uri="direct://noTrust"/>
-            <to 
uri="cxfrs://bean://rsClientHttp?sslContextParameters=#wrongSslContext&amp;hostnameVerifier=#defaultHostnameVerifier&amp;synchronous=true"/>
-        </route>
-    </camelContext>
-
-</beans>
diff --git 
a/components/camel-cxf/camel-cxf-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslAsyncProducer.xml
 
b/components/camel-cxf/camel-cxf-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslAsyncProducer.xml
deleted file mode 100644
index 2d6721b6281a..000000000000
--- 
a/components/camel-cxf/camel-cxf-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslAsyncProducer.xml
+++ /dev/null
@@ -1,96 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
-    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.
-
--->
-<beans xmlns="http://www.springframework.org/schema/beans";
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-       xmlns:cxf="http://camel.apache.org/schema/cxf";
-       xmlns:jaxrs="http://cxf.apache.org/jaxrs";
-       xmlns:sec="http://cxf.apache.org/configuration/security";
-       
xmlns:httpj="http://cxf.apache.org/transports/http-undertow/configuration";
-       xsi:schemaLocation="
-       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
-       http://camel.apache.org/schema/cxf 
http://camel.apache.org/schema/cxf/camel-cxf.xsd
-       http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
-       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
-       http://cxf.apache.org/configuration/security 
http://cxf.apache.org/schemas/configuration/security.xsd
-       http://cxf.apache.org/transports/http-undertow/configuration 
http://cxf.apache.org/schemas/configuration/http-undertow.xsd
-    ">
-    <bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
-
-    <import resource="classpath:META-INF/cxf/cxf.xml"/>
-
-    <httpj:engine-factory bus="cxf">
-        <!-- you just need to specify the TLS Server configuration for the 
certain port -->
-        <httpj:engine port="${CXFTestSupport.sslPort}">
-            <httpj:tlsServerParameters>
-                <sec:keyManagers keyPassword="changeit">
-                    <sec:keyStore type="JKS" password="changeit"
-                                  resource="/ssl/keystore-server.jks"/>
-                </sec:keyManagers>
-                <sec:clientAuthentication want="false" required="false"/>
-            </httpj:tlsServerParameters>
-        </httpj:engine>
-    </httpj:engine-factory>
-
-    <jaxrs:server id="restService"
-                  
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/";
-                  staticSubresourceResolution="true">
-        <jaxrs:serviceBeans>
-            <ref bean="customerService"/>
-        </jaxrs:serviceBeans>
-    </jaxrs:server>
-
-    <sslContextParameters xmlns="http://camel.apache.org/schema/spring";
-                          id="wrongSslContext">
-        <trustManagers>
-            <keyStore type="JKS" resource="/ssl/truststore-wrong.jks"
-                      password="changeit"/>
-        </trustManagers>
-    </sslContextParameters>
-    <sslContextParameters xmlns="http://camel.apache.org/schema/spring";
-                          id="mySslContext">
-        <trustManagers>
-            <keyStore type="JKS" resource="/ssl/truststore-client.jks"
-                      password="changeit"/>
-        </trustManagers>
-    </sslContextParameters>
-
-    <bean id="defaultHostnameVerifier"
-          
class="org.apache.cxf.transport.https.httpclient.DefaultHostnameVerifier"/>
-
-    <bean id="customerService" 
class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"/>
-
-    <cxf:rsClient id="rsClientHttp" 
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/"/>
-
-    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
-        <route>
-            <from uri="direct://trust"/>
-            <to 
uri="cxfrs://bean://rsClientHttp?sslContextParameters=#mySslContext&amp;hostnameVerifier=#defaultHostnameVerifier"/>
-        </route>
-        <route>
-            <from uri="direct://wrongTrust"/>
-            <to 
uri="cxfrs://bean://rsClientHttp?sslContextParameters=#wrongSslContext&amp;hostnameVerifier=#defaultHostnameVerifier"/>
-        </route>
-        <route>
-            <from uri="direct://noTrust"/>
-            <to 
uri="cxfrs://bean://rsClientHttp?sslContextParameters=#wrongSslContext&amp;hostnameVerifier=#defaultHostnameVerifier"/>
-        </route>
-    </camelContext>
-
-</beans>
diff --git 
a/components/camel-cxf/camel-cxf-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslProducer.xml
 
b/components/camel-cxf/camel-cxf-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslProducer.xml
deleted file mode 100644
index 30aab3e97eaa..000000000000
--- 
a/components/camel-cxf/camel-cxf-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslProducer.xml
+++ /dev/null
@@ -1,96 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
-    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.
-
--->
-<beans xmlns="http://www.springframework.org/schema/beans";
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-       xmlns:cxf="http://camel.apache.org/schema/cxf";
-       xmlns:jaxrs="http://cxf.apache.org/jaxrs";
-       xmlns:sec="http://cxf.apache.org/configuration/security";
-       
xmlns:httpj="http://cxf.apache.org/transports/http-undertow/configuration";
-       xsi:schemaLocation="
-       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
-       http://camel.apache.org/schema/cxf 
http://camel.apache.org/schema/cxf/camel-cxf.xsd
-       http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
-       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
-       http://cxf.apache.org/configuration/security 
http://cxf.apache.org/schemas/configuration/security.xsd
-       http://cxf.apache.org/transports/http-undertow/configuration 
http://cxf.apache.org/schemas/configuration/http-undertow.xsd
-    ">
-    <bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
-
-    <import resource="classpath:META-INF/cxf/cxf.xml"/>
-
-    <httpj:engine-factory bus="cxf">
-        <!-- you just need to specify the TLS Server configuration for the 
certain port -->
-        <httpj:engine port="${CXFTestSupport.sslPort}">
-            <httpj:tlsServerParameters>
-                <sec:keyManagers keyPassword="changeit">
-                    <sec:keyStore type="JKS" password="changeit"
-                                  resource="/ssl/keystore-server.jks"/>
-                </sec:keyManagers>
-                <sec:clientAuthentication want="false" required="false"/>
-            </httpj:tlsServerParameters>
-        </httpj:engine>
-    </httpj:engine-factory>
-
-    <jaxrs:server id="restService"
-                  
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/";
-                  staticSubresourceResolution="true">
-        <jaxrs:serviceBeans>
-            <ref bean="customerService"/>
-        </jaxrs:serviceBeans>
-    </jaxrs:server>
-
-    <sslContextParameters xmlns="http://camel.apache.org/schema/spring";
-                          id="wrongSslContext">
-        <trustManagers>
-            <keyStore type="JKS" resource="/ssl/truststore-wrong.jks"
-                      password="changeit"/>
-        </trustManagers>
-    </sslContextParameters>
-    <sslContextParameters xmlns="http://camel.apache.org/schema/spring";
-                          id="mySslContext">
-        <trustManagers>
-            <keyStore type="JKS" resource="/ssl/truststore-client.jks"
-                      password="changeit"/>
-        </trustManagers>
-    </sslContextParameters>
-
-    <bean id="defaultHostnameVerifier"
-          
class="org.apache.cxf.transport.https.httpclient.DefaultHostnameVerifier"/>
-
-    <bean id="customerService" 
class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"/>
-
-    <cxf:rsClient id="rsClientHttp" 
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/"/>
-
-    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
-        <route>
-            <from uri="direct://trust"/>
-            <to 
uri="cxfrs://bean://rsClientHttp?sslContextParameters=#mySslContext&amp;hostnameVerifier=#defaultHostnameVerifier&amp;synchronous=true"/>
-        </route>
-        <route>
-            <from uri="direct://wrongTrust"/>
-            <to 
uri="cxfrs://bean://rsClientHttp?sslContextParameters=#wrongSslContext&amp;hostnameVerifier=#defaultHostnameVerifier&amp;synchronous=true"/>
-        </route>
-        <route>
-            <from uri="direct://noTrust"/>
-            <to 
uri="cxfrs://bean://rsClientHttp?sslContextParameters=#wrongSslContext&amp;hostnameVerifier=#defaultHostnameVerifier&amp;synchronous=true"/>
-        </route>
-    </camelContext>
-
-</beans>
diff --git 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsGlobalSslProducerTest.java
 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsGlobalSslProducerTest.java
index 0fd82c26846b..bdee3a2907a8 100644
--- 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsGlobalSslProducerTest.java
+++ 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsGlobalSslProducerTest.java
@@ -22,10 +22,10 @@ import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.SSLContextParametersAware;
-import org.apache.camel.component.cxf.common.CXFTestSupport;
 import org.apache.camel.component.cxf.common.message.CxfConstants;
 import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
 import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.spring.junit6.CamelSpringTestSupport;
 import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
@@ -36,17 +36,35 @@ import static 
org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class CxfRsGlobalSslProducerTest extends CamelSpringTestSupport {
-    private static int port1 = CXFTestSupport.getSslPort();
+    static final String PORT_PROPERTY = "CxfRsGlobalSslProducerTest.sslPort";
+
+    // allocated as late as possible (when the Spring context is created) to 
minimize the time between
+    // the port reservation and its binding by the route
+    private AvailablePortFinder.Port sslPort;
 
     public int getPort1() {
-        return port1;
+        return sslPort.getPort();
     }
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
+        sslPort = AvailablePortFinder.find();
+        System.setProperty(PORT_PROPERTY, sslPort.toString());
         return new 
ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsSpringGlobalSslProducer.xml");
     }
 
+    @Override
+    public void doPostTearDown() throws Exception {
+        try {
+            super.doPostTearDown();
+        } finally {
+            System.clearProperty(PORT_PROPERTY);
+            if (sslPort != null) {
+                sslPort.release();
+            }
+        }
+    }
+
     @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
diff --git 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSslAsyncProducerTest.java
 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSslAsyncProducerTest.java
index 1154d93eed8f..87abbf51afb5 100644
--- 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSslAsyncProducerTest.java
+++ 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSslAsyncProducerTest.java
@@ -20,9 +20,9 @@ import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
-import org.apache.camel.component.cxf.common.CXFTestSupport;
 import org.apache.camel.component.cxf.common.message.CxfConstants;
 import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.spring.junit6.CamelSpringTestSupport;
 import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
@@ -33,17 +33,35 @@ import static 
org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class CxfRsSslAsyncProducerTest extends CamelSpringTestSupport {
-    private static int port1 = CXFTestSupport.getSslPort();
+    static final String PORT_PROPERTY = "CxfRsSslAsyncProducerTest.sslPort";
+
+    // allocated as late as possible (when the Spring context is created) to 
minimize the time between
+    // the port reservation and its binding by the route
+    private AvailablePortFinder.Port sslPort;
 
     public int getPort1() {
-        return port1;
+        return sslPort.getPort();
     }
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
+        sslPort = AvailablePortFinder.find();
+        System.setProperty(PORT_PROPERTY, sslPort.toString());
         return new 
ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslAsyncProducer.xml");
     }
 
+    @Override
+    public void doPostTearDown() throws Exception {
+        try {
+            super.doPostTearDown();
+        } finally {
+            System.clearProperty(PORT_PROPERTY);
+            if (sslPort != null) {
+                sslPort.release();
+            }
+        }
+    }
+
     @Test
     public void testCorrectTrustStore() {
         Exchange exchange = template.send("direct://trust", new MyProcessor());
diff --git 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSslProducerTest.java
 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSslProducerTest.java
index fffbf349d6a6..2f8ab165aee5 100644
--- 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSslProducerTest.java
+++ 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSslProducerTest.java
@@ -20,9 +20,9 @@ import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
-import org.apache.camel.component.cxf.common.CXFTestSupport;
 import org.apache.camel.component.cxf.common.message.CxfConstants;
 import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.spring.junit6.CamelSpringTestSupport;
 import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
@@ -33,17 +33,35 @@ import static 
org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class CxfRsSslProducerTest extends CamelSpringTestSupport {
-    private static int port1 = CXFTestSupport.getSslPort();
+    static final String PORT_PROPERTY = "CxfRsSslProducerTest.sslPort";
+
+    // allocated as late as possible (when the Spring context is created) to 
minimize the time between
+    // the port reservation and its binding by the route
+    private AvailablePortFinder.Port sslPort;
 
     public int getPort1() {
-        return port1;
+        return sslPort.getPort();
     }
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
+        sslPort = AvailablePortFinder.find();
+        System.setProperty(PORT_PROPERTY, sslPort.toString());
         return new 
ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslProducer.xml");
     }
 
+    @Override
+    public void doPostTearDown() throws Exception {
+        try {
+            super.doPostTearDown();
+        } finally {
+            System.clearProperty(PORT_PROPERTY);
+            if (sslPort != null) {
+                sslPort.release();
+            }
+        }
+    }
+
     protected void setupDestinationURL(Message inMessage) {
         // do nothing here
     }
diff --git 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringGlobalSslProducer.xml
 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringGlobalSslProducer.xml
index e4503a4d5df8..5142a3af99aa 100644
--- 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringGlobalSslProducer.xml
+++ 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringGlobalSslProducer.xml
@@ -37,7 +37,7 @@
 
     <httpj:engine-factory bus="cxf">
         <!-- you just need to specify the TLS Server configuration for the 
certain port -->
-        <httpj:engine port="${CXFTestSupport.sslPort}">
+        <httpj:engine port="${CxfRsGlobalSslProducerTest.sslPort}">
             <httpj:tlsServerParameters>
                 <sec:keyManagers keyPassword="changeit">
                     <sec:keyStore type="JKS" password="changeit"
@@ -49,7 +49,7 @@
     </httpj:engine-factory>
 
     <jaxrs:server id="restService"
-                  
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/";
+                  
address="https://localhost:${CxfRsGlobalSslProducerTest.sslPort}/CxfRsProducerTest/";
                   staticSubresourceResolution="true">
         <jaxrs:serviceBeans>
             <ref bean="customerService"/>
@@ -76,7 +76,7 @@
 
     <bean id="customerService" 
class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"/>
 
-    <cxf:rsClient id="rsClientHttp" 
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/"/>
+    <cxf:rsClient id="rsClientHttp" 
address="https://localhost:${CxfRsGlobalSslProducerTest.sslPort}/CxfRsProducerTest/"/>
 
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
         <route>
diff --git 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslAsyncProducer.xml
 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslAsyncProducer.xml
index f93919fbfebf..bc4c12d9f02f 100644
--- 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslAsyncProducer.xml
+++ 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslAsyncProducer.xml
@@ -37,7 +37,7 @@
 
     <httpj:engine-factory bus="cxf">
         <!-- you just need to specify the TLS Server configuration for the 
certain port -->
-        <httpj:engine port="${CXFTestSupport.sslPort}">
+        <httpj:engine port="${CxfRsSslAsyncProducerTest.sslPort}">
             <httpj:tlsServerParameters>
                 <sec:keyManagers keyPassword="changeit">
                     <sec:keyStore type="JKS" password="changeit"
@@ -49,7 +49,7 @@
     </httpj:engine-factory>
 
     <jaxrs:server id="restService"
-                  
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/";
+                  
address="https://localhost:${CxfRsSslAsyncProducerTest.sslPort}/CxfRsProducerTest/";
                   staticSubresourceResolution="true">
         <jaxrs:serviceBeans>
             <ref bean="customerService"/>
@@ -76,7 +76,7 @@
 
     <bean id="customerService" 
class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"/>
 
-    <cxf:rsClient id="rsClientHttp" 
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/"/>
+    <cxf:rsClient id="rsClientHttp" 
address="https://localhost:${CxfRsSslAsyncProducerTest.sslPort}/CxfRsProducerTest/"/>
 
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
         <route>
diff --git 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslProducer.xml
 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslProducer.xml
index dd70364d4603..a5a1ee5a7679 100644
--- 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslProducer.xml
+++ 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslProducer.xml
@@ -37,7 +37,7 @@
 
     <httpj:engine-factory bus="cxf">
         <!-- you just need to specify the TLS Server configuration for the 
certain port -->
-        <httpj:engine port="${CXFTestSupport.sslPort}">
+        <httpj:engine port="${CxfRsSslProducerTest.sslPort}">
             <httpj:tlsServerParameters>
                 <sec:keyManagers keyPassword="changeit">
                     <sec:keyStore type="JKS" password="changeit"
@@ -49,7 +49,7 @@
     </httpj:engine-factory>
 
     <jaxrs:server id="restService"
-                  
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/";
+                  
address="https://localhost:${CxfRsSslProducerTest.sslPort}/CxfRsProducerTest/";
                   staticSubresourceResolution="true">
         <jaxrs:serviceBeans>
             <ref bean="customerService"/>
@@ -76,7 +76,7 @@
 
     <bean id="customerService" 
class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"/>
 
-    <cxf:rsClient id="rsClientHttp" 
address="https://localhost:${CXFTestSupport.sslPort}/CxfRsProducerTest/"/>
+    <cxf:rsClient id="rsClientHttp" 
address="https://localhost:${CxfRsSslProducerTest.sslPort}/CxfRsProducerTest/"/>
 
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
         <route>
diff --git 
a/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/ssl/SslGlobalTest.java
 
b/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/ssl/SslGlobalTest.java
index 4184a50ea351..312b4025ed0e 100644
--- 
a/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/ssl/SslGlobalTest.java
+++ 
b/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/ssl/SslGlobalTest.java
@@ -23,9 +23,9 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.SSLContextParametersAware;
-import org.apache.camel.component.cxf.common.CXFTestSupport;
 import org.apache.camel.component.cxf.common.message.CxfConstants;
 import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.spring.junit6.CamelSpringTestSupport;
 import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
@@ -37,10 +37,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class SslGlobalTest extends CamelSpringTestSupport {
 
+    static final String PORT_PROPERTY = "SslGlobalTest.sslPort";
+
+    // allocated as late as possible (when the Spring context is created) to 
minimize the time between
+    // the port reservation and its binding by the route
+    private AvailablePortFinder.Port sslPort;
+
     protected static final String GREET_ME_OPERATION = "greetMe";
     protected static final String TEST_MESSAGE = "Hello World!";
-    protected static final String JAXWS_SERVER_ADDRESS
-            = "https://localhost:"; + CXFTestSupport.getPort1() + 
"/CxfSslTest/SoapContext/SoapPort";
 
     @Override
     protected CamelContext createCamelContext() throws Exception {
@@ -87,8 +91,22 @@ public class SslGlobalTest extends CamelSpringTestSupport {
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
+        sslPort = AvailablePortFinder.find();
+        System.setProperty(PORT_PROPERTY, sslPort.toString());
         // we can put the http conduit configuration here
         return new 
ClassPathXmlApplicationContext("org/apache/camel/component/cxf/CxfGlobalSslContext.xml");
     }
 
+    @Override
+    public void doPostTearDown() throws Exception {
+        try {
+            super.doPostTearDown();
+        } finally {
+            System.clearProperty(PORT_PROPERTY);
+            if (sslPort != null) {
+                sslPort.release();
+            }
+        }
+    }
+
 }
diff --git 
a/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/ssl/SslTest.java
 
b/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/ssl/SslTest.java
index 74a1ce613232..3122fb3f8056 100644
--- 
a/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/ssl/SslTest.java
+++ 
b/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/ssl/SslTest.java
@@ -21,11 +21,9 @@ import java.util.List;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.apache.camel.component.cxf.common.CXFTestSupport;
 import org.apache.camel.component.cxf.common.message.CxfConstants;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.spring.junit6.CamelSpringTestSupport;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -36,22 +34,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class SslTest extends CamelSpringTestSupport {
 
-    protected static final String GREET_ME_OPERATION = "greetMe";
-    protected static final String TEST_MESSAGE = "Hello World!";
-    protected static final String JAXWS_SERVER_ADDRESS
-            = "https://localhost:"; + CXFTestSupport.getPort1() + 
"/CxfSslTest/SoapContext/SoapPort";
+    static final String PORT_PROPERTY = "SslTest.sslPort";
 
-    @AfterAll
-    public static void cleanUp() {
-        //System.clearProperty("cxf.config.file");
-    }
+    // allocated as late as possible (when the Spring context is created) to 
minimize the time between
+    // the port reservation and its binding by the route
+    private AvailablePortFinder.Port sslPort;
 
-    @BeforeAll
-    public static void startService() {
-        //System.getProperties().put("cxf.config.file", 
"/org/apache/camel/component/cxf/CxfSslContext.xml");
-        //Greeter implementor = new GreeterImpl();
-        //Endpoint.publish(JAXWS_SERVER_ADDRESS, implementor);
-    }
+    protected static final String GREET_ME_OPERATION = "greetMe";
+    protected static final String TEST_MESSAGE = "Hello World!";
 
     @Test
     public void testInvokingTrustRoute() throws Exception {
@@ -97,8 +87,22 @@ public class SslTest extends CamelSpringTestSupport {
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
+        sslPort = AvailablePortFinder.find();
+        System.setProperty(PORT_PROPERTY, sslPort.toString());
         // we can put the http conduit configuration here
         return new 
ClassPathXmlApplicationContext("org/apache/camel/component/cxf/CxfSslContext.xml");
     }
 
+    @Override
+    public void doPostTearDown() throws Exception {
+        try {
+            super.doPostTearDown();
+        } finally {
+            System.clearProperty(PORT_PROPERTY);
+            if (sslPort != null) {
+                sslPort.release();
+            }
+        }
+    }
+
 }
diff --git 
a/components/camel-cxf/camel-cxf-spring-soap/src/test/resources/org/apache/camel/component/cxf/CxfGlobalSslContext.xml
 
b/components/camel-cxf/camel-cxf-spring-soap/src/test/resources/org/apache/camel/component/cxf/CxfGlobalSslContext.xml
index 68de2a65881b..52f0b6f71b49 100644
--- 
a/components/camel-cxf/camel-cxf-spring-soap/src/test/resources/org/apache/camel/component/cxf/CxfGlobalSslContext.xml
+++ 
b/components/camel-cxf/camel-cxf-spring-soap/src/test/resources/org/apache/camel/component/cxf/CxfGlobalSslContext.xml
@@ -34,7 +34,7 @@
 
     <httpj:engine-factory bus="cxf">
         <!-- you just need to specify the TLS Server configuration for the 
certain port -->
-        <httpj:engine port="${CXFTestSupport.sslPort}">
+        <httpj:engine port="${SslGlobalTest.sslPort}">
             <httpj:tlsServerParameters>
                 <sec:keyManagers keyPassword="changeit">
                     <sec:keyStore type="JKS" password="changeit"
@@ -66,7 +66,7 @@
           
class="org.apache.cxf.transport.https.httpclient.DefaultHostnameVerifier"/>
 
     <cxf:cxfEndpoint id="springEndpoint"
-                     
address="https://localhost:${CXFTestSupport.sslPort}/CxfSslTest/SoapContext/SoapPort";
+                     
address="https://localhost:${SslGlobalTest.sslPort}/CxfSslTest/SoapContext/SoapPort";
                      serviceClass="org.apache.hello_world_soap_http.Greeter"/>
 
     <bean id="greeter" class="org.apache.camel.component.cxf.GreeterImpl"/>
diff --git 
a/components/camel-cxf/camel-cxf-spring-soap/src/test/resources/org/apache/camel/component/cxf/CxfSslContext.xml
 
b/components/camel-cxf/camel-cxf-spring-soap/src/test/resources/org/apache/camel/component/cxf/CxfSslContext.xml
index b2243defbfc6..fcfceaf633f6 100644
--- 
a/components/camel-cxf/camel-cxf-spring-soap/src/test/resources/org/apache/camel/component/cxf/CxfSslContext.xml
+++ 
b/components/camel-cxf/camel-cxf-spring-soap/src/test/resources/org/apache/camel/component/cxf/CxfSslContext.xml
@@ -34,7 +34,7 @@
 
     <httpj:engine-factory bus="cxf">
         <!-- you just need to specify the TLS Server configuration for the 
certain port -->
-        <httpj:engine port="${CXFTestSupport.sslPort}">
+        <httpj:engine port="${SslTest.sslPort}">
             <httpj:tlsServerParameters>
                 <sec:keyManagers keyPassword="changeit">
                     <sec:keyStore type="JKS" password="changeit"
@@ -66,7 +66,7 @@
           
class="org.apache.cxf.transport.https.httpclient.DefaultHostnameVerifier"/>
 
     <cxf:cxfEndpoint id="springEndpoint"
-                     
address="https://localhost:${CXFTestSupport.sslPort}/CxfSslTest/SoapContext/SoapPort";
+                     
address="https://localhost:${SslTest.sslPort}/CxfSslTest/SoapContext/SoapPort";
                      serviceClass="org.apache.hello_world_soap_http.Greeter"/>
 
     <bean id="greeter" class="org.apache.camel.component.cxf.GreeterImpl"/>

Reply via email to