You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/03/21 04:36:41 UTC

svn commit: r756870 - in /camel/trunk/components/camel-cxf: pom.xml src/test/java/org/apache/camel/component/cxf/CxfMtomConsumerTest.java src/test/java/org/apache/camel/component/cxf/HelloImpl.java src/test/resources/java.jpg src/test/resources/mtom.wsdl

Author: ningjiang
Date: Sat Mar 21 03:36:40 2009
New Revision: 756870

URL: http://svn.apache.org/viewvc?rev=756870&view=rev
Log:
Added a mtom unit test into camel-cxf module

Added:
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMtomConsumerTest.java   (with props)
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloImpl.java   (with props)
    camel/trunk/components/camel-cxf/src/test/resources/java.jpg   (with props)
    camel/trunk/components/camel-cxf/src/test/resources/mtom.wsdl   (with props)
Modified:
    camel/trunk/components/camel-cxf/pom.xml

Modified: camel/trunk/components/camel-cxf/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/pom.xml?rev=756870&r1=756869&r2=756870&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/pom.xml (original)
+++ camel/trunk/components/camel-cxf/pom.xml Sat Mar 21 03:36:40 2009
@@ -312,11 +312,11 @@
       			<configuration>
       				<sourceRoot>${basedir}/target/generated</sourceRoot>
       				<wsdlOptions>
+      				    <wsdlOption>
+      						<wsdl>${basedir}/src/test/resources/mtom.wsdl</wsdl>      						
+      					</wsdlOption>
       					<wsdlOption>
-      						<wsdl>${basedir}/src/test/resources/person.wsdl</wsdl>
-      						<extraargs>
-      							<extraarg>-verbose</extraarg>
-      						</extraargs>
+      						<wsdl>${basedir}/src/test/resources/person.wsdl</wsdl>      						
       					</wsdlOption>
       					<wsdlOption>
       						<wsdl>${basedir}/src/test/resources/person-non-wrapper.wsdl</wsdl>

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMtomConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMtomConsumerTest.java?rev=756870&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMtomConsumerTest.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMtomConsumerTest.java Sat Mar 21 03:36:40 2009
@@ -0,0 +1,110 @@
+/**
+ * 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;
+
+import java.awt.Image;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.util.List;
+
+import javax.imageio.ImageIO;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Holder;
+import javax.xml.ws.soap.SOAPBinding;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.cxf.mtom_feature.Hello;
+import org.apache.camel.cxf.mtom_feature.HelloService;
+import org.apache.cxf.BusFactory;
+
+
+public class CxfMtomConsumerTest extends ContextTestSupport {
+    protected static final String MTOM_ENDPOINT_ADDRESS = "http://localhost:9090/jaxws-mtom/hello";
+    protected static final String MTOM_ENDPOINT_URI = "cxf://" + MTOM_ENDPOINT_ADDRESS
+        + "?serviceClass=org.apache.camel.component.cxf.HelloImpl";        
+
+    private final QName serviceName = new QName("http://apache.org/camel/cxf/mtom_feature", "HelloService");
+    
+
+    protected RouteBuilder createRouteBuilder() {      
+        
+        return new RouteBuilder() {
+            public void configure() {
+                from(MTOM_ENDPOINT_URI).process(new Processor() {
+                    @SuppressWarnings("unchecked")
+                    public void process(final Exchange exchange) throws Exception {
+                        Message in = exchange.getIn();
+                        // Get the parameter list
+                        List<?> parameter = in.getBody(List.class);
+                        // Get the operation name
+                        Holder<byte[]> photo = (Holder<byte[]>)parameter.get(0);
+                        assertNotNull("The photo should not be null", photo.value);
+                        assertEquals("Should get the right request", new String(photo.value, "UTF-8"),
+                                     "RequestFromCXF");
+                        photo.value = "ResponseFromCamel".getBytes("UTF-8");
+                        Holder<Image> image = (Holder<Image>)parameter.get(1);
+                        assertNotNull("We should get the image here", image.value);
+                        // set the holder message back    
+                        exchange.getOut().setBody(new Object[] {null, photo, image});
+
+                    }
+                });                
+            }
+        };
+    }
+    
+    private Hello getPort() {
+        URL wsdl = getClass().getResource("/mtom.wsdl");
+        assertNotNull("WSDL is null", wsdl);
+
+        HelloService service = new HelloService(wsdl, serviceName);
+        assertNotNull("Service is null ", service);
+        return service.getHelloPort();
+    }
+    
+    private Image getImage(String name) throws Exception {
+        return ImageIO.read(getClass().getResource(name));
+    }
+    
+    public void testInvokingServiceFromCXFClient() throws Exception {        
+
+        if (Boolean.getBoolean("java.awt.headless")) {
+            System.out.println("Running headless. Skipping test as Images may not work.");
+            return;
+        }        
+        
+        Holder<byte[]> photo = new Holder<byte[]>("RequestFromCXF".getBytes("UTF-8"));
+        Holder<Image> image = new Holder<Image>(getImage("/java.jpg"));
+
+        Hello port = getPort();
+
+        SOAPBinding binding = (SOAPBinding) ((BindingProvider)port).getBinding();
+        binding.setMTOMEnabled(true);
+
+        port.detail(photo, image);
+
+        assertEquals("ResponseFromCamel", new String(photo.value, "UTF-8"));
+        assertNotNull(image.value);        
+        
+    }
+
+}

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

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

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloImpl.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloImpl.java?rev=756870&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloImpl.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloImpl.java Sat Mar 21 03:36:40 2009
@@ -0,0 +1,35 @@
+/**
+ * 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;
+
+import java.awt.Image;
+import javax.xml.ws.BindingType;
+import javax.xml.ws.Holder;
+
+import org.apache.camel.cxf.mtom_feature.Hello;
+
+@BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING)
+public class HelloImpl implements Hello {
+    public void detail(Holder<byte[]> photo, Holder<Image> image) {
+        // echo through Holder
+    }
+      
+    public void echoData(Holder<byte[]> data) {
+        // echo through Holder
+    }
+}

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

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

Added: camel/trunk/components/camel-cxf/src/test/resources/java.jpg
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/java.jpg?rev=756870&view=auto
==============================================================================
Binary file - no diff available.

Propchange: camel/trunk/components/camel-cxf/src/test/resources/java.jpg
------------------------------------------------------------------------------
    svn:mime-type = image/jpeg

Added: camel/trunk/components/camel-cxf/src/test/resources/mtom.wsdl
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/mtom.wsdl?rev=756870&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/mtom.wsdl (added)
+++ camel/trunk/components/camel-cxf/src/test/resources/mtom.wsdl Sat Mar 21 03:36:40 2009
@@ -0,0 +1,105 @@
+<?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.
+-->
+<wsdl:definitions xmlns:types="http://apache.org/camel/cxf/mtom_feature/types" 
+		  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
+		  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
+		  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
+		  xmlns:tns="http://apache.org/camel/cxf/mtom_feature" 
+		  name="jaxws mtom feature"
+		  targetNamespace="http://apache.org/camel/cxf/mtom_feature">
+
+    <wsdl:types>
+	<schema xmlns="http://www.w3.org/2001/XMLSchema" 
+		xmlns:xmime="http://www.w3.org/2005/05/xmlmime" 
+		targetNamespace="http://apache.org/camel/cxf/mtom_feature/types"
+		elementFormDefault="qualified">
+	    <complexType name="DetailType">
+		<sequence>
+		    <element name="photo" type="base64Binary"></element>
+		    <element name="image" type="base64Binary" xmime:expectedContentTypes="image/jpeg"></element>
+		</sequence>
+	    </complexType>
+	    <element name="Detail" type="types:DetailType"></element>
+	    <element name="DetailResponse" type="types:DetailType"></element>
+	    <element name="data" type="base64Binary"></element>
+	</schema>
+    </wsdl:types>
+
+    <wsdl:message name="echoDataIn">
+	<wsdl:part name="data" element="types:data"></wsdl:part>
+    </wsdl:message>
+
+    <wsdl:message name="echoDataOut">
+	<wsdl:part name="data" element="types:data"></wsdl:part>
+    </wsdl:message>
+
+    <wsdl:message name="DetailIn">
+	<wsdl:part name="data" element="types:Detail"></wsdl:part>
+    </wsdl:message>
+
+    <wsdl:message name="DetailOut">
+	<wsdl:part name="data" element="types:DetailResponse"></wsdl:part>
+    </wsdl:message>
+
+    <wsdl:portType name="Hello">
+	<wsdl:operation name="echoData">
+	    <wsdl:input message="tns:echoDataIn"></wsdl:input>
+	    <wsdl:output message="tns:echoDataOut"></wsdl:output>
+	</wsdl:operation>
+
+	<wsdl:operation name="Detail">
+	    <wsdl:input message="tns:DetailIn"></wsdl:input>
+	    <wsdl:output message="tns:DetailOut"></wsdl:output>
+	</wsdl:operation>
+
+    </wsdl:portType>
+
+    <wsdl:binding name="HelloBinding" type="tns:Hello">
+	<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"></soap:binding>
+
+	<wsdl:operation name="echoData">
+	    <soap:operation soapAction=""></soap:operation>
+	    <wsdl:input>
+		<soap:body use="literal"></soap:body>
+	    </wsdl:input>
+	    <wsdl:output>
+		<soap:body use="literal"></soap:body>
+	    </wsdl:output>
+	</wsdl:operation>
+
+	<wsdl:operation name="Detail">
+	    <soap:operation soapAction=""></soap:operation>
+	    <wsdl:input>
+		<soap:body use="literal"></soap:body>
+	    </wsdl:input>
+	    <wsdl:output>
+		<soap:body use="literal"></soap:body>
+	    </wsdl:output>
+	</wsdl:operation>
+
+    </wsdl:binding>
+
+    <wsdl:service name="HelloService">
+	<wsdl:port name="HelloPort" binding="tns:HelloBinding">
+	    <soap:address location="http://localhost:9090/jaxws-mtom/hello"></soap:address>
+	</wsdl:port>
+    </wsdl:service>
+
+</wsdl:definitions>
\ No newline at end of file

Propchange: camel/trunk/components/camel-cxf/src/test/resources/mtom.wsdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/resources/mtom.wsdl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-cxf/src/test/resources/mtom.wsdl
------------------------------------------------------------------------------
    svn:mime-type = text/xml