This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch CAMEL-23214-port-cxf-netty in repository https://gitbox.apache.org/repos/asf/camel.git
commit 837b838f9bc22b36cdfc5c506c8a757984f864fa Author: Guillaume Nodet <[email protected]> AuthorDate: Fri Mar 20 09:07:29 2026 +0100 CAMEL-23214: Keep Port references alive in CXF tests to prevent TOCTOU race CxfConsumerPayloadXPathTest: the port is used by CXF to bind a consumer endpoint, so releasing it immediately allows another process to grab it. CxfProducerTest: the port is used for a "wrong server" address where nothing should listen, but releasing it allows reuse by other tests. Co-Authored-By: Claude Opus 4.6 <[email protected]> --- .../component/cxf/jaxws/CxfConsumerPayloadXPathTest.java | 12 +++++++----- .../apache/camel/component/cxf/jaxws/CxfProducerTest.java | 8 +++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfConsumerPayloadXPathTest.java b/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfConsumerPayloadXPathTest.java index b3492c1ca4d3..768369e1c009 100644 --- a/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfConsumerPayloadXPathTest.java +++ b/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfConsumerPayloadXPathTest.java @@ -241,12 +241,14 @@ public class CxfConsumerPayloadXPathTest extends CamelTestSupport { } } + // Keep a reference to the port to prevent it from being reused before CXF binds to it + private AvailablePortFinder.Port availablePort; + private String getAvailableUrl(String pathEnd) { - try (AvailablePortFinder.Port p = AvailablePortFinder.find()) { - String url = "http://localhost:" + p.getPort() - + "/" + getClass().getSimpleName(); - return url + "/" + pathEnd; - } + availablePort = AvailablePortFinder.find(); + String url = "http://localhost:" + availablePort.getPort() + + "/" + getClass().getSimpleName(); + return url + "/" + pathEnd; } private String constructSoapMessage(String content) { diff --git a/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfProducerTest.java b/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfProducerTest.java index 0e30eb1b3113..5e8c694169bb 100644 --- a/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfProducerTest.java +++ b/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfProducerTest.java @@ -72,11 +72,13 @@ public class CxfProducerTest { return "http://localhost:" + CXFTestSupport.getPort2() + "/" + getClass().getSimpleName() + "/test"; } + // Keep port reference to prevent reuse — this address must have nothing listening on it + private AvailablePortFinder.Port wrongPort; + protected String getWrongServerAddress() { // Avoiding the test error on camel-cxf module - try (AvailablePortFinder.Port p = AvailablePortFinder.find()) { - return "http://localhost:" + p.getPort() + "/" + getClass().getSimpleName() + "/test"; - } + wrongPort = AvailablePortFinder.find(); + return "http://localhost:" + wrongPort.getPort() + "/" + getClass().getSimpleName() + "/test"; } @BeforeEach
