camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-7207 CxfRsEndpoint should accept in/out interceptors and properties with thanks to Sergey
Date Tue, 18 Feb 2014 12:45:27 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.12.x fa07991fe -> 73c31fb98


CAMEL-7207 CxfRsEndpoint should accept in/out interceptors and properties with thanks to Sergey


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

Branch: refs/heads/camel-2.12.x
Commit: 73c31fb98041b41817738ee3a6eed6bad464eae6
Parents: fa07991
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Tue Feb 18 20:40:51 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Tue Feb 18 20:45:05 2014 +0800

----------------------------------------------------------------------
 .../component/cxf/jaxrs/CxfRsEndpoint.java      | 101 +++++++++++++++----
 .../cxf/jaxrs/CxfRsEndpointWithProperties.java  |  12 +++
 .../cxf/jaxrs/CxfRsSpringEndpointTest.java      |   9 ++
 .../cxf/jaxrs/CxfRsEndpointWithProperties.xml   |   3 +
 .../cxf/jaxrs/CxfRsSpringEndpointBeans-2.6.xml  |   3 +
 5 files changed, 109 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/73c31fb9/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 242c027..625643b 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
@@ -42,9 +42,13 @@ import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.util.ModCountCopyOnWriteArrayList;
 import org.apache.cxf.feature.Feature;
 import org.apache.cxf.feature.LoggingFeature;
+import org.apache.cxf.interceptor.AbstractBasicInterceptorProvider;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.logging.FaultListener;
+import org.apache.cxf.message.Message;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -92,7 +96,8 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     private boolean isSetDefaultBus;
     
     private List<Feature> features = new ModCountCopyOnWriteArrayList<Feature>();
-    
+    private InterceptorHolder interceptorHolder = new InterceptorHolder();
+    private Map<String, Object> properties;
    
 
     @Deprecated
@@ -192,16 +197,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
             }
             sfb.setResourceClasses(res);
         }
-        // let customer to override the default setting of provider
-        if (!getProviders().isEmpty()) {
-            sfb.setProviders(getProviders());
-        }
-        // setup the features
-        if (!getFeatures().isEmpty()) {
-            for (Feature feature : getFeatures()) {
-                sfb.getFeatures().add(feature);
-            }
-        }
+        setupCommonFactoryProperties(sfb);
         sfb.setStart(false);
     }
 
@@ -214,28 +210,48 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
             cfb.setResourceClass(getResourceClasses().get(0));
             cfb.getServiceFactory().setResourceClasses(getResourceClasses());
         }
