You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by reena upadhyay <re...@outlook.com> on 2013/12/13 14:06:03 UTC

How to call remote soap web service from a application using apache camel

Hi,

I have a  apache cxf soap service deployed on a web container tomcat.

The web service is is published on TOMCAT on URL:

http://localhost:8181/exemplar/Quote?wsdl

This wsdl has several web service operations exposed.
I want to call web service method findQuote(int quoteId) from a external application using apache camel.

Please guide me how to invoke a soap web service by passing request parameter and how to get the response in apache camel.

If anybody have a piece of code for this use case, then it would be of really very great help for me.

Thanks in advance.

 		 	   		  

Re: How to call remote soap web service from a application using apache camel

Posted by Christian Müller <ch...@gmail.com>.
Did you checked our examples page? http://camel.apache.org/examples.html
Check out the CXF examples...

Best,

Christian
-----------------

Software Integration Specialist

Apache Member
V.P. Apache Camel | Apache Camel PMC Member | Apache Camel committer
Apache Incubator PMC Member

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Sun, Dec 15, 2013 at 6:00 PM, reena upadhyay <re...@outlook.com>wrote:

> Can anybody guide me on this?
>
> > From: reena2485@outlook.com
> > To: users@camel.apache.org
> > Subject: How to call remote soap web service from a application using
> apache camel
> > Date: Fri, 13 Dec 2013 18:36:03 +0530
> >
> > Hi,
> >
> > I have a  apache cxf soap service deployed on a web container tomcat.
> >
> > The web service is is published on TOMCAT on URL:
> >
> > http://localhost:8181/exemplar/Quote?wsdl
> >
> > This wsdl has several web service operations exposed.
> > I want to call web service method findQuote(int quoteId) from a external
> application using apache camel.
> >
> > Please guide me how to invoke a soap web service by passing request
> parameter and how to get the response in apache camel.
> >
> > If anybody have a piece of code for this use case, then it would be of
> really very great help for me.
> >
> > Thanks in advance.
> >
> >
>
>

RE: How to call remote soap web service from a application using apache camel

Posted by reena upadhyay <re...@outlook.com>.
Can anybody guide me on this?

> From: reena2485@outlook.com
> To: users@camel.apache.org
> Subject: How to call remote soap web service from a application using apache camel
> Date: Fri, 13 Dec 2013 18:36:03 +0530
> 
> Hi,
> 
> I have a  apache cxf soap service deployed on a web container tomcat.
> 
> The web service is is published on TOMCAT on URL:
> 
> http://localhost:8181/exemplar/Quote?wsdl
> 
> This wsdl has several web service operations exposed.
> I want to call web service method findQuote(int quoteId) from a external application using apache camel.
> 
> Please guide me how to invoke a soap web service by passing request parameter and how to get the response in apache camel.
> 
> If anybody have a piece of code for this use case, then it would be of really very great help for me.
> 
> Thanks in advance.
> 
>  		 	   		  
 		 	   		  

RE: How to call remote soap web service from a application using apache camel

Posted by contactreji <co...@gmail.com>.
Why would you want to use a Code first approach when you are creating the
client program which consumes the service? U have the wsdl of the service.
So its easier to follow a wsdl first approach here.

Usually we follow code first approach when we create services. Not when we
consume services.
For code first approach, checkout jboss fuse example SOAP.



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-call-remote-soap-web-service-from-a-application-using-apache-camel-tp5744734p5744869.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: How to call remote soap web service from a application using apache camel

Posted by reena upadhyay <re...@outlook.com>.
Hi,
As I am beginner , want to know how did you executed this through test case?

> Date: Mon, 16 Dec 2013 09:48:31 -0800
> From: contactreji@gmail.com
> To: users@camel.apache.org
> Subject: RE: How to call remote soap web service from a application using apache camel
> 
> Reena.
> 
> I used Active MQ cos in my example, I am taking the input from an Active MQ
> queue. The use case takes an input string from queue like example
> "tom-cruise" .. The program separates 'tom' and 'cruise' as first name and
> last name and uses them to invoke the webservice which returns the Marks and
> Rank.
> 
> In your example, you may be having some other requirement. So customize the
> project according to your requirement.
> 
> Reji
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-call-remote-soap-web-service-from-a-application-using-apache-camel-tp5744734p5744871.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
 		 	   		  

RE: How to call remote soap web service from a application using apache camel

Posted by contactreji <co...@gmail.com>.
Reena.

I used Active MQ cos in my example, I am taking the input from an Active MQ
queue. The use case takes an input string from queue like example
"tom-cruise" .. The program separates 'tom' and 'cruise' as first name and
last name and uses them to invoke the webservice which returns the Marks and
Rank.

In your example, you may be having some other requirement. So customize the
project according to your requirement.

Reji



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-call-remote-soap-web-service-from-a-application-using-apache-camel-tp5744734p5744871.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: How to call remote soap web service from a application using apache camel

Posted by reena upadhyay <re...@outlook.com>.
One more question here I have:Why you have used ActiveMQ here? 


> From: reena2485@outlook.com
> To: users@camel.apache.org
> Subject: RE: How to call remote soap web service from a application using apache camel
> Date: Mon, 16 Dec 2013 23:06:24 +0530
> 
> Hi,
> Thanks much...But I want to follow the code first approach as the apache services that I have exposed on Tomcat server are written using code first approach. So any idea how to start?
> 
> > Date: Mon, 16 Dec 2013 05:19:50 -0800
> > From: contactreji@gmail.com
> > To: users@camel.apache.org
> > Subject: RE: How to call remote soap web service from a application using apache camel
> > 
> > Hi Reena
> > 
> > The Camel-xml route file is already included in the code. Anyways its as
> > follows
> > 
> > *
> > <?xml version="1.0" encoding="UTF-8"?> 
> > 
> > 
> > <beans xmlns="http://www.springframework.org/schema/beans"
> >         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xmlns:camel="http://camel.apache.org/schema/spring"
> >         xmlns:jaxws="http://cxf.apache.org/jaxws"
> > xmlns:cxf="http://camel.apache.org/schema/cxf"
> >         xmlns:osgi="http://www.springframework.org/schema/osgi"
> > xmlns:soap="http://cxf.apache.org/bindings/soap"
> >        
> > xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
> >         xmlns:http="http://cxf.apache.org/transports/http/configuration"
> >         xmlns:sec="http://cxf.apache.org/configuration/security"
> > xmlns:ctx="http://www.springframework.org/schema/context"
> > 
> >         xsi:schemaLocation=" 
> >        http://camel.apache.org/schema/cxf
> > http://camel.apache.org/schema/cxf/camel-cxf.xsd
> >        http://cxf.apache.org/bindings/soap
> > http://cxf.apache.org/schemas/configuration/soap.xsd
> >        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd  
> >          http://www.springframework.org/schema/beans  
> >          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
> >          http://camel.apache.org/schema/spring  
> >          http://camel.apache.org/schema/spring/camel-spring.xsd
> >          http://www.springframework.org/schema/osgi
> > http://www.springframework.org/schema/osgi/spring-osgi.xsd
> >          http://cxf.apache.org/bindings/soap
> > http://cxf.apache.org/schemas/configuration/soap.xsd
> >        http://www.springframework.org/schema/context
> > http://www.springframework.org/schema/context/spring-context.xsd
> >          http://cxf.apache.org/configuration/security
> > http://cxf.apache.org/schemas/configuration/security.xsd
> >     http://cxf.apache.org/transports/http/configuration
> > http://cxf.apache.org/schemas/configuration/http-conf.xsd">
> > 
> >         
> >         <bean id="activemq"
> > class="org.apache.activemq.camel.component.ActiveMQComponent">
> >                 <property name="brokerURL" value="tcp://localhost:61616" />
> >                 <property name="userName" value="admin" />
> >                 <property name="password" value="admin" />
> >         </bean>
> >         
> > 
> >         <camelContext xmlns="http://camel.apache.org/schema/spring">
> > 
> >                 
> >                 <route>
> >                         
> >                         <from uri="activemq:queue:input" />
> >                         <to uri="WebServiceClient"/>
> >                         <to uri="activemq:queue:responseXML" />
> >                         
> >                 </route>
> > 
> >                 
> >         </camelContext>
> >         
> >         
> >         
> >         <jaxws:client id="sapPiProxy" 
> >                
> > address="http://REJI-PC:8181/WebService.serviceagent/getResultEndpoint1"
> >                 serviceClass="com.example.xmlns._1386864564116.GetResult" 
> >                 />
> >         <bean id="WebServiceClient"
> > class="com.mycompany.camel.cxf.contract.first.ServiceClientInvoker" 
> >                 init-method="init" destroy-method="destroy">
> >                 <property name="myService" ref="sapPiProxy" />
> >         </bean>
> >         
> > 
> > </beans>*
> > 
> > 
> > 
> > 
> > --
> > View this message in context: http://camel.465427.n5.nabble.com/How-to-call-remote-soap-web-service-from-a-application-using-apache-camel-tp5744734p5744850.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>  		 	   		  
 		 	   		  

RE: How to call remote soap web service from a application using apache camel

Posted by reena upadhyay <re...@outlook.com>.
Hi,
Thanks much...But I want to follow the code first approach as the apache services that I have exposed on Tomcat server are written using code first approach. So any idea how to start?

