camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [6/9] git commit: CAMEL-7856 Added igoreDeleteMethodMessageBody option to CxfRsEndpoint
Date Fri, 26 Sep 2014 07:10:36 GMT
CAMEL-7856 Added igoreDeleteMethodMessageBody option to CxfRsEndpoint

Conflicts:
	components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java


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

Branch: refs/heads/camel-2.13.x
Commit: 3a5497afcb533f083cb726f57c0153b44e7f52ed
Parents: 55c5c4b
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Fri Sep 26 15:02:27 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Fri Sep 26 15:08:56 2014 +0800

----------------------------------------------------------------------
 .../component/cxf/jaxrs/CxfRsEndpoint.java      | 85 +++++++++++---------
 .../component/cxf/jaxrs/CxfRsProducer.java      | 17 ++--
 .../component/cxf/jaxrs/CxfRsSpringRouter.xml   |  7 +-
 3 files changed, 61 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3a5497af/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 d3e29c2..b4b63a1 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
@@ -51,7 +51,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrategyAware,
Service {
-    
+
     public enum BindingStyle {
         /**
          * <i>Only available for consumers.</i>
@@ -60,7 +60,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
          * It also also adds more flexibility and simplicity to the response mapping.
          */
         SimpleConsumer,
-        
+
         /**
          * This is the traditional binding style, which simply dumps the {@link org.apache.cxf.message.MessageContentsList}
coming in from the CXF stack
          * onto the IN message body. The user is then responsible for processing it according
to the contract defined by the JAX-RS method signature.
@@ -77,9 +77,9 @@ 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;
@@ -87,6 +87,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     private HeaderFilterStrategy headerFilterStrategy;
     private CxfRsBinding binding;
     private boolean httpClientAPI = true;
+    private boolean ignoreDeleteMethodMessageBody;
     private String address;
     private boolean throwExceptionOnFailure = true;
     private int maxClientCacheSize = 10;
@@ -94,13 +95,13 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     private int loggingSizeLimit;
     private boolean skipFaultLogging;
     private BindingStyle bindingStyle = BindingStyle.Default;
-   
+
     private boolean isSetDefaultBus;
-    
+
     private List<Feature> features = new ModCountCopyOnWriteArrayList<Feature>();
     private InterceptorHolder interceptorHolder = new InterceptorHolder();
     private Map<String, Object> properties;
-   
+
 
     @Deprecated
     public CxfRsEndpoint(String endpointUri, CamelContext camelContext) {
@@ -171,7 +172,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     public CxfRsBinding getBinding() {
         return binding;
     }
-    
+
     public boolean isSkipFaultLogging() {
         return skipFaultLogging;
     }
@@ -179,7 +180,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     public void setSkipFaultLogging(boolean skipFaultLogging) {
         this.skipFaultLogging = skipFaultLogging;
     }
-    
+
     protected void checkBeanType(Object object, Class<?> clazz) {
         if (!clazz.isAssignableFrom(object.getClass())) {
             throw new IllegalArgumentException("The configure bean is not the instance of
" + clazz.getName());
@@ -215,7 +216,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
         setupCommonFactoryProperties(cfb);
         cfb.setThreadSafe(true);
     }
-    
+
     protected void setupCommonFactoryProperties(AbstractJAXRSFactoryBean factory) {
         // let customer to override the default setting of provider
         if (!getProviders().isEmpty()) {
@@ -225,11 +226,11 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
         if (!getFeatures().isEmpty()) {
             factory.getFeatures().addAll(getFeatures());
         }
-        
+
         // we need to avoid flushing the setting from spring or blueprint
         if (!interceptorHolder.getInInterceptors().isEmpty()) {
             factory.setInInterceptors(interceptorHolder.getInInterceptors());
-        } 
+        }
         if (!interceptorHolder.getOutInterceptors().isEmpty()) {
             factory.setOutInterceptors(interceptorHolder.getOutInterceptors());
         }
@@ -237,9 +238,9 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
             factory.setOutFaultInterceptors(interceptorHolder.getOutFaultInterceptors());
         }
         if (!interceptorHolder.getInFaultInterceptors().isEmpty()) {
-            factory.setInFaultInterceptors(interceptorHolder.getInFaultInterceptors()); 
+            factory.setInFaultInterceptors(interceptorHolder.getInFaultInterceptors());
         }
-        
+
         if (getProperties() != null) {
             if (factory.getProperties() != null) {
                 // add to existing properties
@@ -249,7 +250,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
             }
             LOG.debug("JAXRS FactoryBean: {} added properties: {}", factory, getProperties());
         }
-        
+
         if (isLoggingFeatureEnabled()) {
             if (getLoggingSizeLimit() > 0) {
                 factory.getFeatures().add(new LoggingFeature(getLoggingSizeLimit()));
@@ -264,15 +265,15 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
             factory.getProperties().put(FaultListener.class.getName(), new NullFaultListener());
         }
     }
-    
+
     protected JAXRSServerFactoryBean newJAXRSServerFactoryBean() {
         return new JAXRSServerFactoryBean();
     }
-    
+
     protected JAXRSClientFactoryBean newJAXRSClientFactoryBean() {
         return new JAXRSClientFactoryBean();
     }
-    
+
     protected String resolvePropertyPlaceholders(String str) {
         try {
             if (getCamelContext() != null) {
@@ -291,12 +292,12 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
         setupJAXRSServerFactoryBean(answer);
         return answer;
     }
-    
+
 
     public JAXRSClientFactoryBean createJAXRSClientFactoryBean() {
         return createJAXRSClientFactoryBean(getAddress());
     }
-    
+
     public JAXRSClientFactoryBean createJAXRSClientFactoryBean(String address) {
         JAXRSClientFactoryBean answer = newJAXRSClientFactoryBean();
         setupJAXRSClientFactoryBean(answer, address);
@@ -320,7 +321,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     public void setResourceClasses(Class<?>... classes) {
         setResourceClasses(Arrays.asList(classes));
     }
-    
+
     public void setAddress(String address) {
         this.address = address;
     }
@@ -366,7 +367,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     public int getMaxClientCacheSize() {
         return maxClientCacheSize;
     }
-    
+
     public void setBus(Bus bus) {
         this.bus = bus;
         if (isSetDefaultBus) {
@@ -378,7 +379,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     public Bus getBus() {
         return bus;
     }
-    
+
     public void setSetDefaultBus(boolean isSetDefaultBus) {
         this.isSetDefaultBus = isSetDefaultBus;
     }
@@ -386,31 +387,39 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     public boolean isSetDefaultBus() {
         return isSetDefaultBus;
     }
-    
+
+    public boolean isIgnoreDeleteMethodMessageBody() {
+        return ignoreDeleteMethodMessageBody;
+    }
+
+    public void setIgnoreDELETEMethodMessageBody(boolean ignoreDELETEMethodMessageBody) {
+        this.ignoreDeleteMethodMessageBody = ignoreDELETEMethodMessageBody;
+    }
+
     public BindingStyle getBindingStyle() {
         return bindingStyle;
     }
-    
+
     public List<?> getProviders() {
         return entityProviders;
     }
-    
+
     public void setProviders(List<?> providers) {
         this.entityProviders.addAll(providers);
     }
-    
+
     public void setProvider(Object provider) {
         entityProviders.add(provider);
     }
-    
+
     public void setSchemaLocation(String schema) {
-        setSchemaLocations(Collections.singletonList(schema));    
+        setSchemaLocations(Collections.singletonList(schema));
     }
-    
+
     public void setSchemaLocations(List<String> schemas) {
-        this.schemaLocations = schemas;    
+        this.schemaLocations = schemas;
     }
-    
+
     public List<String> getSchemaLocations() {
         return schemaLocations;
     }
@@ -446,7 +455,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     public void setOutFaultInterceptors(List<Interceptor<? extends Message>>
interceptors) {
         interceptorHolder.setOutFaultInterceptors(interceptors);
     }
-    
+
     public List<Feature> getFeatures() {
         return features;
     }
@@ -458,7 +467,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     public Map<String, Object> getProperties() {
         return properties;
     }
-    
+
     public void setProperties(Map<String, Object> properties) {
         if (this.properties == null) {
             this.properties = properties;
@@ -466,14 +475,14 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
             this.properties.putAll(properties);
         }
     }
-    
+
     /**
      * See documentation of {@link BindingStyle}.
      */
     public void setBindingStyle(BindingStyle bindingStyle) {
         this.bindingStyle = bindingStyle;
     }
-    
+
     @Override
     protected void doStart() throws Exception {
         if (headerFilterStrategy == null) {
@@ -488,7 +497,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
         // if the user has set a binding, do nothing, just make sure that BindingStyle =
Custom for coherency purposes
         if (binding != null) {
             bindingStyle = BindingStyle.Custom;
-        } 
+        }
 
         // set the right binding based on the binding style
         if (bindingStyle == BindingStyle.SimpleConsumer) {
@@ -498,7 +507,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
         } else {
             binding = new DefaultCxfRsBinding();
         }
-        
+
         if (binding instanceof HeaderFilterStrategyAware) {
             ((HeaderFilterStrategyAware) binding).setHeaderFilterStrategy(getHeaderFilterStrategy());
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/3a5497af/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
index c580445..7129829 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
@@ -57,12 +57,15 @@ public class CxfRsProducer extends DefaultProducer {
 
     private boolean throwException;
     
+    private CxfRsEndpoint cxfRsEndpoint;
+    
     // using a cache of factory beans instead of setting the address of a single cfb
     // to avoid concurrent issues
     private ClientFactoryBeanCache clientFactoryBeanCache;
     
     public CxfRsProducer(CxfRsEndpoint endpoint) {
         super(endpoint);
+        cxfRsEndpoint = endpoint;
         this.throwException = endpoint.isThrowExceptionOnFailure();
         clientFactoryBeanCache = new ClientFactoryBeanCache(endpoint.getMaxClientCacheSize());
     }
@@ -158,11 +161,15 @@ public class CxfRsProducer extends DefaultProducer {
 
         // set the body
         Object body = null;
-        if (!"GET".equals(httpMethod) && !"DELETE".equals(httpMethod)) {
-            // need to check the request object if the http Method is not GET or DELETE 
         
-            body = binding.bindCamelMessageBodyToRequestBody(inMessage, exchange);
-            if (LOG.isTraceEnabled()) {
-                LOG.trace("Request body = " + body);
+        if (!"GET".equals(httpMethod)) {
+            // need to check the request object if the http Method is not GET      
+            if ("DELETE".equals(httpMethod) && cxfRsEndpoint.isIgnoreDeleteMethodMessageBody())
{
+                // just ignore the message body if the ignoreDeleteMethodMessageBody is true
+            } else {
+                body = binding.bindCamelMessageBodyToRequestBody(inMessage, exchange);
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Request body = " + body);
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/3a5497af/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRouter.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRouter.xml
b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRouter.xml
index 9f51dd6..172aac1 100644
--- a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRouter.xml
+++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRouter.xml
@@ -63,12 +63,9 @@
   <!-- The camel route context -->
   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
     <route>
-       <from uri="cxfrs://bean://rsServer"/>
+       <!-- Just need to ignoreDeleteMethodMessageBody -->
+       <from uri="cxfrs://bean://rsServer?ignoreDeleteMethodMessageBody=true"/>
        <to uri="log:body?level=INFO"/>
-       <!-- We can remove this configure as the CXFRS producer is using the HttpAPI by
default -->
-       <setHeader headerName="CamelCxfRsUsingHttpAPI">
-         <constant>True</constant>        
-       </setHeader>
        <to uri="cxfrs://bean://rsClient"/>
     </route>
   </camelContext>


Mime
View raw message