Author: ningjiang
Date: Wed Jun 13 15:20:35 2012
New Revision: 1349901

URL: http://svn.apache.org/viewvc?rev=1349901&view=rev
Log:
CAMEL-5365 Added SOAPMessage to InputStream coverter

Added:
    
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/SoapMessageProviderStreamContext.xml
Modified:
    
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
    
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/SoapTargetBean.java

Modified: 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java?rev=1349901&r1=1349900&r2=1349901&view=diff
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
 (original)
+++ 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
 Wed Jun 13 15:20:35 2012
@@ -28,6 +28,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.FallbackConverter;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.component.cxf.DataFormat;
+import org.apache.camel.converter.stream.CachedOutputStream;
 import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.cxf.message.MessageContentsList;
 import org.slf4j.Logger;
@@ -89,6 +90,19 @@ public final class CxfConverter {
     }
     
     @Converter
+    public static InputStream soapMessageToInputStream(final SOAPMessage 
soapMessage, Exchange exchange) {
+        CachedOutputStream cos = new CachedOutputStream(exchange);
+        InputStream in = null;
+        try {
+            soapMessage.writeTo(cos);
+            in = cos.getInputStream();
+        } catch (Exception e) {
+            LOG.error("Get the exception when converting the SOAPMessage into 
InputStream, the exception is " + e);
+        }
+        return in;
+    }
+    
+    @Converter
     public static DataFormat toDataFormat(final String name) {
         return DataFormat.valueOf(name.toUpperCase());
     }

Modified: 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/SoapTargetBean.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/SoapTargetBean.java?rev=1349901&r1=1349900&r2=1349901&view=diff
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/SoapTargetBean.java
 (original)
+++ 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/SoapTargetBean.java
 Wed Jun 13 15:20:35 2012
@@ -23,11 +23,14 @@ import javax.xml.soap.MessageFactory;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPMessage;
 
+import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
+import org.apache.cxf.helpers.XMLUtils;
+
 public class SoapTargetBean {
-    private static QName sayHi = new 
QName("http://apache.org/hello_world_soap_http";, "sayHi");
-    private static QName greetMe = new 
QName("http://apache.org/hello_world_soap_http";, "greetMe");
+    private static QName sayHi = new 
QName("http://apache.org/hello_world_soap_http/types";, "sayHi");
+    private static QName greetMe = new 
QName("http://apache.org/hello_world_soap_http/types";, "greetMe");
     private SOAPMessage sayHiResponse;
     private SOAPMessage greetMeResponse;
 
@@ -76,4 +79,21 @@ public class SoapTargetBean {
         return response;
     }
 
+    //Simulates a stream based processor or producer (e.g., file EP)
+    public SOAPMessage invokeStream(InputStream in) {
+        SOAPMessage response = null;
+        try {
+            Document doc = XMLUtils.parse(in);
+            if (doc.getElementsByTagNameNS(greetMe.getNamespaceURI(), 
+                                           sayHi.getLocalPart()).getLength() 
== 1) {
+                response = sayHiResponse;
+            } else if (doc.getElementsByTagNameNS(greetMe.getNamespaceURI(), 
+                                                  
greetMe.getLocalPart()).getLength() == 1) {
+                response = greetMeResponse;
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return response;
+    }
 }

Added: 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/SoapMessageProviderStreamContext.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/SoapMessageProviderStreamContext.xml?rev=1349901&view=auto
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/SoapMessageProviderStreamContext.xml
 (added)
+++ 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/SoapMessageProviderStreamContext.xml
 Wed Jun 13 15:20:35 2012
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:cxf="http://camel.apache.org/schema/cxf";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans
+       http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/cxf 
http://camel.apache.org/schema/cxf/camel-cxf.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+    <bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+    <!--
+    If you want to run this example in Tomcat container which need to used 
servlet transoprt,
+    please repalce the cxf-extension-http-jetty.xml with cxf-servlet.xml
+    -->
+
+    <import resource="classpath:META-INF/cxf/cxf.xml"/>
+
+    <bean id = "targetBean" 
class="org.apache.camel.component.cxf.SoapTargetBean" />
+
+       <cxf:cxfEndpoint id="soapMessageEndpoint"
+               
serviceClass="org.apache.camel.component.cxf.SoapMessageProvider"
+               
address="http://localhost:${CXFTestSupport.port1}/CxfSoapMessageProviderTest/SoapContext/SoapProviderPort";>
+       </cxf:cxfEndpoint>
+
+
+   <camelContext id="test_context" 
xmlns="http://camel.apache.org/schema/spring";>
+       <route>
+            <from uri="cxf:bean:soapMessageEndpoint"/>
+            <to uri="bean:targetBean?method=invokeStream"/>
+        </route>
+   </camelContext>
+
+</beans>


Reply via email to