> Date: Mon, 16 Dec 2013 05:19:50 -0800
> From: contactreji@gmail.com
> To: users@camel.apache.org
> Subject: RE: How to call remote soap web service from a application using apache camel
> 
> Hi Reena
> 
> The Camel-xml route file is already included in the code. Anyways its as
> follows
> 
> *
> <?xml version="1.0" encoding="UTF-8"?> 
> 
> 
> <beans xmlns="http://www.springframework.org/schema/beans"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:camel="http://camel.apache.org/schema/spring"
>         xmlns:jaxws="http://cxf.apache.org/jaxws"
> xmlns:cxf="http://camel.apache.org/schema/cxf"
>         xmlns:osgi="http://www.springframework.org/schema/osgi"
> xmlns:soap="http://cxf.apache.org/bindings/soap"
>        
> xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
>         xmlns:http="http://cxf.apache.org/transports/http/configuration"
>         xmlns:sec="http://cxf.apache.org/configuration/security"
> xmlns:ctx="http://www.springframework.org/schema/context"
> 
>         xsi:schemaLocation=" 
>        http://camel.apache.org/schema/cxf
> http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://cxf.apache.org/bindings/soap
> http://cxf.apache.org/schemas/configuration/soap.xsd
>        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd  
>          http://www.springframework.org/schema/beans  
>          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>          http://camel.apache.org/schema/spring  
>          http://camel.apache.org/schema/spring/camel-spring.xsd
>          http://www.springframework.org/schema/osgi
> http://www.springframework.org/schema/osgi/spring-osgi.xsd
>          http://cxf.apache.org/bindings/soap
> http://cxf.apache.org/schemas/configuration/soap.xsd
>        http://www.springframework.org/schema/context
> http://www.springframework.org/schema/context/spring-context.xsd
>          http://cxf.apache.org/configuration/security
> http://cxf.apache.org/schemas/configuration/security.xsd
>     http://cxf.apache.org/transports/http/configuration
> http://cxf.apache.org/schemas/configuration/http-conf.xsd">
> 
>         
>         <bean id="activemq"
> class="org.apache.activemq.camel.component.ActiveMQComponent">
>                 <property name="brokerURL" value="tcp://localhost:61616" />
>                 <property name="userName" value="admin" />
>                 <property name="password" value="admin" />
>         </bean>
>         
> 
>         <camelContext xmlns="http://camel.apache.org/schema/spring">
> 
>                 
>                 <route>
>                         
>                         <from uri="activemq:queue:input" />
>                         <to uri="WebServiceClient"/>
>                         <to uri="activemq:queue:responseXML" />
>                         
>                 </route>
> 
>                 
>         </camelContext>
>         
>         
>         
>         <jaxws:client id="sapPiProxy" 
>                
> address="http://REJI-PC:8181/WebService.serviceagent/getResultEndpoint1"
>                 serviceClass="com.example.xmlns._1386864564116.GetResult" 
>                 />
>         <bean id="WebServiceClient"
> class="com.mycompany.camel.cxf.contract.first.ServiceClientInvoker" 
>                 init-method="init" destroy-method="destroy">
>                 <property name="myService" ref="sapPiProxy" />
>         </bean>
>         
> 
> </beans>*
> 
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-call-remote-soap-web-service-from-a-application-using-apache-camel-tp5744734p5744850.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
 		 	   		  

RE: How to call remote soap web service from a application using apache camel

Posted by contactreji <co...@gmail.com>.
Hi Reena

The Camel-xml route file is already included in the code. Anyways its as
follows

*
<?xml version="1.0" encoding="UTF-8"?> 


<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
        xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://camel.apache.org/schema/cxf"
        xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:soap="http://cxf.apache.org/bindings/soap"
       
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
        xmlns:http="http://cxf.apache.org/transports/http/configuration"
        xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns:ctx="http://www.springframework.org/schema/context"

        xsi:schemaLocation=" 
       http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd
       http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
       http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd  
         http://www.springframework.org/schema/beans  
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://camel.apache.org/schema/spring  
         http://camel.apache.org/schema/spring/camel-spring.xsd
         http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
         http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
       http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
         http://cxf.apache.org/configuration/security
http://cxf.apache.org/schemas/configuration/security.xsd
    http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd">

        
        <bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
                <property name="brokerURL" value="tcp://localhost:61616" />
                <property name="userName" value="admin" />
                <property name="password" value="admin" />
        </bean>
        

        <camelContext xmlns="http://camel.apache.org/schema/spring">

                
                <route>
                        
                        <from uri="activemq:queue:input" />
                        <to uri="WebServiceClient"/>
                        <to uri="activemq:queue:responseXML" />
                        
                </route>

                
        </camelContext>
        
        
        
        <jaxws:client id="sapPiProxy" 
               
address="http://REJI-PC:8181/WebService.serviceagent/getResultEndpoint1"
                serviceClass="com.example.xmlns._1386864564116.GetResult" 
                />
        <bean id="WebServiceClient"
class="com.mycompany.camel.cxf.contract.first.ServiceClientInvoker" 
                init-method="init" destroy-method="destroy">
                <property name="myService" ref="sapPiProxy" />
        </bean>
        

</beans>*




--
View this message in context: http://camel.465427.n5.nabble.com/How-to-call-remote-soap-web-service-from-a-application-using-apache-camel-tp5744734p5744850.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: How to call remote soap web service from a application using apache camel

