camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1302484 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
Date Mon, 19 Mar 2012 14:52:18 GMT
Author: ningjiang
Date: Mon Mar 19 14:52:17 2012
New Revision: 1302484

URL: http://svn.apache.org/viewvc?rev=1302484&view=rev
Log:
CAMEL-5107 cxfrs producer should retain the message headers when it gets the reponse

Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java?rev=1302484&r1=1302483&r2=1302484&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
Mon Mar 19 14:52:17 2012
@@ -181,8 +181,9 @@ public class CxfRsProducer extends Defau
         // set response
         if (exchange.getPattern().isOutCapable()) {
             LOG.trace("Response body = {}", response);
+            exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
             exchange.getOut().setBody(binding.bindResponseToCamelBody(response, exchange));
-            exchange.getOut().setHeaders(binding.bindResponseHeadersToCamelHeaders(response,
exchange));
+            exchange.getOut().getHeaders().putAll(binding.bindResponseHeadersToCamelHeaders(response,
exchange));
             exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, statesCode);
         }
     }
@@ -230,8 +231,9 @@ public class CxfRsProducer extends Defau
         
         if (exchange.getPattern().isOutCapable()) {
             LOG.trace("Response body = {}", response);
+            exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
             exchange.getOut().setBody(binding.bindResponseToCamelBody(response, exchange));
-            exchange.getOut().setHeaders(binding.bindResponseHeadersToCamelHeaders(response,
exchange));
+            exchange.getOut().getHeaders().putAll(binding.bindResponseHeadersToCamelHeaders(response,
exchange));
             exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, statesCode);
         }
     }

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java?rev=1302484&r1=1302483&r2=1302484&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
(original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
Mon Mar 19 14:52:17 2012
@@ -80,6 +80,8 @@ public class CxfRsProducerTest extends C
                 inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomer");
                 // using the proxy client API
                 inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE);
+                // set a customer header
+                inMessage.setHeader("key", "value");
                 // set the parameters , if you just have one parameter 
                 // camel will put this object into an Object[] itself
                 inMessage.setBody("123");
@@ -93,6 +95,8 @@ public class CxfRsProducerTest extends C
         assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
         assertEquals("Get a wrong customer name", response.getName(), "John");
         assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
+        System.out.println(exchange.getOut().getHeaders());
+        assertEquals("Get a wrong header value", "value", exchange.getOut().getHeader("key"));
         // END SNIPPET: ProxyExample     
     }
     
@@ -138,6 +142,8 @@ public class CxfRsProducerTest extends C
                 inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
               
                 // Specify the response class , cxfrs will use InputStream as the response
object type 
                 inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
+                // set a customer header
+                inMessage.setHeader("key", "value");
                 // since we use the Get method, so we don't need to set the message body
                 inMessage.setBody(null);                
             }
@@ -150,6 +156,7 @@ public class CxfRsProducerTest extends C
         assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
         assertEquals("Get a wrong customer name", response.getName(), "John");
         assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
+        assertEquals("Get a wrong header value", "value", exchange.getOut().getHeader("key"));
         // END SNIPPET: HttpExample 
     }
     



Mime
View raw message