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/09/18 05:43:01 UTC

svn commit: r816457 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/cxfbean/ test/java/org/apache/camel/component/cxf/cxfbean/ test/resources/ test/resources/org/apache/camel/component/cxf/cxfbean/

Author: ningjiang
Date: Fri Sep 18 03:43:00 2009
New Revision: 816457

URL: http://svn.apache.org/viewvc?rev=816457&view=rev
Log:
CAMEL-1989 applied patch with thanks to Seumas

Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/cxfbean/CxfBeanEndpoint.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfbean/CxfBeanTest-context.xml
    camel/trunk/components/camel-cxf/src/test/resources/person.wsdl

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/cxfbean/CxfBeanEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/cxfbean/CxfBeanEndpoint.java?rev=816457&r1=816456&r2=816457&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/cxfbean/CxfBeanEndpoint.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/cxfbean/CxfBeanEndpoint.java Fri Sep 18 03:43:00 2009
@@ -19,6 +19,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.jws.WebService;
+
 import org.apache.camel.component.cxf.CxfHeaderFilterStrategy;
 import org.apache.camel.impl.ProcessorEndpoint;
 import org.apache.camel.spi.HeaderFilterStrategy;
@@ -27,7 +29,9 @@
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.frontend.ServerFactoryBean;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
 import org.apache.cxf.transport.ConduitInitiatorManager;
 import org.apache.cxf.transport.DestinationFactoryManager;
 
@@ -78,9 +82,9 @@
             BusFactory.setDefaultBus(bus);
         }
         
-        registerTransportFactory((CxfBeanComponent)this.getComponent());
-        server = createServerFactoryBean(serviceBeans).create();
+        registerTransportFactory((CxfBeanComponent)this.getComponent());       
         
+        createServer(serviceBeans);
     }
     
     @Override
@@ -88,15 +92,26 @@
         return URI_PREFIX + ":" + getEndpointUri();
     }
     
