camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-7557 Fixed the issue that CxfRsProducer does not copy headers between Camel and CXF messages in a proxy mode
Date Fri, 04 Jul 2014 08:59:20 GMT
Repository: camel
Updated Branches:
  refs/heads/master c69feb066 -> c9a408b20


CAMEL-7557 Fixed the issue that CxfRsProducer does not copy headers between Camel and CXF
messages in a proxy mode


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

Branch: refs/heads/master
Commit: c9a408b2098a4513c3c0616addf28ce2448244a1
Parents: c69feb0
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Fri Jul 4 16:41:14 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Fri Jul 4 16:58:52 2014 +0800

----------------------------------------------------------------------
 .../component/cxf/jaxrs/CxfRsProducer.java      | 56 ++++++++++++--------
 .../component/cxf/jaxrs/CxfRsProducerTest.java  |  2 +
 .../component/cxf/jaxrs/CxfRsSpringProducer.xml |  3 +-
 3 files changed, 38 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c9a408b2/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 729417b..af5e0bd 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
@@ -90,8 +90,36 @@ public class CxfRsProducer extends DefaultProducer {
             invokeProxyClient(exchange);
         }
     }
-
+    
     @SuppressWarnings("unchecked")
+    protected void setupClientQueryAndHeaders(Client client, Exchange exchange) throws Exception
{
+        Message inMessage = exchange.getIn();
+        CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint();
+        // check if there is a query map in the message header
+        Map<String, String> maps = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_QUERY_MAP,
Map.class);
+        if (maps == null) {
+            // Get the map from HTTP_QUERY header
+            String queryString = inMessage.getHeader(Exchange.HTTP_QUERY, String.class);
+            if (queryString != null) {
+                maps = getQueryParametersFromQueryString(queryString,
+                                                         IOHelper.getCharsetName(exchange));
+            }
+        }
+        if (maps == null) {
+            maps = cxfRsEndpoint.getParameters();
+        }
+        if (maps != null) {
+            for (Map.Entry<String, String> entry : maps.entrySet()) {
+                client.query(entry.getKey(), entry.getValue());
+            }
+        }
+        
+        CxfRsBinding binding = cxfRsEndpoint.getBinding();
+        // set headers
+        client.headers(binding.bindCamelHeadersToRequestHeaders(inMessage.getHeaders(), exchange));
+        
+    }
+
     protected void invokeHttpClient(Exchange exchange) throws Exception {
         Message inMessage = exchange.getIn();
         JAXRSClientFactoryBean cfb = clientFactoryBeanCache.get(CxfEndpointUtils
@@ -119,24 +147,6 @@ public class CxfRsProducer extends DefaultProducer {
         }
 
         CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint();
-        // check if there is a query map in the message header
-        Map<String, String> maps = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_QUERY_MAP,
Map.class);
-        if (maps == null) {
-            // Get the map from HTTP_QUERY header
-            String queryString = inMessage.getHeader(Exchange.HTTP_QUERY, String.class);
-            if (queryString != null) {
-                maps = getQueryParametersFromQueryString(queryString,
-                                                         IOHelper.getCharsetName(exchange));
-            }
-        }
-        if (maps == null) {
-            maps = cxfRsEndpoint.getParameters();
-        }
-        if (maps != null) {
-            for (Map.Entry<String, String> entry : maps.entrySet()) {
-                client.query(entry.getKey(), entry.getValue());
-            }
-        }
 
         CxfRsBinding binding = cxfRsEndpoint.getBinding();
 
@@ -150,9 +160,8 @@ public class CxfRsProducer extends DefaultProducer {
             }
         }
 
-        // set headers
-        client.headers(binding.bindCamelHeadersToRequestHeaders(inMessage.getHeaders(), exchange));
-
+        setupClientQueryAndHeaders(client, exchange);
+        
         // invoke the client
         Object response = null;
         if (responseClass == null || Response.class.equals(responseClass)) {
@@ -210,6 +219,9 @@ public class CxfRsProducer extends DefaultProducer {
         } else {
             target = cfb.createWithValues(varValues);
         }
+        
+        setupClientQueryAndHeaders(target, exchange);
+        
         // find out the method which we want to invoke
         JAXRSServiceFactoryBean sfb = cfb.getServiceFactory();
         sfb.getResourceClasses();

http://git-wip-us.apache.org/repos/asf/camel/blob/c9a408b2/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
index 0eeb742..af255e9 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
@@ -88,6 +88,8 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
                 inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE);
                 // set a customer header
                 inMessage.setHeader("key", "value");
+                // setup the accept content type
+                inMessage.setHeader(Exchange.ACCEPT_CONTENT_TYPE, "application/json");
                 // set the parameters , if you just have one parameter 
                 // camel will put this object into an Object[] itself
                 inMessage.setBody("123");

http://git-wip-us.apache.org/repos/asf/camel/blob/c9a408b2/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducer.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducer.xml
b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducer.xml
index 6f8add8..34d073b 100644
--- a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducer.xml
+++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducer.xml
@@ -40,7 +40,8 @@
   <bean id="customerService" class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
/>
 
   <cxf:rsClient id="rsClientProxy" address="http://localhost:${CXFTestSupport.port1}/CxfRsProducerTest/"
-    serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"/>
+    serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
+    loggingFeatureEnabled="true" />
    
   <cxf:rsClient id="rsClientHttp" address="http://localhost:${CXFTestSupport.port1}/CxfRsProducerTest/"/>
 


Mime
View raw message