Author: ningjiang
Date: Fri Feb  3 14:01:43 2012
New Revision: 1240179

URL: http://svn.apache.org/viewvc?rev=1240179&view=rev
Log:
Merged revisions 1240157 via svnmerge from 
https://svn.apache.org/repos/asf/camel/branches/camel-2.9.x

................
  r1240157 | ningjiang | 2012-02-03 21:33:36 +0800 (Fri, 03 Feb 2012) | 9 lines
  
  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.8.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
      - copied unchanged from r1240157, 
camel/branches/camel-2.9.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
    
camel/branches/camel-2.8.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java
      - copied unchanged from r1240157, 
camel/branches/camel-2.9.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java
Modified:
    camel/branches/camel-2.8.x/   (props changed)
    
camel/branches/camel-2.8.x/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
    
camel/branches/camel-2.8.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Feb  3 14:01:43 2012
@@ -1,2 +1,2 @@
-/camel/branches/camel-2.9.x:1227549,1228229,1229567,1234054,1236672,1238942
-/camel/trunk:1226860,1227540,1228223,1229565,1234043,1236667,1238937
+/camel/branches/camel-2.9.x:1227549,1228229,1229567,1234054,1236672,1238942,1240157
+/camel/trunk:1226860,1227540,1228223,1229565,1234043,1236667,1238937,1240025

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

Modified: 
camel/branches/camel-2.8.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.8.x/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java?rev=1240179&r1=1240178&r2=1240179&view=diff
==============================================================================
--- 
camel/branches/camel-2.8.x/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
 (original)
+++ 
camel/branches/camel-2.8.x/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
 Fri Feb  3 14:01:43 2012
