This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch backport/CAMEL-24573-4.22.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit 62681f8f5541df58b4337dda55ec530242a412c9 Author: Marco Carletti <[email protected]> AuthorDate: Mon Aug 31 18:27:52 2026 +0200 CAMEL-24573: CXF REST: UnsupportedOperationException when copying factory bean with fixed-size features list When creating a CXF JAXRS client factory bean from a Spring bean with a fixed-size features list (e.g., from Arrays.asList()), the shallow field copy in CxfRsSpringEndpoint.newInstanceWithCommonProperties() resulted in a reference to the immutable list. A subsequent attempt to append endpoint features via addAll() in setupCommonFactoryProperties() then threw UnsupportedOperationException. Wrap the copied features list in a new ArrayList so the copy is mutable, while leaving the original Spring bean's list untouched. Adds testCreateCxfRsClientFactoryBeanWithFixedSizeFeatures to cover the fixed-size-list case. Co-authored-by: Claude Haiku 4.5 <[email protected]> Closes #25967 --- .../cxf/spring/jaxrs/CxfRsSpringEndpoint.java | 3 +++ .../cxf/jaxrs/CxfRsSpringEndpointTest.java | 25 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/components/camel-cxf/camel-cxf-spring-rest/src/main/java/org/apache/camel/component/cxf/spring/jaxrs/CxfRsSpringEndpoint.java b/components/camel-cxf/camel-cxf-spring-rest/src/main/java/org/apache/camel/component/cxf/spring/jaxrs/CxfRsSpringEndpoint.java index a2f564abff43..83ad90afb3de 100644 --- a/components/camel-cxf/camel-cxf-spring-rest/src/main/java/org/apache/camel/component/cxf/spring/jaxrs/CxfRsSpringEndpoint.java +++ b/components/camel-cxf/camel-cxf-spring-rest/src/main/java/org/apache/camel/component/cxf/spring/jaxrs/CxfRsSpringEndpoint.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.cxf.spring.jaxrs; +import java.util.ArrayList; + import org.apache.camel.Component; import org.apache.camel.component.cxf.jaxrs.BeanIdAware; import org.apache.camel.component.cxf.jaxrs.CxfRsEndpoint; @@ -110,6 +112,7 @@ public class CxfRsSpringEndpoint extends CxfRsEndpoint implements BeanIdAware { if (bean instanceof SpringJAXRSClientFactoryBean) { ReflectionUtils.shallowCopyFieldState(bean, cfb); + cfb.setFeatures(new ArrayList<>(cfb.getFeatures())); } return cfb; diff --git a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java index 9fc1d967786c..3bbefade6ada 100644 --- a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java +++ b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java @@ -16,12 +16,14 @@ */ package org.apache.camel.component.cxf.jaxrs; +import java.util.Arrays; import java.util.Map; import org.apache.camel.component.cxf.jaxrs.testbean.CustomerService; import org.apache.camel.component.cxf.spring.jaxrs.SpringJAXRSClientFactoryBean; import org.apache.camel.component.cxf.spring.jaxrs.SpringJAXRSServerFactoryBean; import org.apache.camel.test.spring.junit6.CamelSpringTestSupport; +import org.apache.cxf.feature.AbstractFeature; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -36,6 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class CxfRsSpringEndpointTest extends CamelSpringTestSupport { private static final String BEAN_SERVICE_ENDPOINT_NAME = "serviceEndpoint"; + private static final String FIXED_SIZE_FEATURES_ENDPOINT_NAME = "fixedSizeFeaturesEndpoint"; private static final String BEAN_SERVICE_ADDRESS = "http://localhost/programmatically"; private static final String BEAN_SERVICE_USERNAME = "BEAN_SERVICE_USERNAME"; private static final String BEAN_SERVICE_PASSWORD = "BEAN_SERVICE_PASSWORD"; @@ -88,6 +91,16 @@ public class CxfRsSpringEndpointTest extends CamelSpringTestSupport { assertEquals(BEAN_SERVICE_PASSWORD, cfb.getPassword(), "Got the wrong password"); } + @Test + public void testCreateCxfRsClientFactoryBeanWithFixedSizeFeatures() { + CxfRsEndpoint endpoint = resolveMandatoryEndpoint( + "cxfrs://bean://" + FIXED_SIZE_FEATURES_ENDPOINT_NAME, CxfRsEndpoint.class); + + SpringJAXRSClientFactoryBean cfb = (SpringJAXRSClientFactoryBean) endpoint.createJAXRSClientFactoryBean(); + + assertEquals(2, cfb.getFeatures().size(), "The endpoint features must be appended to the copied feature list"); + } + public static SpringJAXRSClientFactoryBean serviceEndpoint() { SpringJAXRSClientFactoryBean clientFactoryBean = new SpringJAXRSClientFactoryBean(); @@ -99,6 +112,13 @@ public class CxfRsSpringEndpointTest extends CamelSpringTestSupport { return clientFactoryBean; } + public static SpringJAXRSClientFactoryBean fixedSizeFeaturesEndpoint() { + SpringJAXRSClientFactoryBean clientFactoryBean = serviceEndpoint(); + clientFactoryBean.setFeatures(Arrays.asList(new AbstractFeature() { + })); + return clientFactoryBean; + } + @Override protected AbstractXmlApplicationContext createApplicationContext() { @@ -115,5 +135,10 @@ public class CxfRsSpringEndpointTest extends CamelSpringTestSupport { BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder .rootBeanDefinition(CxfRsSpringEndpointTest.class.getName()).setFactoryMethod("serviceEndpoint"); beanFactory.registerBeanDefinition(BEAN_SERVICE_ENDPOINT_NAME, definitionBuilder.getBeanDefinition()); + + BeanDefinitionBuilder fixedSizeFeaturesDefinitionBuilder = BeanDefinitionBuilder + .rootBeanDefinition(CxfRsSpringEndpointTest.class.getName()).setFactoryMethod("fixedSizeFeaturesEndpoint"); + beanFactory.registerBeanDefinition(FIXED_SIZE_FEATURES_ENDPOINT_NAME, + fixedSizeFeaturesDefinitionBuilder.getBeanDefinition()); } }
