camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1240157 - in /camel/branches/camel-2.9.x: ./ components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/ components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/
Date Fri, 03 Feb 2012 13:33:36 GMT
Author: ningjiang
Date: Fri Feb  3 13:33:36 2012
New Revision: 1240157

URL: http://svn.apache.org/viewvc?rev=1240157&view=rev
Log:
Merged revisions 1240025 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1240025 | ningjiang | 2012-02-03 16:16:26 +0800 (Fri, 03 Feb 2012) | 1 line
  
  CAMEL-4973 Camel CXF Transport should update the content-type as other CXF transport does
........

Added:
    camel/branches/camel-2.9.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
      - copied unchanged from r1240025, camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
    camel/branches/camel-2.9.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java
      - copied unchanged from r1240025, camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java
Modified:
    camel/branches/camel-2.9.x/   (props changed)
    camel/branches/camel-2.9.x/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
    camel/branches/camel-2.9.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Feb  3 13:33:36 2012
@@ -1 +1 @@
-/camel/trunk:1235643,1236639,1236667,1237666,1237807,1238225,1238229,1238387,1238463,1238477,1238503,1238937,1238988,1239006,1239045,1239080-1239081,1239470,1239479,1239497,1240063
+/camel/trunk:1235643,1236639,1236667,1237666,1237807,1238225,1238229,1238387,1238463,1238477,1238503,1238937,1238988,1239006,1239045,1239080-1239081,1239470,1239479,1239497,1240025,1240063

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.9.x/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java?rev=1240157&r1=1240156&r2=1240157&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
Fri Feb  3 13:33:36 2012
@@ -97,9 +97,11 @@ public final class CxfHeaderHelper {
             }
         }
 
-        // propagate content type
+        // propagate content type with the encoding information
+        // We need to do it as the CXF does this kind of thing in transport level
         String key = Message.CONTENT_TYPE;
-        Object value = message.get(key);
+        Object value = determineContentType(message);
+        
         if (value != null && !strategy.applyFilterToExternalHeaders(key, value, exchange))
{
             headers.put(Exchange.CONTENT_TYPE, value);
         }
@@ -125,5 +127,25 @@ public final class CxfHeaderHelper {
             headers.put(Exchange.HTTP_RESPONSE_CODE, value);
         }
     }
+    
+    private static String determineContentType(Message message) {
+        String ct  = (String)message.get(Message.CONTENT_TYPE);
+        String enc = (String)message.get(Message.ENCODING);
+
+        if (null != ct) {
+            if (enc != null 
+                && ct.indexOf("charset=") == -1
+                && !ct.toLowerCase().contains("multipart/related")) {
+                ct = ct + "; charset=" + enc;
+            }
+        } else if (enc != null) {
+            ct = "text/xml; charset=" + enc;
+        } else {
+            ct = "text/xml";
+        }
+        // update the content_type value in the message
+        message.put(Message.CONTENT_TYPE, ct);
+        return ct;
+    }
 
 }

Modified: camel/branches/camel-2.9.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java?rev=1240157&r1=1240156&r2=1240157&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java
Fri Feb  3 13:33:36 2012
@@ -16,68 +16,16 @@
  */
 package org.apache.camel.component.cxf.transport;
 
-
-import javax.jws.WebMethod;
-import javax.jws.WebResult;
-import javax.jws.WebService;
-import javax.xml.namespace.QName;
-import javax.xml.ws.Service;
-
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.cxf.BusFactory;
-import org.junit.Before;
 import org.junit.Test;
-
 import static org.hamcrest.CoreMatchers.is;
+
 /**
  * Test CXF-CamelConduit when the destination is not a pipeline
  */
-public class JaxWSCamelConduitTest extends CamelTestSupport {
-    
-    /**
-     * Expected SOAP answer for the 'SampleWS.getSomething' method
-     */
-    public static final String ANSWER = "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>"
-                                        + "<Body>" + "<getSomethingResponse xmlns='urn:test'>"
-                                        + "<result>Something</result>" + "</getSomethingResponse>"
-                                        + "</Body>" + "</Envelope>";
-
-    /**
-     * Sample WebService
-     */
-    @WebService(targetNamespace = "urn:test", serviceName = "testService", portName = "testPort")
-    public interface SampleWS {
-
-        @WebMethod
-        @WebResult(name = "result", targetNamespace = "urn:test")
-        String getSomething();
-    }
-
-    /**
-     * Initialize CamelTransportFactory without Spring
-     */
-    @Before
-    public void setUpCXFCamelContext() {
-        BusFactory.getThreadDefaultBus().getExtension(CamelTransportFactory.class).setCamelContext(context);
-    }
-
-    /**
-     * Create a SampleWS JAXWS-Proxy to a specified route
-     * 
-     * @param camelRoute
-     * @return
-     */
-    public SampleWS getSampleWS(String camelRoute) {
-        QName serviceName = new QName("urn:test", "testService");
-        Service s = Service.create(serviceName);
-
-        QName portName = new QName("urn:test", "testPort");
-        s.addPort(portName, "http://schemas.xmlsoap.org/soap/", "camel://" + camelRoute);
-
-        return s.getPort(SampleWS.class);
-    }
-
+public class JaxWSCamelConduitTest extends JaxWSCamelTestSupport {
     
 
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -88,6 +36,15 @@ public class JaxWSCamelConduitTest exten
                 from("direct:start1").setBody(constant(ANSWER));
 
                 from("direct:start2").setBody(constant(ANSWER)).log("Force pipeline creation");
+                
+                from("direct:start3").choice().when(header(Exchange.CONTENT_TYPE).isEqualTo("text/xml;
charset=UTF-8")).process(new Processor() {
+                    public void process(final Exchange exchange) {
+                        exchange.getOut().setBody(ANSWER);
+                    }
+                });
+                // otherwise you will get the request message back
+                    
+                
             }
         };
     }
@@ -105,4 +62,10 @@ public class JaxWSCamelConduitTest exten
     public void testStart2() {
         assertThat(getSampleWS("direct:start2").getSomething(), is("Something"));
     }
+    
+    // test the content type
+    @Test
+    public void testStart3() {
+        assertThat(getSampleWS("direct:start3").getSomething(), is("Something"));
+    }
 }



Mime
View raw message