Posted by reena upadhyay <re...@outlook.com>.
Hi Sir,Can you please show me your camel-route.xml?
> Date: Sun, 15 Dec 2013 09:33:07 -0800
> From: contactreji@gmail.com
> To: users@camel.apache.org
> Subject: Re: How to call remote soap web service from a application using apache camel
> 
> Hi Reena
> 
> U need to use CXF component for doing the same. Here i am following the WSDL
> first approach. i.e I got the wsdl file from the service provider. The wsdl
> file which I got is as follows.
> *
> <?xml version="1.0" encoding="UTF-8"?>
> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
> xmlns:tns="http://xmlns.example.com/1386864564116"
> xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
> xmlns:ns0="http://inputMessage.data" xmlns:ns1="http://outputMessage.data"
> name="Untitled" targetNamespace="http://xmlns.example.com/1386864564116">
>     <wsdl:types>
>         <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="http://outputMessage.data"
> targetNamespace="http://outputMessage.data" elementFormDefault="qualified"
> attributeFormDefault="unqualified">
>             <xs:element name="RES">
>                 <xs:complexType>
>                     <xs:sequence>
>                         <xs:element name="RANK" type="xs:string"
> minOccurs="0"/>
>                         <xs:element name="MARKS" type="xs:string"
> minOccurs="0"/>
>                     </xs:sequence>
>                 </xs:complexType>
>             </xs:element>
>         </xs:schema>
>         <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="http://inputMessage.data" targetNamespace="http://inputMessage.data"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
>             <xs:element name="REQ">
>                 <xs:complexType>
>                     <xs:sequence>
>                         <xs:element name="FIRSTNAME" type="xs:string"
> minOccurs="0"/>
>                         <xs:element name="LASTNAME" type="xs:string"
> minOccurs="0"/>
>                     </xs:sequence>
>                 </xs:complexType>
>             </xs:element>
>         </xs:schema>
>     </wsdl:types>
>     <wsdl:service name="WebService">
>         <wsdl:port name="getResultEndpoint1"
> binding="tns:getResultEndpoint1Binding">
>             <soap:address
> location="http://REJI-PC:8181/WebService.serviceagent/getResultEndpoint1"/>
>         </wsdl:port>
>     </wsdl:service>
>     <wsdl:portType name="getResult">
>         <wsdl:operation name="getResultAndRank">
>             <wsdl:input message="tns:REQ_MESSAGE"/>
>             <wsdl:output message="tns:RES_MESSAGE"/>
>         </wsdl:operation>
>     </wsdl:portType>
>     <wsdl:binding name="getResultEndpoint1Binding" type="tns:getResult">
>         <soap:binding style="document"
> transport="http://schemas.xmlsoap.org/soap/http"/>
>         <wsdl:operation name="getResultAndRank">
>             <soap:operation style="document"
> soapAction="/WebService.serviceagent/getResultEndpoint1/getResultAndRank"/>
>             <wsdl:input>
>                 <soap:body use="literal" parts="part1"/>
>             </wsdl:input>
>             <wsdl:output>
>                 <soap:body use="literal" parts="part1"/>
>             </wsdl:output>
>         </wsdl:operation>
>     </wsdl:binding>
>     <wsdl:message name="REQ_MESSAGE">
>         <wsdl:part name="part1" element="ns0:REQ"/>
>     </wsdl:message>
>     <wsdl:message name="RES_MESSAGE">
>         <wsdl:part name="part1" element="ns1:RES"/>
>     </wsdl:message>
> </wsdl:definitions>
> *
> 
> 
> 
> Now I will come to the camel project. I have used a plugin  to generate the
> Java stubs and SEI for the web service invocation. Find a copy of my POM
> file and you can figure out the plugin which is used for generating the
> Stubs.
> 
> *<?xml version="1.0" encoding="UTF-8" standalone="no"?><project
> xmlns="http://maven.apache.org/POM/4.0.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd">
> 
>   <modelVersion>4.0.0</modelVersion>
> 
>   
> 
>   <version>1.0.0-SNAPSHOT</version>
>   <groupId>com.poc</groupId>
>   <artifactId>bw-client</artifactId>
>   <name>BWClient</name>
>   <description>Creates a web service using the WSDL contract
> first</description>
> 
>   <repositories>
>     <repository>
>       <id>fusesource</id>
>       <name>FuseSource Release Repository</name>
>       <url>http://repo.fusesource.com/nexus/content/groups/public/</url>
>       <snapshots>
>         <enabled>false</enabled>
>       </snapshots>
>       <releases>
>         <enabled>true</enabled>
>       </releases>
>     </repository>
>     <repository>
>         <id>fusesource.ea</id>
>         <name>FuseSource Community Early Access Release Repository</name>
>         <url>http://repo.fusesource.com/nexus/content/groups/ea</url>
>         <snapshots>
>             <enabled>false</enabled>
>         </snapshots>
>         <releases>
>             <enabled>true</enabled>
>         </releases>
>     </repository>
>     <repository>
>       <id>jboss-public-repository-group</id>
>       <name>JBoss Public Repository Group</name>
>       <url>http://repository.jboss.org/nexus/content/groups/public/</url>
>       <layout>default</layout>
>       <releases>
>         <enabled>true</enabled>
>         <updatePolicy>never</updatePolicy>
>       </releases>
>       <snapshots>
>         <enabled>true</enabled>
>         <updatePolicy>daily</updatePolicy>
>       </snapshots>
>     </repository>
>   </repositories>
> 
>   <pluginRepositories>
>     <pluginRepository>
>       <id>fusesource</id>
>       <name>FuseSource Release Repository</name>
>       <url>http://repo.fusesource.com/nexus/content/groups/public/</url>
>       <snapshots>
>         <enabled>false</enabled>
>       </snapshots>
>       <releases>
>         <enabled>true</enabled>
>       </releases>
>     </pluginRepository>
>     <pluginRepository>
>         <id>fusesource.ea</id>
>         <name>FuseSource Community Early Access Release Repository</name>
>         <url>http://repo.fusesource.com/nexus/content/groups/ea</url>
>         <snapshots>
>             <enabled>false</enabled>
>         </snapshots>
>         <releases>
>             <enabled>true</enabled>
>         </releases>
>     </pluginRepository>
>   </pluginRepositories>
> 
> 
>   <dependencies>
> 
> 	
> 		<dependency>
> 			<groupId>org.apache.camel</groupId>
> 			<artifactId>camel-core</artifactId>
> 			<version>2.10.0.fuse-71-047</version>
> 		</dependency>
> 
> 		<dependency>
> 			<groupId>org.apache.camel</groupId>
> 			<artifactId>camel-cxf</artifactId>
> 			<version>2.10.0.fuse-71-047</version>
> 		</dependency>
> 
> 		<dependency>
> 			<groupId>log4j</groupId>
> 			<artifactId>log4j</artifactId>
> 			<version>1.2.16</version>
> 		</dependency>
> 
> 		
> 		<dependency>
> 			<groupId>org.slf4j</groupId>
> 			<artifactId>slf4j-api</artifactId>
> 			<version>1.6.1</version>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.slf4j</groupId>
> 			<artifactId>slf4j-log4j12</artifactId>
> 			<version>1.6.1</version>
> 		</dependency>
> 
> 		
> 		<dependency>
> 			<groupId>org.apache.cxf</groupId>
> 			<artifactId>cxf-rt-transports-http-jetty</artifactId>
> 			<version>2.6.0.fuse-71-047</version>
> 		</dependency>
> 
> 		<dependency>
> 			<groupId>org.apache.camel</groupId>
> 			<artifactId>camel-test-spring</artifactId>
> 			<version>2.10.0.fuse-71-047</version>
> 			<scope>test</scope>
> 		</dependency>
> 
> 		<dependency>
> 			<groupId>junit</groupId>
> 			<artifactId>junit</artifactId>
> 			<version>4.10</version>
> 			<scope>test</scope>
> 		</dependency>
> 
> 
> 		
> 
> 
> 		<dependency>
> 			<groupId>commons-lang</groupId>
> 			<artifactId>commons-lang</artifactId>
> 			<version>2.6</version>
> 		</dependency>
> 
> 		<dependency>
> 			<groupId>org.apache.commons</groupId>
> 			<artifactId>commons-lang3</artifactId>
> 			<version>3.1</version>
> 		</dependency>
> 
> 		<dependency>
> 			<groupId>org.apache.camel</groupId>
> 			<artifactId>camel-mail</artifactId>
> 			<version>2.10.6</version>
> 		</dependency>
> 
> 		<dependency>
> 			<groupId>org.apache.servicemix.specs</groupId>
> 			<artifactId>org.apache.servicemix.specs.activation-api-1.1</artifactId>
> 			<version>2.1.0</version>
> 		</dependency>
> 
> 		<dependency>
> 			<groupId>javax.mail</groupId>
> 			<artifactId>mail</artifactId>
> 			<version>1.4</version>
> 		</dependency>
> 
> 
> 		<dependency>
> 			<groupId>org.apache.activemq</groupId>
> 			<artifactId>activemq-camel</artifactId>
> 			<version>5.8.0</version>
> 		</dependency>
> 
> 		<dependency>
> 			<groupId>org.apache.camel</groupId>
> 			<artifactId>camel-mail</artifactId>
> 			<version>2.10.0.fuse-71-047</version>
> 
> 		</dependency>
>   </dependencies>
> 
>   <build>
>     <plugins>
> 
>       <plugin>
>         <groupId>org.apache.cxf</groupId>
>         <artifactId>cxf-codegen-plugin</artifactId>
>         <version>2.6.0.redhat-60024</version>
>         <executions>
>           <execution>
>             <id>generate-sources</id>
>             <phase>generate-sources</phase>
>             <configuration>
>              
> <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
>               <wsdlOptions>
>                 <wsdlOption>
>                  
> <wsdl>${basedir}/src/main/resources/wsdl/MyResultService.wsdl</wsdl>
>                   <extraargs>
>                     <extraarg>-impl</extraarg>
>                   </extraargs>
>                 </wsdlOption>
>               </wsdlOptions>
>             </configuration>
>             <goals>
>               <goal>wsdl2java</goal>
>             </goals>
>           </execution>
>         </executions>
>       </plugin>
> 
>       <plugin>
>         <groupId>org.apache.maven.plugins</groupId>
>         <artifactId>maven-compiler-plugin</artifactId>
>         <version>2.3.2</version>
>         <configuration>
>           <source>1.6</source>
>           <target>1.6</target>
>         </configuration>
>       </plugin>
> 
>       <plugin>
>         <groupId>org.apache.maven.plugins</groupId>
>         <artifactId>maven-resources-plugin</artifactId>
>         <version>2.6</version>
>       </plugin>
> 
>       
>       <plugin>
>         <groupId>org.apache.camel</groupId>
>         <artifactId>camel-maven-plugin</artifactId>
>         <version>2.10.0.redhat-60024</version>
>       </plugin>
>     </plugins>
>   </build>
> 
> </project>
> *
> 
> 
> Once your POM file is ready, you can see that the stubs are created.
> <http://camel.465427.n5.nabble.com/file/n5744794/Capture.jpg> 
> U can use the generated stub to invoke the web service.
> 
> Find copy of my Camel XML Spring Config File.
> *<?xml version="1.0" encoding="UTF-8"?>
> 
> 
> <beans xmlns="http://www.springframework.org/schema/beans"
> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:camel="http://camel.apache.org/schema/spring"
> 	xmlns:jaxws="http://cxf.apache.org/jaxws"
> xmlns:cxf="http://camel.apache.org/schema/cxf"
> 	xmlns:osgi="http://www.springframework.org/schema/osgi"
> xmlns:soap="http://cxf.apache.org/bindings/soap"
> 	xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
> 	xmlns:http="http://cxf.apache.org/transports/http/configuration"
> 	xmlns:sec="http://cxf.apache.org/configuration/security"
> xmlns:ctx="http://www.springframework.org/schema/context"
> 
> 	xsi:schemaLocation="
>        http://camel.apache.org/schema/cxf
> http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://cxf.apache.org/bindings/soap
> http://cxf.apache.org/schemas/configuration/soap.xsd
>        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
>          http://www.springframework.org/schema/beans 
>          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>          http://camel.apache.org/schema/spring 
>          http://camel.apache.org/schema/spring/camel-spring.xsd
>          http://www.springframework.org/schema/osgi
> http://www.springframework.org/schema/osgi/spring-osgi.xsd
>          http://cxf.apache.org/bindings/soap
> http://cxf.apache.org/schemas/configuration/soap.xsd
>        http://www.springframework.org/schema/context
> http://www.springframework.org/schema/context/spring-context.xsd
>          http://cxf.apache.org/configuration/security
> http://cxf.apache.org/schemas/configuration/security.xsd
>     	 http://cxf.apache.org/transports/http/configuration
> http://cxf.apache.org/schemas/configuration/http-conf.xsd">
> 
> 	
> 	<bean id="activemq"
> class="org.apache.activemq.camel.component.ActiveMQComponent">
> 		<property name="brokerURL" value="tcp://localhost:61616" />
> 		<property name="userName" value="admin" />
> 		<property name="password" value="admin" />
> 	</bean>
> 	
> 
> 	<camelContext xmlns="http://camel.apache.org/schema/spring">
> 
> 		
> 		<route>
> 			
> 			<from uri="activemq:queue:input" />
> 			<to uri="WebServiceClient"/>
> 			<to uri="activemq:queue:responseXML" />
> 			
> 		</route>
> 
> 		
> 	</camelContext>
> 	
> 	
> 	
> 	<jaxws:client id="sapPiProxy"
> 		address="http://REJI-PC:8181/WebService.serviceagent/getResultEndpoint1"
> 		serviceClass="com.example.xmlns._1386864564116.GetResult"
> 		/>
> 	<bean id="WebServiceClient"
> class="com.mycompany.camel.cxf.contract.first.ServiceClientInvoker"
> 		init-method="init" destroy-method="destroy">
> 		<property name="myService" ref="sapPiProxy" />
> 	</bean>
> 	
> 
> </beans>
> *
> 
> The web service is actually invoked inside the Java class
> com.mycompany.camel.cxf.contract.first.ServiceClientInvoker Find the code
> below
> 
> *package com.mycompany.camel.cxf.contract.first;
> 
> import java.io.ByteArrayInputStream;
> import java.io.InputStream;
> import java.io.Serializable;
> import java.io.StringWriter;
> 
> import javax.xml.bind.JAXBContext;
> import javax.xml.bind.Marshaller;
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.dom.DOMSource;
> import javax.xml.transform.stream.StreamResult;
> 
> import org.apache.camel.Exchange;
> import org.apache.camel.Processor;
> 
> import com.example.xmlns._1386864564116.GetResult;
> 
> import data.inputmessage.REQ;
> import data.outputmessage.RES;
> 
> public class ServiceClientInvoker implements Runnable, Processor,
> Serializable{
> 
> 	private GetResult myService;
> 	
> 	
> 	
> 	
> 	public GetResult getMyService() {
> 		return myService;
> 	}
> 
> 	public void setMyService(GetResult myService) {
> 		this.myService = myService;
> 	}
> 
> 	@Override
> 	public void process(Exchange exchange) throws Exception {
> 		// TODO Auto-generated method stub
> 		REQ requestData=new REQ();
> 		String inputString = exchange.getIn().getBody(java.lang.String.class);
> 		String[] parts = inputString.split("-");
> 		String part1 = parts[0]; // 004
> 		String part2 = parts[1]; // 034556
> 		
> 		requestData.setFIRSTNAME(part1);
> 		requestData.setLASTNAME(part2);
> 		
> 		RES responseObj = myService.getResultAndRank(requestData);
> 		
> 		
> 		
> 
> 		JAXBContext jc = JAXBContext
> 				.newInstance(new Class[] { RES.class });
> 
> 		Marshaller um = jc.createMarshaller();
> 		StringWriter sw = new StringWriter();
> 
> 		um.marshal(responseObj, sw);
> 
> 		InputStream is = new ByteArrayInputStream(sw.toString().getBytes());
> 		org.w3c.dom.Document xmlDocument = DocumentBuilderFactory
> 				.newInstance().newDocumentBuilder().parse(is);
> 		
> 		
> 
> 		DOMSource domSource = new DOMSource(xmlDocument);
> 	       StringWriter writer1 = new StringWriter();
> 	       StreamResult result = new StreamResult(writer1);
> 	       TransformerFactory tf = TransformerFactory.newInstance();
> 	       Transformer transformer = tf.newTransformer();
> 
> 	       transformer.transform(domSource, result);
> 		
> 		
> 		
> 		
> 		
> 		exchange.getIn().setBody(writer1.toString());
> 		
> 		
> 	}
> 
> 	private Thread t;
> 	@Override
> 	public void run() {
> 		// TODO Auto-generated method stub
> 		
> 	}
> 	
> 	public void init() {
> 		
> 		t = new Thread(this, "SAPPI web service invoker thread");
> 		t.start();
> 
> 	}
> 
> 	public void destroy() {
> 		try {
> 			t.join();
> 		} catch (InterruptedException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		}
> 
> 	}
> 
> }
> 
> 
> *
> 
> My overall project structure will look like as follows
> <http://camel.465427.n5.nabble.com/file/n5744794/structure.jpg> 
> 
> Hope my post will be helpful. 
> 
> Cheers
> Reji
> 
> 
>  
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-call-remote-soap-web-service-from-a-application-using-apache-camel-tp5744734p5744794.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
 		 	   		  

Re: How to call remote soap web service from a application using apache camel

Posted by contactreji <co...@gmail.com>.
Hi Reena

U need to use CXF component for doing the same. Here i am following the WSDL
first approach. i.e I got the wsdl file from the service provider. The wsdl
file which I got is as follows.
*
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://xmlns.example.com/1386864564116"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:ns0="http://inputMessage.data" xmlns:ns1="http://outputMessage.data"
name="Untitled" targetNamespace="http://xmlns.example.com/1386864564116">
    <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://outputMessage.data"
targetNamespace="http://outputMessage.data" elementFormDefault="qualified"
attributeFormDefault="unqualified">
            <xs:element name="RES">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="RANK" type="xs:string"
minOccurs="0"/>
                        <xs:element name="MARKS" type="xs:string"
minOccurs="0"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://inputMessage.data" targetNamespace="http://inputMessage.data"
elementFormDefault="qualified" attributeFormDefault="unqualified">
            <xs:element name="REQ">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="FIRSTNAME" type="xs:string"
minOccurs="0"/>
                        <xs:element name="LASTNAME" type="xs:string"
minOccurs="0"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </wsdl:types>
    <wsdl:service name="WebService">
        <wsdl:port name="getResultEndpoint1"
binding="tns:getResultEndpoint1Binding">
            <soap:address
