camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-6971 Supprts to set the Providers and SchemaLocation in CXFRsEndpoint
Date Mon, 18 Nov 2013 04:28:49 GMT
Updated Branches:
  refs/heads/master 2deddc3f3 -> 8a080c97b


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/8a080c97
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8a080c97
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8a080c97

Branch: refs/heads/master
Commit: 8a080c97bc9412f68ddf3629ee3cf5e34649b322
Parents: 2deddc3
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Mon Nov 18 12:28:20 2013 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Mon Nov 18 12:28:20 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/8a080c97/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/8a080c97/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());
+    }
 
 }


Mime
View raw message