To consume a SOAP Web Service in the Mule ESB, in addition to using the CXF Component, we can also use the Web Service Consumer Connector. How is it in details? We will find out in this tutorial.
First, I will create a new Maven Mule project as an example:
In this example, I will use the HTTP Listener Connector to receive the request from the client with the name of the student (for example, my name as Khanh), then I will use the Web Service Consumer Connector to consume SOAP Web Service in the tutorial Expose SOAP Web Service using CXF component in Mule ESB, allow us to return the result of “Hello, Khanh”.
OK, let’s get started.
First, we will use the HTTP Listener Connector to expose a request to our application that allows the client to pass the student information.
If you do not know how to configure the HTTP Listener Connector, please refer to this tutorial.
Here, I configure as follows:
Global Configuration:
Next, you need to use the Transform Message Component to build the SOAP message.
Building SOAP message is a necessity for the SOAP Web Service to process our requests.
As I mentioned in my tutorial Learn about SOAP message, we have a lot of tags in a SOAP message and the <Body> tag is a mandatory tag. In Mule 3, the Web Service Consumer Connector will automatically use the payload to build the <Body> and the Mule Message Property to build the <Header> of SOAP message. With SOAP Web Service in the tutorial Expose SOAP Web Service using CXF component in Mule ESB, because the “hello” operation only has the section <Body>, so what we need to do is build the content of the tag <Body>.
Here we are using the Transform Message Component with DataWeave to transform the request from the client into the XML content which we need to send to the SOAP Web Service.
Expect the XML content we need to send to the SOAP Web Service in the tutorial Expose SOAP Web Service using CXF component in Mule ESB is:
1 2 3 |
<hdj:hello xmlns:hdj="http://muleesbcxfsoapexpose.huongdanjava.com/"> <arg0>Khanh</arg0> </hdj:hello> |
so, my DataWeave will have the following content:
1 2 3 4 5 6 7 8 9 10 11 12 |
%dw 1.0 %output application/xml %namespace hdj http://muleesbcxfsoapexpose.huongdanjava.com/ --- { hdj#hello: { arg0: inboundProperties."http.query.params".name } } |
Finally, we will use the Web Service Consumer Connector by dragging and dropping into the Message Processor in our example.
The configuration for the Web Service Consumer is as follows:
In order to configure the Web Service Consumer, we have two parts to do:
- First is the Global Configuration section, to configure this section, click the Add button next to the Connector Configuration field.
You need to specify the WSDL file defined for the SOAP Web Service in the WSDL Location field. If you already have a WSDL file in your project, then click on the … button to choose the WSDL file! This field also allows us to specify the WSDL file from a remote URL, so I will enter the URL of the SOAP Web Service in the tutorial Expose SOAP Web Service using CXF component in Mule ESB for simplicity.
As you can see, after entering the WSDL URL, the fields below including Service, Port, Address are automatically configured based on the contents of the WSDL file. The values in the Field, Port, and Address fields define the URL information that the client will use to request to the SOAP Web Service. You can refer to the tutorial Learn about WSDL file in SOAP Web Service to understand more.
OK, so we have configured the Global Configuration for Web Service Consumer Connector. Click OK button to close this window.
- After configuring the Global Configuration section, you will see the main configuration section of the Web Service Consumer Connector that automatically selects Operation that the SOAP Web Service is defining.
That’s it!
Now try running the application and then asking for http://localhost:8082/hello?name=Khanh. The result will be: