19
CONSUMING SOAP WEB SERVICE - MULESOFT CXF JAX-WS-CLIENT MODULE Vince Jason Soliza

MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Embed Size (px)

Citation preview

Page 1: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

CONSUMING SOAP WEB SERVICE

- MULESOFT CXF JAX-WS-CLIENT MODULE

Vince Jason Soliza

Page 2: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Mulesoft CXF Jax-WS Client Module

When using CXF inside of Mule, there are several different ways to consume web service.

One is the WSDL First CXF JAX-WS Client: It builds a message processor which can use a JAX-WS client generated from WSDL.

Page 3: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

JAX-WS-CLIENT WSDL / CONTRACT FIRST APPROACH

Page 4: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Create Stub Client with CXF: wsdl2javaFirst we need to setup our maven configuration to create a stub client. CXF includes the wsdl2java utility that can generate Java stub client code to call any method on the service, and marshal and un-marshal request parameters and responses as Java objects for further processing. This generated stub client is the core of your connector.

Page 5: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Create Stub Client with CXF: wsdl2java

The Java source files generated correspond to the service as described by the contents of the WSDL.

Page 6: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Create 2 Flows:Main Flow & CXF Client Flow

Page 7: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Main Flow Components• HTTP Listener

– Accepts the request

• Transform Message – Create request for web service consumer the output is XML

• XML-to-JAXB-Object – Transform XML to JAXB-Object to be consumed by the JAX-WS-Client

• Flow Reference– Reference to the Flow of EchoServiceFlow

• Transform Message– Parse the response of EchoServiceFlow to XML

Page 8: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

CXF Client Components• CXF

– Jax-ws-client configuration

• HTTP request– http request hold the configuration for the target endpoint

Page 9: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Request ConfigurationWe used Transform Message to create a SOAP request, cxf:jax-ws-client requires jaxb-object as the acceptable request so we added xml-to-jaxb-object transformer after it.

Page 10: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Request ConfigurationCheck in debug mode, the payload is an instance of EchoRequest.

Page 11: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Request ConfigurationCode Snippet:

<dw:transform-message doc:name="Transform Message"><dw:set-payload><![CDATA[%dw 1.0

%output application/xml%namespace echo http://www.whiteskylabs.com/wsdl/echo/---echo#EchoRequest: {

EchoInfo: {Id: "1345",Name: "Mario Luigi",Description: "Mario Bros",OtherInfo: "Legendary"}

}]]></dw:set-payload></dw:transform-message><mulexml:jaxb-xml-to-object-transformer

returnClass="com.whiteskylabs.wsdl.echo.EchoRequest" jaxbContext-ref="JAXB_Context"doc:name="XML to JAXB Object" />

Page 12: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

cxf:jax-ws-client ConfigurationConfigure the client with the following properties.

• clientClass: The client class generated by CXF, which extends javax.xml.ws.Service.

• port: The WSDL port to use for communicating with the service

• wsdlLocation: The location of the WSDL for the service. Since we are using WSDL first client, CXF uses this to configure the client.

• operation: The operation name to invoke on the web service.

Page 13: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

cxf:jax-ws-client ConfigurationWe put cxf:jax-ws-client into a new private flow, to wrap it as a SOAP web service consumer.

code snippet:

<flow name="EchoServiceFlow"><cxf:jaxws-client operation="echo"

clientClass="com.whiteskylabs.wsdl.echo.EchoService_Service" port="EchoServicePort"

wsdlLocation="classpath:/EchoService.wsdl" doc:name="CXF"soapVersion="1.2" />

<http:request config-ref="HTTP_Request_Configuration"path="/echo-ws/ws/EchoService" method="POST" doc:name="HTTP" />

</flow>

Page 14: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Response ConfigurationThe cxf:jax-ws-client response is also an object, but unlike with request it’s not in the form of JAXB-Object. We can directly use the Transform Message to parse it and create an XML response.

Page 15: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Response ConfigurationCheck in debug mode, the payload is an instance of EchoResponse.

Page 16: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Response Configurationcode snippet:

<dw:transform-message doc:name="Transform Message"><dw:set-payload><![CDATA[%dw 1.0

%output application/xml%namespace echo http://com.whiteskylabs/wsdl/echo/---{

echo#EchoResponse: {echoResult: {echoInfo: {id: payload.echoResult.echoInfo.id,name: payload.echoResult.echoInfo.name,description: payload.echoResult.echoInfo.description,otherInfo: payload.echoResult.echoInfo.otherInfo}}}

}]]></dw:set-payload></dw:transform-message>

Page 17: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Test the application• Run the application in Anypoint Studio.• Send request through HTTP using Postman, browser or any client you

prefer.• We can see in the screenshot below, the response of the soap web service

we consumed using web service consumer.

Page 18: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

Summary

This slide describes how to consume web services using the CXF jax-ws-client message processor using WSDL first approach.

It is still recommended to use the Web Service Consumer component instead of this whenever possible.

Page 19: MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module

QUESTIONS?Please leave a comment