+        setupCommonFactoryProperties(cfb);
+        cfb.setThreadSafe(true);
+    }
+    
+    protected void setupCommonFactoryProperties(AbstractJAXRSFactoryBean factory) {
         // let customer to override the default setting of provider
         if (!getProviders().isEmpty()) {
-            cfb.setProviders(getProviders());
+            factory.setProviders(getProviders());
         }
         // setup the features
         if (!getFeatures().isEmpty()) {
-            cfb.setFeatures(getFeatures());
+            factory.getFeatures().addAll(getFeatures());
         }
+        
+        factory.setInInterceptors(interceptorHolder.getInInterceptors());
+        factory.setOutInterceptors(interceptorHolder.getOutInterceptors());
+        factory.setOutFaultInterceptors(interceptorHolder.getOutFaultInterceptors());
+        factory.setInFaultInterceptors(interceptorHolder.getInFaultInterceptors()); 
+        
+        if (getProperties() != null) {
+            if (factory.getProperties() != null) {
+                // add to existing properties
+                factory.getProperties().putAll(getProperties());
+            } else {
+                factory.setProperties(getProperties());
+            }
+            LOG.debug("JAXRS FactoryBean: {} added properties: {}", factory, getProperties());
+        }
+        
         if (isLoggingFeatureEnabled()) {
             if (getLoggingSizeLimit() > 0) {
-                cfb.getFeatures().add(new LoggingFeature(getLoggingSizeLimit()));
+                factory.getFeatures().add(new LoggingFeature(getLoggingSizeLimit()));
             } else {
-                cfb.getFeatures().add(new LoggingFeature());
+                factory.getFeatures().add(new LoggingFeature());
             }
         }
         if (this.isSkipFaultLogging()) {
-            if (cfb.getProperties() == null) {
-                cfb.setProperties(new HashMap<String, Object>());
+            if (factory.getProperties() == null) {
+                factory.setProperties(new HashMap<String, Object>());
             }
-            cfb.getProperties().put(FaultListener.class.getName(), new NullFaultListener());
+            factory.getProperties().put(FaultListener.class.getName(), new NullFaultListener());
         }
-        cfb.setThreadSafe(true);
     }
     
     protected JAXRSServerFactoryBean newJAXRSServerFactoryBean() {
@@ -393,6 +409,38 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
         return schemaLocations;
     }
 
+    public List<Interceptor<? extends Message>> getOutFaultInterceptors() {
+        return interceptorHolder.getOutFaultInterceptors();
+    }
+
+    public List<Interceptor<? extends Message>> getInFaultInterceptors() {
+        return interceptorHolder.getInFaultInterceptors();
+    }
+
+    public List<Interceptor<? extends Message>> getInInterceptors() {
+        return interceptorHolder.getInInterceptors();
+    }
+
+    public List<Interceptor<? extends Message>> getOutInterceptors() {
+        return interceptorHolder.getOutInterceptors();
+    }
+
+    public void setInInterceptors(List<Interceptor<? extends Message>> interceptors)
{
+        interceptorHolder.setInInterceptors(interceptors);
+    }
+
+    public void setInFaultInterceptors(List<Interceptor<? extends Message>> interceptors)
{
+        interceptorHolder.setInFaultInterceptors(interceptors);
+    }
+
+    public void setOutInterceptors(List<Interceptor<? extends Message>> interceptors)
{
+        interceptorHolder.setOutInterceptors(interceptors);
+    }
+
+    public void setOutFaultInterceptors(List<Interceptor<? extends Message>>
interceptors) {
+        interceptorHolder.setOutFaultInterceptors(interceptors);
+    }
+    
     public List<Feature> getFeatures() {
         return features;
     }
@@ -401,6 +449,18 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
         this.features = features;
     }
 
+    public Map<String, Object> getProperties() {
+        return properties;
+    }
+    
+    public void setProperties(Map<String, Object> properties) {
+        if (this.properties == null) {
+            this.properties = properties;
+        } else {
+            this.properties.putAll(properties);
+        }
+    }
+    
     /**
      * See documentation of {@link BindingStyle}.
      */
@@ -426,4 +486,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
         // noop
     }
 
