Consuming jax-ws webservice in Mule Project

This tutorial shows how to consume jax-ws webservice in Mule ESB step by step. You need to have some idea on SOAP based webservices otherwise it will be a bit difficult to understand. From jdk 6 onwards we don’t need to put any extra jar for jax-ws based webservices as it comes out of the box. You can also implement jax-ws service using Metro, Axis2, CXF framework but Metro implementation has the best support for jax-ws service.

Before you proceed you must go through creating jax-ws webservice in Mule Project.


Prerequisites
Mule Studio 3.5.0
Mule 3.4.1
JDK 1.6
Maven 2.x

Step 1. Create new Mule flow under jax-ws-cxf project. Do right-click on the project and do like below screen-shot.

consuming jax-ws webservice in Mule ESB

Step 2. In the popup window input name as jax-ws-consumer. The flow name will automatically be created. Click Finish.

consuming jax-ws webservice in Mule ESB
Step 3. Now create a flow like below screen-shot.
Endpoint: HTTP
Component: SOAP
Transformer: Object to String
consuming jax-ws webservice in Mule ESB

Step 4. Do double-click jax-ws-consumerFlow1 and rename jax-ws-consumerFlow1 to jax-ws-consumer

consuming jax-ws webservice in Mule ESB
Step 5. Do double-click on HTTP endpoint and change the below properties.
consuming jax-ws webservice in Mule ESB

Step 6. Do double-click on SOAP component and change the below properties.

consuming jax-ws webservice in Mule ESB

Step 7. Do double-click on outbound HTTP endpoint and change the below properties.

consuming jax-ws webservice in Mule ESB

Step 8. Object to String transformer is used to render the correct format data. HTTP outbound endpoint sends payload in XML format and expects to receive response in XML as well. However, SOAP client unmarshals XML content and sends plain String (returned from sayHello method). So, let’s turn the content-type into text/plain in order to avoid browser rendering issues.

Step 9. Save all and run the project as Mule Application.

Step 10. Now once the application successfully runs hit the URL http://localhost:8084/jax-ws-consumer/Soumitra. You will get below output in the browser.

consuming jax-ws webservice in Mule ESB
So we have also seen how to consume the service.
Thanks for your reading. Please do not forget to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *