Updated Branches:
  refs/heads/camel-2.11.x 0d5420706 -> 8e294be90
  refs/heads/camel-2.12.x 0ae2eb9b0 -> 3d1a87efe


CAMEL-6971 Supprts to set the Providers and SchemaLocation in CXFRsEndpoint


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3d1a87ef
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3d1a87ef
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3d1a87ef

Branch: refs/heads/camel-2.12.x
Commit: 3d1a87efe5317c374f1cd7d854b5de47d70bf9b8
Parents: 0ae2eb9
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Mon Nov 18 12:28:20 2013 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Mon Nov 18 12:30:15 2013 +0800

----------------------------------------------------------------------
 .../component/cxf/jaxrs/CxfRsEndpoint.java      | 44 ++++++++++++++++++++
 .../component/cxf/jaxrs/CxfRsEndpointTest.java  | 22 ++++++++++
 2 files changed, 66 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3d1a87ef/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
index 18191cd..4e736fd 100644
--- 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
+++ 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
@@ -18,7 +18,9 @@ package org.apache.camel.component.cxf.jaxrs;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -65,6 +67,10 @@ public class CxfRsEndpoint extends DefaultEndpoint 
implements HeaderFilterStrate
     private static final Logger LOG = 
LoggerFactory.getLogger(CxfRsEndpoint.class);
 
     protected Bus bus;
+    
+    protected List<Object> entityProviders = new LinkedList<Object>();
+    
+    protected List<String> schemaLocations;
 
     private Map<String, String> parameters;
     private List<Class<?>> resourceClasses;
@@ -82,6 +88,8 @@ public class CxfRsEndpoint extends DefaultEndpoint implements 
HeaderFilterStrate
     private AtomicBoolean getBusHasBeenCalled = new AtomicBoolean(false);
 
     private boolean isSetDefaultBus;
+    
+   
 
     @Deprecated
     public CxfRsEndpoint(String endpointUri, CamelContext camelContext) {
@@ -230,8 +238,16 @@ public class CxfRsEndpoint extends DefaultEndpoint 
implements HeaderFilterStrate
 
 
     public JAXRSServerFactoryBean createJAXRSServerFactoryBean() {
+        
         JAXRSServerFactoryBean answer = newJAXRSServerFactoryBean();
         setupJAXRSServerFactoryBean(answer);
+        // let customer to override the default setting of provider
+        if (!getProviders().isEmpty()) {
+            answer.setProviders(getProviders());
+        }
+        if (schemaLocations != null) {
+            answer.setSchemaLocations(schemaLocations);
+        }
         if (isLoggingFeatureEnabled()) {
             if (getLoggingSizeLimit() > 0) {
                 answer.getFeatures().add(new 
LoggingFeature(getLoggingSizeLimit()));
@@ -254,8 +270,16 @@ public class CxfRsEndpoint extends DefaultEndpoint 
implements HeaderFilterStrate
     }
     
     public JAXRSClientFactoryBean createJAXRSClientFactoryBean(String address) 
{
+        
         JAXRSClientFactoryBean answer = newJAXRSClientFactoryBean();
         setupJAXRSClientFactoryBean(answer, address);
+        // let customer to override the default setting of provider
+        if (!getProviders().isEmpty()) {
+            answer.setProviders(getProviders());
+        }
+        if (schemaLocations != null) {
+            answer.setSchemaLocations(schemaLocations);
+        }
         if (isLoggingFeatureEnabled()) {
             if (getLoggingSizeLimit() > 0) {
                 answer.getFeatures().add(new 
LoggingFeature(getLoggingSizeLimit()));
@@ -364,6 +388,26 @@ public class CxfRsEndpoint extends DefaultEndpoint 
implements HeaderFilterStrate
     public BindingStyle getBindingStyle() {
         return bindingStyle;
     }
+    
+    public List<?> getProviders() {
+        return entityProviders;
+    }
+    
+    public void setProviders(List<? extends Object> providers) {
+        this.entityProviders.addAll(providers);
+    }
+    
+    public void setProvider(Object provider) {
+        entityProviders.add(provider);
+    }
+    
+    public void setSchemaLocation(String schema) {
+        setSchemaLocations(Collections.singletonList(schema));    
+    }
+    
+    public void setSchemaLocations(List<String> schemas) {
+        this.schemaLocations = schemas;    
+    }
 
     /**
      * See documentation of {@link BindingStyle}.

http://git-wip-us.apache.org/repos/asf/camel/blob/3d1a87ef/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointTest.java
 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointTest.java
index a2aef10..5156c77 100644
--- 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointTest.java
+++ 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointTest.java
@@ -19,6 +19,9 @@ package org.apache.camel.component.cxf.jaxrs;
 import org.apache.camel.component.cxf.CXFTestSupport;
 import org.apache.camel.component.cxf.jaxrs.testbean.CustomerService;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.apache.cxf.jaxrs.provider.json.JSONProvider;
 import org.junit.Test;
 
 public class CxfRsEndpointTest extends CamelTestSupport {
@@ -68,5 +71,24 @@ public class CxfRsEndpointTest extends CamelTestSupport {
         assertEquals("Get a wrong size of resouces classes", 1, 
endpoint.getResourceClasses().size());
         assertEquals("Get a wrong resources class", CustomerService.class, 
endpoint.getResourceClasses().get(0));
     }
+    
+    @Test
+    public void testCxfRsEndpointSetProvider() throws Exception {
+
+        String endpointUri = "cxfrs://http://localhost:"; + CTX + ""
+                             + 
"?resourceClass=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
+
+        CxfRsComponent component = new CxfRsComponent(context);
+        CxfRsEndpoint endpoint = 
(CxfRsEndpoint)component.createEndpoint(endpointUri);
+        @SuppressWarnings("rawtypes")
+        JSONProvider jsonProvider = new JSONProvider();
+        jsonProvider.setDropRootElement(true);
+        jsonProvider.setSupportUnwrapped(true);
+        endpoint.setProvider(jsonProvider);
+        JAXRSServerFactoryBean sfb = endpoint.createJAXRSServerFactoryBean();
+        assertEquals("Get a wrong proider size", 1, sfb.getProviders().size());
+        JAXRSClientFactoryBean cfb = endpoint.createJAXRSClientFactoryBean();
+        assertEquals("Get a wrong proider size", 1, cfb.getProviders().size());
+    }
 
 }

Reply via email to