Hi Sir,Can you please show me your camel-route.xml?
> Date: Sun, 15 Dec 2013 09:33:07 -0800
> From: [email protected]
> To: [email protected]
> 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.