camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1240025 - in /camel/trunk/components/camel-cxf-transport/src: main/java/org/apache/camel/component/cxf/common/header/ test/java/org/apache/camel/component/cxf/transport/
Date Fri, 03 Feb 2012 08:16:26 GMT
Author: ningjiang
Date: Fri Feb  3 08:16:26 2012
New Revision: 1240025

URL: http://svn.apache.org/viewvc?rev=1240025&view=rev
Log:
CAMEL-4973 Camel CXF Transport should update the content-type as other CXF transport does

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

Modified: camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java?rev=1240025&r1=1240024&r2=1240025&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
(original)
+++ camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
Fri Feb  3 08:16:26 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/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java?rev=1240025&r1=1240024&r2=1240025&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java
(original)
+++ camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java
Fri Feb  3 08:16:26 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"));
+    }
 }

Added: camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java?rev=1240025&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
(added)
+++ camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
Fri Feb  3 08:16:26 2012
@@ -0,0 +1,67 @@
+/**
+ * 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.transport;
+
+import javax.xml.ws.Endpoint;
+
+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.junit.After;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+
+// Test the CamelDestination with whole CXF context
+public class JaxWSCamelDestinationTest extends JaxWSCamelTestSupport {
+    private Endpoint endpoint;
+    
+    @After
+    public void stopEndpoint() {
+        if (endpoint != null) {
+            endpoint.stop();
+        }
+    }
+    
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+
+            public void configure() throws Exception {
+
+                from("direct:start").to("direct:endpoint");
+                
+            }
+        };
+    }
+    @Test
+    public void testDestinationContentType() {
+        // publish the endpoint
+        endpoint = publishSampleWS("direct:endpoint");
+        Exchange exchange = template.request("direct:start", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(REQUEST);
+            }
+            
+        });
+        assertThat(exchange.getOut().getHeader(Exchange.CONTENT_TYPE, String.class), is("text/xml;
charset=UTF-8"));
+        assertTrue(exchange.getOut().getBody(String.class).indexOf("something!") > 0);
+    }
+
+}

Propchange: camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java
(from r1239623, camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java?p2=camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java&p1=camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java&r1=1239623&r2=1240025&rev=1240025&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelConduitTest.java
(original)
+++ camel/trunk/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java
Fri Feb  3 08:16:26 2012
@@ -16,25 +16,18 @@
  */
 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.Endpoint;
 import javax.xml.ws.Service;
 
-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 {
-    
+public class JaxWSCamelTestSupport extends CamelTestSupport {
     /**
      * Expected SOAP answer for the 'SampleWS.getSomething' method
      */
@@ -42,6 +35,10 @@ public class JaxWSCamelConduitTest exten
                                         + "<Body>" + "<getSomethingResponse xmlns='urn:test'>"
                                         + "<result>Something</result>" + "</getSomethingResponse>"
                                         + "</Body>" + "</Envelope>";
+    
+    public static final String REQUEST = "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>"
+        + "<Body>" + "<getSomething xmlns='urn:test'/>"
+        + "</Body>" + "</Envelope>";
 
     /**
      * Sample WebService
@@ -53,6 +50,15 @@ public class JaxWSCamelConduitTest exten
         @WebResult(name = "result", targetNamespace = "urn:test")
         String getSomething();
     }
+    
+    public static class SampleWSImpl implements SampleWS {
+
+        @Override
+        public String getSomething() {
+            return "something!";
+        }
+        
+    }
 
     /**
      * Initialize CamelTransportFactory without Spring
@@ -65,44 +71,27 @@ public class JaxWSCamelConduitTest exten
     /**
      * Create a SampleWS JAXWS-Proxy to a specified route
      * 
-     * @param camelRoute
+     * @param camelEndpoint
      * @return
      */
-    public SampleWS getSampleWS(String camelRoute) {
+    public SampleWS getSampleWS(String camelEndpoint) {
         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);
+        s.addPort(portName, "http://schemas.xmlsoap.org/soap/", "camel://" + camelEndpoint);
 
         return s.getPort(SampleWS.class);
     }
-
     
-
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-
-            public void configure() throws Exception {
-
-                from("direct:start1").setBody(constant(ANSWER));
-
-                from("direct:start2").setBody(constant(ANSWER)).log("Force pipeline creation");
-            }
-        };
-    }
-
-   
-    @Test
-    public void testStart1() {
-        assertThat(getSampleWS("direct:start1").getSomething(), is("Something"));
-    }
-
     /**
-     * Success
+     * Create a SampleWS Server to a specified route
+     * @param camelEndpoint
      */
-    @Test
-    public void testStart2() {
-        assertThat(getSampleWS("direct:start2").getSomething(), is("Something"));
+    
+    public Endpoint publishSampleWS(String camelEndpoint) {
+        return Endpoint.publish("camel://" + camelEndpoint, new SampleWSImpl());
+        
     }
+
 }



Mime
View raw message