location="http://REJI-PC:8181/WebService.serviceagent/getResultEndpoint1"/>
        </wsdl:port>
    </wsdl:service>
    <wsdl:portType name="getResult">
        <wsdl:operation name="getResultAndRank">
            <wsdl:input message="tns:REQ_MESSAGE"/>
            <wsdl:output message="tns:RES_MESSAGE"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="getResultEndpoint1Binding" type="tns:getResult">
        <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="getResultAndRank">
            <soap:operation style="document"
soapAction="/WebService.serviceagent/getResultEndpoint1/getResultAndRank"/>
            <wsdl:input>
                <soap:body use="literal" parts="part1"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" parts="part1"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:message name="REQ_MESSAGE">
        <wsdl:part name="part1" element="ns0:REQ"/>
    </wsdl:message>
    <wsdl:message name="RES_MESSAGE">
        <wsdl:part name="part1" element="ns1:RES"/>
    </wsdl:message>
</wsdl:definitions>
*



Now I will come to the camel project. I have used a plugin  to generate the
Java stubs and SEI for the web service invocation. Find a copy of my POM
file and you can figure out the plugin which is used for generating the
Stubs.

*<?xml version="1.0" encoding="UTF-8" standalone="no"?><project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  

  <version>1.0.0-SNAPSHOT</version>
  <groupId>com.poc</groupId>
  <artifactId>bw-client</artifactId>
  <name>BWClient</name>
  <description>Creates a web service using the WSDL contract
first</description>

  <repositories>
    <repository>
      <id>fusesource</id>
      <name>FuseSource Release Repository</name>
      <url>http://repo.fusesource.com/nexus/content/groups/public/</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>
      </releases>
    </repository>
    <repository>
        <id>fusesource.ea</id>
        <name>FuseSource Community Early Access Release Repository</name>
        <url>http://repo.fusesource.com/nexus/content/groups/ea</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
    <repository>
      <id>jboss-public-repository-group</id>
      <name>JBoss Public Repository Group</name>
      <url>http://repository.jboss.org/nexus/content/groups/public/</url>
      <layout>default</layout>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>daily</updatePolicy>
      </snapshots>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>fusesource</id>
      <name>FuseSource Release Repository</name>
      <url>http://repo.fusesource.com/nexus/content/groups/public/</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>
      </releases>
    </pluginRepository>
    <pluginRepository>
        <id>fusesource.ea</id>
        <name>FuseSource Community Early Access Release Repository</name>
        <url>http://repo.fusesource.com/nexus/content/groups/ea</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
  </pluginRepositories>


  <dependencies>

	
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-core</artifactId>
			<version>2.10.0.fuse-71-047</version>
		</dependency>

		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-cxf</artifactId>
			<version>2.10.0.fuse-71-047</version>
		</dependency>

		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.16</version>
		</dependency>

		
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.6.1</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.6.1</version>
		</dependency>

		
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-transports-http-jetty</artifactId>
			<version>2.6.0.fuse-71-047</version>
		</dependency>

		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-test-spring</artifactId>
			<version>2.10.0.fuse-71-047</version>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.10</version>
			<scope>test</scope>
		</dependency>


		


		<dependency>
			<groupId>commons-lang</groupId>
			<artifactId>commons-lang</artifactId>
			<version>2.6</version>
		</dependency>

		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
			<version>3.1</version>
		</dependency>

		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-mail</artifactId>
			<version>2.10.6</version>
		</dependency>

		<dependency>
			<groupId>org.apache.servicemix.specs</groupId>
			<artifactId>org.apache.servicemix.specs.activation-api-1.1</artifactId>
			<version>2.1.0</version>
		</dependency>

		<dependency>
			<groupId>javax.mail</groupId>
			<artifactId>mail</artifactId>
			<version>1.4</version>
		</dependency>


		<dependency>
			<groupId>org.apache.activemq</groupId>
			<artifactId>activemq-camel</artifactId>
			<version>5.8.0</version>
		</dependency>

		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-mail</artifactId>
			<version>2.10.0.fuse-71-047</version>

		</dependency>
  </dependencies>

  <build>
    <plugins>

      <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>2.6.0.redhat-60024</version>
        <executions>
          <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
             
<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
              <wsdlOptions>
                <wsdlOption>
                 