-    private JAXRSServerFactoryBean createServerFactoryBean(List<Object> serviceBeans) {
-        JAXRSServerFactoryBean answer = new JAXRSServerFactoryBean();
-        answer.setServiceBeans(serviceBeans);
-        answer.setAddress("camel://" + createEndpointUri());
-        answer.setStart(true);
-        answer.setTransportId(CxfBeanTransportFactory.TRANSPORT_ID);
-        answer.setBus(bus);
-        return answer;
-        
+    private void createServer(List<Object> serviceBeans) {
+        Object obj = serviceBeans.get(0).getClass().getAnnotation(WebService.class);
+
+        if (obj != null) {
+            JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();
+            bean.setTransportId(CxfBeanTransportFactory.TRANSPORT_ID);
+            bean.setServiceClass(serviceBeans.get(0).getClass());
+            bean.setBus(bus);
+            bean.setStart(true);
+            bean.setAddress("camel://" + createEndpointUri());
+            server = bean.create();
+        } else {
+            JAXRSServerFactoryBean answer = new JAXRSServerFactoryBean();
+            answer.setServiceBeans(serviceBeans);
+            answer.setAddress("camel://" + createEndpointUri());
+            answer.setStart(true);
+            answer.setTransportId(CxfBeanTransportFactory.TRANSPORT_ID);
+            answer.setBus(bus);
+            server = answer.create();
+        }
     }
     
     /**

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java?rev=816457&r1=816456&r2=816457&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java Fri Sep 18 03:43:00 2009
@@ -19,9 +19,14 @@
 import java.io.InputStream;
 import java.net.URL;
 
+import javax.xml.namespace.QName;
+import javax.xml.ws.Holder;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.cxf.util.CxfUtils;
+import org.apache.camel.wsdl_first.Person;
+import org.apache.camel.wsdl_first.PersonService;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.PutMethod;
@@ -45,30 +50,6 @@
     private static final String PUT_REQUEST = "<Customer><name>Mary</name><id>113</id></Customer>";
     private static final String POST_REQUEST = "<Customer><name>Jack</name></Customer>";
     
-    @Autowired
-    protected CamelContext context;
-    
-    @Before
-    public void setUp() throws Exception {
-        RouteBuilder builder = createRouteBuilder();
-        context.addRoutes(builder);
-    }
-    
-    protected RouteBuilder createRouteBuilder() {
-        return new RouteBuilder() {
-
-            @Override
-            public void configure() throws Exception {
-                // START SNIPPET: routeDefinition
-                from("jetty:http://localhost:9000?matchOnUriPrefix=true").
-                        to("cxfbean:customerServiceBean");
-                // END SNIPPET: routeDefinition
-
-            }
-            
-        };
-    }   
-    
     @Test
     public void testGetConsumer() throws Exception {
         
@@ -136,4 +117,44 @@
 
     }
 
+    @Test
+    public void testJaxWsBean() throws Exception {        
+        PostMethod post = new PostMethod("http://localhost:9090/customerservice/customers");
+        post.addRequestHeader("Accept" , "text/xml");
+        String body = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+            + "<soap:Body><GetPerson xmlns=\"http://camel.apache.org/wsdl-first/types\">" 
+            + "<personId>hello</personId></GetPerson></soap:Body></soap:Envelope>";
+        
+        RequestEntity entity = new StringRequestEntity(body, "text/xml", "ISO-8859-1");
+        post.setRequestEntity(entity);
+        HttpClient httpclient = new HttpClient();
+
+        try {
+            assertEquals(200, httpclient.executeMethod(post));
+            String response = post.getResponseBodyAsString();
+            String correct = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>"
+                + "<GetPersonResponse xmlns=\"http://camel.apache.org/wsdl-first/types\">"
+                + "<personId>hello</personId><ssn>000-000-0000</ssn><name>Bonjour</name></GetPersonResponse></soap:Body></soap:Envelope>";
+            
+            assertEquals("Get a wrong response", correct, response);
+        } finally {
+            post.releaseConnection();
+        }
+    }
+    
+    @Test
+    public void testJaxWsBeanFromCxfRoute() throws Exception {
+        URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
+        PersonService ss = new PersonService(wsdlURL, new QName("http://camel.apache.org/wsdl-first", "PersonService"));
+        Person client = ss.getSoap();
+        Holder<String> personId = new Holder<String>();
+        personId.value = "hello";
+        Holder<String> ssn = new Holder<String>();
+        Holder<String> name = new Holder<String>();
+        client.getPerson(personId, ssn, name);
+        assertEquals("Get a wrong personId", "hello", personId.value);
+        assertEquals("Get a wrong SSN", "000-000-0000", ssn.value);
+        assertEquals("Get a wrong name", "Bonjour", name.value);
+    }
+
 }

Modified: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfbean/CxfBeanTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfbean/CxfBeanTest-context.xml?rev=816457&r1=816456&r2=816457&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfbean/CxfBeanTest-context.xml (original)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfbean/CxfBeanTest-context.xml Fri Sep 18 03:43:00 2009
@@ -17,21 +17,72 @@
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 	xmlns:cxf="http://camel.apache.org/schema/cxf"
 	xmlns:util="http://www.springframework.org/schema/util"
+	xmlns:camel="http://cxf.apache.org/transports/camel"
 	xsi:schemaLocation="
        http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://camel.apache.org/schema/spring  http://camel.apache.org/schema/spring/camel-spring.xsd
        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
+       http://cxf.apache.org/transports/camel http://cxf.apache.org/transports/camel.xsd
     ">
-    
-	<camelContext id="camelContext"
-		xmlns="http://camel.apache.org/schema/spring">
-	</camelContext>
+    <import resource="classpath:META-INF/cxf/cxf-extension-camel.xml" />
 	
 	<!-- START SNIPPET: beanDefinition -->
 	<util:list id="customerServiceBean">
 		<bean class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService" />
 	</util:list>
-	<!-- END SNIPPET: beanDefinition -->
+	
+	<bean class="org.apache.camel.wsdl_first.PersonImpl" id="jaxwsBean" />
+	
+	<!-- END SNIPPET: beanDefinition -->	
+    
+	<cxf:cxfEndpoint id="routerEndpoint"
+		address="http://localhost:8092/PersonService/" serviceClass="org.apache.camel.wsdl_first.Person"
+		endpointName="person:soap" serviceName="person:PersonService" wsdlURL="person.wsdl"
+		xmlns:person="http://camel.apache.org/wsdl-first">
+	</cxf:cxfEndpoint>
+	
+	<cxf:cxfEndpoint id="serviceEndpoint"
+		address="camel://direct:camel.apache.org.wsdl-first.PersonService" serviceClass="org.apache.camel.wsdl_first.Person"
+		endpointName="person:soap3" serviceName="person:PersonService"
+		wsdlURL="person.wsdl"
+		xmlns:person="http://camel.apache.org/wsdl-first">
+	</cxf:cxfEndpoint>
+
+    <!-- setup our error handler as the deal letter channel -->
+    <bean id="errorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
+        <property name="deadLetterUri" value="mock:error"/>
+        <property name="redeliveryPolicy" ref="myRedeliveryPolicy"/>
+        <property name="handled" value="false"/>
+    </bean>
+
+    <bean id="myRedeliveryPolicy" class="org.apache.camel.processor.RedeliveryPolicy">
+        <property name="maximumRedeliveries" value="5"/>
+        <property name="redeliverDelay" value="0"/>
+    </bean>
+
+	<camelContext errorHandlerRef="errorHandler" id="camel" xmlns="http://camel.apache.org/schema/spring">
+		<route>
+			<from uri="cxf:bean:routerEndpoint?dataFormat=PAYLOAD" />
+			<to uri="cxf:bean:serviceEndpoint?dataFormat=PAYLOAD" />
+		</route>
+		<route>
+			<from uri="jetty:http://localhost:9000?matchOnUriPrefix=true" />
+			<to uri="cxfbean:customerServiceBean" />
+		</route>
+		<route>
+			<from uri="jetty:http://localhost:9090?matchOnUriPrefix=true" />
+			<to uri="cxfbean:jaxwsBean" />
+		</route>				
+	</camelContext>
+	
+	  <camel:conduit name="{http://camel.apache.org/wsdl-first}soap3.camel-conduit">
+       <camelContext id="PersonServiceClientContext" xmlns="http://camel.apache.org/schema/spring">
+           <route>
+               <from uri="direct:camel.apache.org.wsdl-first.PersonService"/>
+               <to uri="cxfbean:jaxwsBean"/>
+          </route>
+      </camelContext>
+  </camel:conduit>
 	
 </beans>
\ No newline at end of file

Modified: camel/trunk/components/camel-cxf/src/test/resources/person.wsdl
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/person.wsdl?rev=816457&r1=816456&r2=816457&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/person.wsdl (original)
+++ camel/trunk/components/camel-cxf/src/test/resources/person.wsdl Fri Sep 18 03:43:00 2009
@@ -98,6 +98,21 @@
 			</wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>
+   
+       <wsdl:binding name="PersonSOAPBinding2" type="tns:Person">
+    	<soap:binding style="document" transport="http://cxf.apache.org/transports/camel" />
+		<wsdl:operation name="GetPerson">
+			<wsdl:input>
+				<soap:body use="literal" />
+			</wsdl:input>
+			<wsdl:output>
+				<soap:body use="literal" />
+			</wsdl:output>
+			<wsdl:fault name="UnknownPerson">
+				<soap:fault use="literal" name="UnknownPerson" />
+			</wsdl:fault>
+       </wsdl:operation>
+   </wsdl:binding>
 
 	<wsdl:service name="PersonService">
     	<wsdl:port binding="tns:PersonSOAPBinding" name="soap">
@@ -106,6 +121,9 @@
        <wsdl:port binding="tns:PersonSOAPBinding" name="soap2">
            <soap:address location="http://localhost:8093/PersonService/" />
        </wsdl:port>
+       <wsdl:port binding="tns:PersonSOAPBinding2" name="soap3">
+       <soap:address location="camel://direct:camel.apache.org.wsdl-first.PersonService"/>
+       </wsdl:port>
    </wsdl:service>
 
 </wsdl:definitions>