@@ -1,129 +1,151 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.cxf.common.header;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.spi.HeaderFilterStrategy;
-import org.apache.cxf.endpoint.Client;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.message.Message;
-
-/**
- * Utility class to propagate headers to and from CXF message.
- *
- * @version 
- */
-public final class CxfHeaderHelper {
-
-    /**
-     * Utility class does not have public constructor
-     */
-    private CxfHeaderHelper() {
-    }
-
-    /**
-     * Propagates Camel headers to CXF message.
-     *
-     * @param strategy header filter strategy
-     * @param headers Camel header
-     * @param message CXF message
-     * @param exchange provides context for filtering
-     */
-    public static void propagateCamelToCxf(HeaderFilterStrategy strategy,
-            Map<String, Object> headers, Message message, Exchange exchange) {
-
-        Map<String, List<String>> cxfHeaders =
-            CastUtils.cast((Map)message.get(Message.PROTOCOL_HEADERS));
-
-        if (cxfHeaders == null) {
-            // use a treemap to keep ordering and ignore key case
-            cxfHeaders = new TreeMap<String, 
List<String>>(String.CASE_INSENSITIVE_ORDER);
-            message.put(Message.PROTOCOL_HEADERS, cxfHeaders);
-        }
-
-        for (Map.Entry<String, Object> entry : headers.entrySet()) {
-            if (strategy != null
-                    && !strategy.applyFilterToCamelHeaders(entry.getKey(), 
entry.getValue(), exchange)) {
-
-                if (Exchange.CONTENT_TYPE.equals(entry.getKey())) {
-                    message.put(Message.CONTENT_TYPE, entry.getValue());
-                } else if (Client.REQUEST_CONTEXT.equals(entry.getKey())
-                            || Client.RESPONSE_CONTEXT.equals(entry.getKey())
-                            || Message.RESPONSE_CODE.equals(entry.getKey())) {
-                    message.put(entry.getKey(), entry.getValue());
-                } else {
-                    List<String> listValue = new ArrayList<String>();
-                    listValue.add(entry.getValue().toString());
-                    cxfHeaders.put(entry.getKey(), listValue);
-                }
-            }
-        }
-    }
-
-    public static void propagateCxfToCamel(HeaderFilterStrategy strategy,
-            Message message, Map<String, Object> headers, Exchange exchange) {
-
-        if (strategy == null) {
-            return;
-        }
-
-        // Copy the CXF protocol headers to the camel headers
-        Map<String, List<String>> cxfHeaders =
-            CastUtils.cast((Map)message.get(Message.PROTOCOL_HEADERS));
-        if (cxfHeaders != null) {
-            for (Map.Entry<String, List<String>> entry : 
cxfHeaders.entrySet()) {
-                if (!strategy.applyFilterToExternalHeaders(entry.getKey(), 
entry.getValue(), exchange)) {
-                    headers.put(entry.getKey(), entry.getValue().get(0));
-                }
-            }
-        }
-
-        // propagate content type
-        String key = Message.CONTENT_TYPE;
-        Object value = message.get(key);
-        if (value != null && !strategy.applyFilterToExternalHeaders(key, 
value, exchange)) {
-            headers.put(Exchange.CONTENT_TYPE, value);
-        }
-
-        // propagate request context
-        key = Client.REQUEST_CONTEXT;
-        value = message.get(key);
-        if (value != null && !strategy.applyFilterToExternalHeaders(key, 
value, exchange)) {
-            headers.put(key, value);
-        }
-
-        // propagate response context
-        key = Client.RESPONSE_CONTEXT;
-        value = message.get(key);
-        if (value != null && !strategy.applyFilterToExternalHeaders(key, 
value, exchange)) {
-            headers.put(key, value);
-        }
-        
-        // propagate response code
-        key = Message.RESPONSE_CODE;
-        value = message.get(key);
-        if (value != null && !strategy.applyFilterToExternalHeaders(key, 
value, exchange)) {
-            headers.put(Exchange.HTTP_RESPONSE_CODE, value);
-        }
-    }
-
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cxf.common.header;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.message.Message;
+
+/**
+ * Utility class to propagate headers to and from CXF message.
+ *
+ * @version 
+ */
+public final class CxfHeaderHelper {
+
+    /**
+     * Utility class does not have public constructor
+     */
+    private CxfHeaderHelper() {
+    }
+
+    /**
+     * Propagates Camel headers to CXF message.
+     *
+     * @param strategy header filter strategy
+     * @param headers Camel header
+     * @param message CXF message
+     * @param exchange provides context for filtering
+     */
+    public static void propagateCamelToCxf(HeaderFilterStrategy strategy,
+            Map<String, Object> headers, Message message, Exchange exchange) {
+
+        Map<String, List<String>> cxfHeaders =
+            CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
+
+        if (cxfHeaders == null) {
+            // use a treemap to keep ordering and ignore key case
+            cxfHeaders = new TreeMap<String, 
List<String>>(String.CASE_INSENSITIVE_ORDER);
+            message.put(Message.PROTOCOL_HEADERS, cxfHeaders);
+        }
+
+        for (Map.Entry<String, Object> entry : headers.entrySet()) {
+            if (strategy != null
+                    && !strategy.applyFilterToCamelHeaders(entry.getKey(), 
entry.getValue(), exchange)) {
+
+                if (Exchange.CONTENT_TYPE.equals(entry.getKey())) {
+                    message.put(Message.CONTENT_TYPE, entry.getValue());
+                } else if (Client.REQUEST_CONTEXT.equals(entry.getKey())
+                            || Client.RESPONSE_CONTEXT.equals(entry.getKey())
+                            || Message.RESPONSE_CODE.equals(entry.getKey())) {
+                    message.put(entry.getKey(), entry.getValue());
+                } else {
+                    List<String> listValue = new ArrayList<String>();
+                    listValue.add(entry.getValue().toString());
+                    cxfHeaders.put(entry.getKey(), listValue);
+                }
+            }
+        }
+    }
+
+    public static void propagateCxfToCamel(HeaderFilterStrategy strategy,
+            Message message, Map<String, Object> headers, Exchange exchange) {
+
+        if (strategy == null) {
+            return;
+        }
+
+        // Copy the CXF protocol headers to the camel headers
+        Map<String, List<String>> cxfHeaders =
+            CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
+        if (cxfHeaders != null) {
+            for (Map.Entry<String, List<String>> entry : 
cxfHeaders.entrySet()) {
+                if (!strategy.applyFilterToExternalHeaders(entry.getKey(), 
entry.getValue(), exchange)) {
+                    headers.put(entry.getKey(), entry.getValue().get(0));
+                }
+            }
+        }
+
+        // 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 = determineContentType(message);
+        
+        if (value != null && !strategy.applyFilterToExternalHeaders(key, 
value, exchange)) {
+            headers.put(Exchange.CONTENT_TYPE, value);
+        }
+
+        // propagate request context
+        key = Client.REQUEST_CONTEXT;
+        value = message.get(key);
+        if (value != null && !strategy.applyFilterToExternalHeaders(key, 
value, exchange)) {
+            headers.put(key, value);
+        }
+
+        // propagate response context
+        key = Client.RESPONSE_CONTEXT;
+        value = message.get(key);
+        if (value != null && !strategy.applyFilterToExternalHeaders(key, 
value, exchange)) {
+            headers.put(key, value);
+        }
+        
+        // propagate response code
+        key = Message.RESPONSE_CODE;
+        value = message.get(key);
+        if (value != null && !strategy.applyFilterToExternalHeaders(key, 
value, exchange)) {
+            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.8.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.8.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java?rev=1240179&r1=1240178&r2=1240179&view=diff
==============================================================================
--- 
camel/branches/camel-2.8.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java
 (original)
+++ 
camel/branches/camel-2.8.x/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java
 Fri Feb  3 14:01:43 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"));
+    }
 }


Reply via email to