Multipart WSDL With Mule ESB
Multipart WSDL With Mule ESB
Let's take a look at a tutorial that explains SOAP binding for an operation that has two parts with a SOAP header part and a SOAP body.
Join the DZone community and get the full member experience.Join For Free
Discover how you can get APIs and microservices to work at true enterprise scale.
Before getting into an article, let’s have a quick introduction about web services with multi-part WSDL.
We can say a WSDL as multipart WSDL when:
1. SOAP binding for an operation bound to A SOAP body and non-binary attachments.
2. SOAP binding for an operation that has two parts with a SOAP header part and a SOAP body. The below screenshot from WSDL will help you in identifying the multi-part WSDL.
In this article, we are going to discuss scenario number 2.
Currently, most of the banking, healthcare, insurance, and aviation sector players maintain their core enterprise integration systems with SOAP-based services for various reasons.
When you are migrating from a legacy WBS-based system into Mule, you will surely end up consuming WS with multi-part WSDL’s.
SOAP-based Webservice’s can be consumed in Mule using a Webservice consumer or CXF component with a JAX-WS client operation. As a web service consumer doesn’t support multi-part implementation, we will go with the CXF component.
CXF as JAX-WS client
XML to JAXBObject transformer
WSDL2 Java tool by CXF can be found here.
Whenever you try consuming services with multi-part messages, the web service consumer shows a warning as “Warning: Operation Messages With More Than 1 Part Are Not Supported.”
When you drag and drop the DW component, it senses either SOAP Body or other parts, which makes it difficult for developers to perform transformations.
Generate JAXB Objects corresponding to the given service WSDL.
Before generating JAXB objects, we need to make the below change to WSDL.
Find the PortType for your interface and place the below binding statement in your WSDL.
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"> <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle> </jaxws:bindings>
Drag and drop CXF componant, select operation as Jax-WS Client as shown in the below screenshot.
To generate JAXB objects, click on Generate from WSDL as highlighted in the above screenshot. Enter the WSDL location and Java package name in the "Generate from WSDL" pop-up:
Identify the below classes from the generated Java files:
1. The interface represents Webservice (tip: search with “@WebService”).
2. Request header and body Java Objects (tip: Identify from Interface class Operation).
3. Webservice Client class (tip: search with “@WebServiceClient”).
Prepare request for Jax-WS client.
As our message payload contains data formats like XML, we need to convert XML to the equivalent, JAXB object, using XML to JAXB Object Transformer.
Header JAXB object creation:
Body JAXB Object creation:
Assign the Payload with the required variables for the given Operation. As getDetails operation as two parameters, out payload will be an array of two JAXB objects.
@WebMethod @WebResult(name = "getDetailsResponse", targetNamespace = "http://soapMain.capg.com", partName = "parameters") public GetDetailsResponse getDetails( @WebParam(partName = "getDetails", name = "getDetails", targetNamespace = "http://soapMain.capg.com") GetDetails getDetails, @WebParam(partName = "InputHeader", name = "getDetailsHeader", targetNamespace = "http://soapMain.capg.com", header = true) GetDetailsHeader inputHeader );
requestPayload = new object(); requestPayload = payload; requestPayload = flowVars.flwJaxBHeader; payload = requestPayload;
Add a combination of CXF as JAX-WS client and HTTP requester for consuming the Webservice.
Thanks for reading this article, and let me know your thoughts and/or suggestions in the comments section.
Opinions expressed by DZone contributors are their own.