Call SOAP Webservice Using CXF
Get the WSDLÂ from an example SOAP service.
Store the WSDL file named calculator.wsdl in your codebase in the folder src/main/resources/wsdls.
Add a dependency on CXF framework to the pom.xml.
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <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> <groupId>net.pricefx.integration</groupId> <version>1.0.0-SNAPSHOT</version> <artifactId>im-example-soap-cxf</artifactId> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <spring.boot>1.5.4.RELEASE</spring.boot> <pricefx-im-version>1.1.14</pricefx-im-version> </properties> <dependencyManagement> <dependencies> <!-- PFX Integration Manager --> <dependency> <groupId>net.pricefx.integration</groupId> <artifactId>integration-manager</artifactId> <version>${pricefx-im-version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <!-- PFX Integration Manager --> <dependency> <groupId>net.pricefx.integration</groupId> <artifactId>integration-manager-starter</artifactId> </dependency> <!-- Apache CXF Framework --> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cxf</artifactId> </dependency> </dependencies> <build> <defaultGoal>install</defaultGoal> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.5.4.RELEASE</version> <configuration> <mainClass>net.pricefx.integration.app.Application</mainClass> <executable>true</executable> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> </project>
Â
Modify pom.xml to generate JAXB beans during Maven build using the Maven plugin and run
mvn package
. It will generate classes to the target folder of the project.pom.xml
<?xml version="1.0" encoding="UTF-8"?> <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> <groupId>net.pricefx.integration</groupId> <version>1.0.0-SNAPSHOT</version> <artifactId>im-example-soap-cxf</artifactId> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <spring.boot>1.5.4.RELEASE</spring.boot> <pricefx-im-version>1.1.14</pricefx-im-version> </properties> <dependencyManagement> <dependencies> <!-- PFX Integration Manager --> <dependency> <groupId>net.pricefx.integration</groupId> <artifactId>integration-manager</artifactId> <version>${pricefx-im-version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <!-- PFX Integration Manager --> <dependency> <groupId>net.pricefx.integration</groupId> <artifactId>integration-manager-starter</artifactId> </dependency> <!-- Apache CXF Framework --> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cxf</artifactId> </dependency> </dependencies> <build> <defaultGoal>install</defaultGoal> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.5.4.RELEASE</version> <configuration> <mainClass>net.pricefx.integration.app.Application</mainClass> <executable>true</executable> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- Generates JAXB beans from WSDL --> <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>3.2.4</version> <executions> <execution> <id>generate-sources</id> <phase>generate-sources</phase> <configuration> <wsdlOptions> <wsdlOption> <wsdl>src/main/resources/wsdls/PricingService.svc.xml</wsdl> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
Â
Add the route file to the camel-context.xml.
camel-context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <import resource="refs/routes/cxfRoutes.xml"/> <camelContext xmlns="http://camel.apache.org/schema/spring" useMDCLogging="true"> <contextScan/> <routeContextRef ref="cxfRoutes"/> </camelContext> </beans>
Â
Create the route file cxfRoutes.xml in src/main/resources/refs/routes containing JAXB factory.
cxfRoutes.xml
Â
Implement a service class for creating the request and setting parameters.
GetPriceService.java
Â
Call the service to create the request and set parameters.
cxfRoutes.xml
Â
Define and call the CXF endpoint. Set the method.
cxfRoutes.xml
Â
Check the result for a failure and log the result.
cxfRoutes.xml
IntegrationManager version 5.8.0