<wsdl>${basedir}/src/main/resources/wsdl/MyResultService.wsdl</wsdl>
                  <extraargs>
                    <extraarg>-impl</extraarg>
                  </extraargs>
                </wsdlOption>
              </wsdlOptions>
            </configuration>
            <goals>
              <goal>wsdl2java</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
      </plugin>

      
      <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-maven-plugin</artifactId>
        <version>2.10.0.redhat-60024</version>
      </plugin>
    </plugins>
  </build>

</project>
*


Once your POM file is ready, you can see that the stubs are created.
<http://camel.465427.n5.nabble.com/file/n5744794/Capture.jpg> 
U can use the generated stub to invoke the web service.

Find copy of my Camel XML Spring Config File.
*<?xml version="1.0" encoding="UTF-8"?>


<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
	xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://camel.apache.org/schema/cxf"
	xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:soap="http://cxf.apache.org/bindings/soap"
	xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
	xmlns:http="http://cxf.apache.org/transports/http/configuration"
	xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns:ctx="http://www.springframework.org/schema/context"

	xsi:schemaLocation="
       http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd
       http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
       http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
         http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://camel.apache.org/schema/spring 
         http://camel.apache.org/schema/spring/camel-spring.xsd
         http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
         http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
       http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
         http://cxf.apache.org/configuration/security
http://cxf.apache.org/schemas/configuration/security.xsd
    	 http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd">

	
	<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
		<property name="brokerURL" value="tcp://localhost:61616" />
		<property name="userName" value="admin" />
		<property name="password" value="admin" />
	</bean>
	

	<camelContext xmlns="http://camel.apache.org/schema/spring">

		
		<route>
			
			<from uri="activemq:queue:input" />
			<to uri="WebServiceClient"/>
			<to uri="activemq:queue:responseXML" />
			
		</route>

		
	</camelContext>
	
	
	
	<jaxws:client id="sapPiProxy"
		address="http://REJI-PC:8181/WebService.serviceagent/getResultEndpoint1"
		serviceClass="com.example.xmlns._1386864564116.GetResult"
		/>
	<bean id="WebServiceClient"
class="com.mycompany.camel.cxf.contract.first.ServiceClientInvoker"
		init-method="init" destroy-method="destroy">
		<property name="myService" ref="sapPiProxy" />
	</bean>
	

</beans>
*

The web service is actually invoked inside the Java class
com.mycompany.camel.cxf.contract.first.ServiceClientInvoker Find the code
below

*package com.mycompany.camel.cxf.contract.first;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

import com.example.xmlns._1386864564116.GetResult;

import data.inputmessage.REQ;
import data.outputmessage.RES;

public class ServiceClientInvoker implements Runnable, Processor,
Serializable{

	private GetResult myService;
	
	
	
	
	public GetResult getMyService() {
		return myService;
	}

	public void setMyService(GetResult myService) {
		this.myService = myService;
	}

	@Override
	public void process(Exchange exchange) throws Exception {
		// TODO Auto-generated method stub
		REQ requestData=new REQ();
		String inputString = exchange.getIn().getBody(java.lang.String.class);
		String[] parts = inputString.split("-");
		String part1 = parts[0]; // 004
		String part2 = parts[1]; // 034556
		
		requestData.setFIRSTNAME(part1);
		requestData.setLASTNAME(part2);
		
		RES responseObj = myService.getResultAndRank(requestData);
		
		
		

		JAXBContext jc = JAXBContext
				.newInstance(new Class[] { RES.class });

		Marshaller um = jc.createMarshaller();
		StringWriter sw = new StringWriter();

		um.marshal(responseObj, sw);

		InputStream is = new ByteArrayInputStream(sw.toString().getBytes());
		org.w3c.dom.Document xmlDocument = DocumentBuilderFactory
				.newInstance().newDocumentBuilder().parse(is);
		
		

		DOMSource domSource = new DOMSource(xmlDocument);
	       StringWriter writer1 = new StringWriter();
	       StreamResult result = new StreamResult(writer1);
	       TransformerFactory tf = TransformerFactory.newInstance();
	       Transformer transformer = tf.newTransformer();

	       transformer.transform(domSource, result);
		
		
		
		
		
		exchange.getIn().setBody(writer1.toString());
		
		
	}

	private Thread t;
	@Override
	public void run() {
		// TODO Auto-generated method stub
		
	}
	
	public void init() {
		
		t = new Thread(this, "SAPPI web service invoker thread");
		t.start();

	}

	public void destroy() {
		try {
			t.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}


*

My overall project structure will look like as follows
<http://camel.465427.n5.nabble.com/file/n5744794/structure.jpg> 

Hope my post will be helpful. 

Cheers
Reji


 



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-call-remote-soap-web-service-from-a-application-using-apache-camel-tp5744734p5744794.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: How to call remote soap web service from a application using apache camel

Posted by Joseph <th...@gmail.com>.
hi Mathews,

I have a requirement like, I need to create a sample Camel project which
invokes the mock web service created in my local soap. I have the wsdl and
created the mock in soap. I need to use the Spring DSL to make the web
service call.
I am beginner to use this Camel framework. Do you have any sample example
which illustrates this scenario. If not can you please guild me in doing
this. 

Queries:
1. Do we need to generate the stubs for the wsdl as in the regular way. If
yes, how can we populate the data for the request object. 
2. How can we invoke the web service from the spring DSL xml file. 
3. If request was generated, do we have a chance to see the request xml
which is going to invoke the service and also if success, can we see the
response coming from the soap service.

Thanks and regards,
Joseph.



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-call-remote-soap-web-service-from-a-application-using-apache-camel-tp5744734p5781694.html
Sent from the Camel - Users mailing list archive at Nabble.com.