+
+    private static class InterceptorHolder extends AbstractBasicInterceptorProvider {
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/73c31fb9/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithProperties.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithProperties.java
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithProperties.java
index 9396e05..0aac3cf 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithProperties.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithProperties.java
@@ -16,8 +16,12 @@
  */
 package org.apache.camel.component.cxf.jaxrs;
 
+import java.util.List;
+import java.util.Map;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.cxf.spring.AbstractSpringBeanTestSupport;
+import org.apache.cxf.feature.Feature;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.DefaultHttpClient;
@@ -36,6 +40,14 @@ public class CxfRsEndpointWithProperties extends AbstractSpringBeanTestSupport
{
         CamelContext camelContext = ctx.getBean("camel", CamelContext.class);
         CxfRsEndpoint testEndpoint = camelContext.getEndpoint("cxfrs:bean:testEndpoint",
CxfRsEndpoint.class);
         assertEquals("Got a wrong address", "http://localhost:9900/testEndpoint", testEndpoint.getAddress());
+        
+        List<Feature> features = testEndpoint.getFeatures();
+        assertEquals("Single feature is expected", 1, features.size());
+        
+        Map<String, Object> endpointProps = testEndpoint.getProperties();
+        assertEquals("Single endpoint property is expected", 1, endpointProps.size());
+        assertEquals("Wrong property value", "aValue", endpointProps.get("aKey"));
+        
         HttpGet get = new HttpGet(testEndpoint.getAddress());
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpResponse response = httpclient.execute(get);

http://git-wip-us.apache.org/repos/asf/camel/blob/73c31fb9/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java
index 593630a..d80441e 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java
@@ -16,7 +16,10 @@
  */
 package org.apache.camel.component.cxf.jaxrs;
 
+import java.util.Map;
+
 import org.apache.camel.component.cxf.jaxrs.testbean.CustomerService;
+import org.apache.camel.component.cxf.spring.AbstractCxfBeanDefinitionParser;
 import org.apache.camel.component.cxf.spring.SpringJAXRSClientFactoryBean;
 import org.apache.camel.component.cxf.spring.SpringJAXRSServerFactoryBean;
 import org.apache.camel.test.spring.CamelSpringTestSupport;
@@ -32,6 +35,7 @@ public class CxfRsSpringEndpointTest extends CamelSpringTestSupport {
     public void testCreateCxfRsServerFactoryBean() {
         CxfRsEndpoint endpoint = resolveMandatoryEndpoint("cxfrs://bean://rsServer", CxfRsEndpoint.class);
         SpringJAXRSServerFactoryBean sfb = (SpringJAXRSServerFactoryBean)endpoint.createJAXRSServerFactoryBean();
+        
         assertEquals("Get a wrong provider size", 1, sfb.getProviders().size());
         assertEquals("Get a wrong beanId", sfb.getBeanId(), "rsServer");
         assertEquals("Get a wrong address", sfb.getAddress(), "http://localhost:9000/router");
@@ -39,6 +43,11 @@ public class CxfRsSpringEndpointTest extends CamelSpringTestSupport {
         assertEquals("Get a wrong resource class", sfb.getResourceClasses().get(0), CustomerService.class);
         assertEquals("Got the wrong loggingFeatureEnabled", true, sfb.isLoggingFeatureEnabled());
         assertEquals("Got the wrong loggingSizeLimit", 200, sfb.getLoggingSizeLimit());
+        
+        Map<String, Object> endpointProps = sfb.getProperties();
+        // The beanId key is put by the AbstractCxfBeanDefinitionParser, so the size is 2
+        assertEquals("Single endpoint property is expected", 2, endpointProps.size());
+        assertEquals("Wrong property value", "aValue", endpointProps.get("aKey"));
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/camel/blob/73c31fb9/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithProperties.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithProperties.xml
b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithProperties.xml
index 7c9d63c..a3755d2 100644
--- a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithProperties.xml
+++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithProperties.xml
@@ -28,6 +28,9 @@
   <cxf:rsServer id="testEndpoint" address="{{address}}"
     serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
     loggingFeatureEnabled="true" loggingSizeLimit="200">
+    <cxf:properties>
+        <entry key="aKey" value="aValue"/>
+    </cxf:properties>
   </cxf:rsServer>
  
   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">

http://git-wip-us.apache.org/repos/asf/camel/blob/73c31fb9/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointBeans-2.6.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointBeans-2.6.xml
b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointBeans-2.6.xml
index 6e4d6b2..1290c71 100644
--- a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointBeans-2.6.xml
+++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointBeans-2.6.xml
@@ -27,6 +27,9 @@
   <cxf:rsServer id="rsServer" address="http://localhost:9000/router"
     serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
     loggingFeatureEnabled="true" loggingSizeLimit="200">
+    <cxf:properties>
+        <entry key="aKey" value="aValue"/>
+    </cxf:properties>
     <cxf:providers>
        <ref bean="jsonProvider"/>
     </cxf:providers>


Mime
View raw message