mulesoft consuming soap web service - cxf proxy-client module
TRANSCRIPT
CONSUMING SOAP WEB SERVICE
- MULESOFT CXF PROXY-CLIENT MODULE
Vince Jason Soliza
MuleSoft CXF Proxy Client ModuleWhen using CXF inside of Mule, there are several different ways to consume web service.
One is the Proxy Client: Unlike jax-ws-client that oblige to use JAXB-Objects, this one could work directly with XML when consuming web services.
Create 2 Flows:Main Flow & CXF Client Flow
Main Flow Components• HTTP Listener
– Accepts the request
• Transform Message – Create request for web service consumer the output is XML
• Flow Reference– Reference to the Flow of EchoServiceFlow
• Transform Message– Parse the response of EchoServiceFlow to XML
CXF Client Components• CXF
– proxy-client configuration
• HTTP request– http request hold the configuration for the target endpoint
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.
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>
cxf:proxy-client ConfigurationCXF proxies support working with the SOAP body or the entire SOAP envelope. By default only the SOAP body is sent as payload, but the payload mode can be set via the "payload" attribute to envelope if needed.
Cxf:proxy-client ConfigurationWe put cxf:proxy-client into a new private flow, to wrap it as a SOAP web service consumer.
code snippet:
<flow name="EchoServiceProxyFlow"><cxf:proxy-client
doc:name="CXF"soapVersion="1.2" payload="body" />
<http:request config-ref="HTTP_Request_Configuration"path="/echo-ws/ws/EchoService" method="POST"
doc:name="HTTP" /></flow>
Response ConfigurationThe cxf:proxy-client response can be parsed directly with Transform Message.
Response 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#EchoResponse: {EchoResult: {EchoInfo: {Id: payload.echo#EchoResponse.EchoResult.EchoInfo.Id,Name: payload.echo#EchoResponse.EchoResult.EchoInfo.Name,Description: payload.echo#EchoResponse.EchoResult.EchoInfo.Description,OtherInfo: payload.echo#EchoResponse.EchoResult.EchoInfo.OtherInfo}}}
}]]></dw:set-payload></dw:transform-message>
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 cxf:proxy-client as web service consumer.
SummaryThis slide describes how to consume web services using the CXF proxy-client message processor. While it is recommended to use web service consumer in consuming SOAP web service there are several reasons you may want to use proxy-client, such as:• You don’t want to use the WSDL• You want to work with the SOAP envelope• To take advantage of the CXF web service
standards support to use WS-Security or WS-Addressing
QUESTIONS?Please leave a comment