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

davsclaus pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new 1270b0281810 CAMEL-24573: CXF REST: UnsupportedOperationException when 
copying factory bean, backport to camel-4.18.x
1270b0281810 is described below

commit 1270b02818109a06705d549fda78f0fd91519969
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Aug 31 19:57:32 2026 +0200

    CAMEL-24573: CXF REST: UnsupportedOperationException when copying factory 
bean, backport to camel-4.18.x
    
    Backports #25967 to camel-4.18.x. Same fix as #25969: wraps the 
shallow-copied
    features field in a new ArrayList in 
CxfRsSpringEndpoint.newInstanceWithCommonProperties()
    so a fixed-size source list (e.g. Arrays.asList()) doesn't cause
    UnsupportedOperationException on a later append.
    
    Not a straight cherry-pick: this branch's camel-cxf-spring-rest test module
    depends on camel-test-spring-junit5, not junit6, so the test's import was
    kept as-is. More substantially, 
CxfRsSpringEndpoint.setupJAXRSClientFactoryBean()
    on this branch never calls setupCommonFactoryProperties() (that call was
    added later by CAMEL-24183, not present here), so the endpoint's own 
features
    are never auto-appended to the copied list. The ported test is adapted to
    assert the copied feature is preserved and that the list is mutable by
    appending directly, rather than relying on auto-append behaviour this branch
    doesn't have.
    
    Co-authored-by: Claude Haiku 4.5 <[email protected]>
    Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
    
    Closes #25970
---
 .../cxf/spring/jaxrs/CxfRsSpringEndpoint.java      |  3 +++
 .../cxf/jaxrs/CxfRsSpringEndpointTest.java         | 29 ++++++++++++++++++++++
 2 files changed, 32 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 3697f7816e05..d513f4dd22e5 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;
@@ -88,6 +90,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 077ed721036f..4275465597c6 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,18 +16,21 @@
  */
 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.junit5.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;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNotSame;
@@ -36,6 +39,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 +92,19 @@ 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(1, cfb.getFeatures().size(), "The copied feature must be 
preserved");
+        assertDoesNotThrow(() -> cfb.getFeatures().add(new AbstractFeature() {
+        }), "The copied features list must be mutable");
+        assertEquals(2, cfb.getFeatures().size(), "The appended feature must 
be present");
+    }
+
     public static SpringJAXRSClientFactoryBean serviceEndpoint() {
 
         SpringJAXRSClientFactoryBean clientFactoryBean = new 
SpringJAXRSClientFactoryBean();
@@ -99,6 +116,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 +139,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());
     }
 }

Reply via email to