Expose SOAP Web Service using CXF component in Mule ESB

The CXF component in the Mule ESB uses the Apache CXF library to help us create a SOAP Web Service or consume from a SOAP Web Service. In this tutorial, I will show you how to use CXF component in Mule ESB to create a SOAP Web Service.

First, I will create a new Maven project in Anypoint Studio as an example:

Expose SOAP Web Service using CXF component in Mule ESB

To create a new SOAP Web Service using the CXF component in the Mule ESB, we need to do the following:

The first step is to use the HTTP Connector in the Message Source section to expose an HTTP server that allows the client to access our SOAP Web Service.

Expose SOAP Web Service using CXF component in Mule ESB

If you guys do not know how to configure HTTP Connector, you can refer to this tutorial.

Here, I configure as follows:

Expose SOAP Web Service using CXF component in Mule ESB

Global Configuration:

Expose SOAP Web Service using CXF component in Mule ESB

With the above configuration, we will expose a SOAP Web Service at http://localhost:8081/hello, right? ????

Next, we will drag and drop the CXF component into the Message Processor in our application.

Expose SOAP Web Service using CXF component in Mule ESB

The CXF component will process the request data from the user.

The configuration for the CXF component is as follows:

Expose SOAP Web Service using CXF component in Mule ESB

To configure the CXF component, we need to configure two parts:

  • The first part is Global Configuration, to configure this section, click the Add button next to the Config Reference field.

Expose SOAP Web Service using CXF component in Mule ESB

Leave the default value and click the OK button.

  • The second part is that we will choose the operation that we need to perform.

Currently, the CXF component supports the following operations:

Expose SOAP Web Service using CXF component in Mule ESB

To create a new SOAP Web Service, you need to select JAX-WS service operation, other operations will be used for other purposes and I will not mention in this tutorial.

Then, the configuration of the CXF component is as follows:

Expose SOAP Web Service using CXF component in Mule ESB

There are many fields here but actually, to expose SOAP Web Service, we just need to configure the Service Class field to be enough, the values of other fields can be taken from the definition of the Service Class field. To know what we need to configure for Service Class field, first, let me briefly talk about SOAP Web Service with Apache CXF.

To expose the SOAP Web Service using Apache CXF, we need to create an interface with Apache CXF’s @WebService annotation. In this tutorial, I will create a simple interface as follows:

If you know about SOAP Web Service, you will know in a SOAP Web Service, we will have one or more operations, the request data from the user will contain the operation name that they want the SOAP Web Service to execute. With Apache CXF, an operation would correspond to a method marked with the @WebMethod annotation. For example, I create an operation called hello located in HelloWorldService as follows:

So, we have defined a simple interface to expose a SOAP Web Service. The value of the Service Class field in the configuration of the CXF component is the name of the interface that we have.

Expose SOAP Web Service using CXF component in Mule ESB

Our last step is to use the Mule ESB Java component to configure the HelloWorldService interface implementation class.

Expose SOAP Web Service using CXF component in Mule ESB

Here, we will implement the HelloWorldService interface as simple as this:

At this point, the configuration of the Java component should look like this:

Expose SOAP Web Service using CXF component in Mule ESB

So we’ve finished the configuration. Now you can use SOAP UI to send a request to our SOAP Web Service to check the results:

Expose SOAP Web Service using CXF component in Mule ESB

5/5 - (1 vote)

One thought on “Expose SOAP Web Service using CXF component in Mule ESB

  1. Hello Khanh,

    Thank you for explaining in details. We have the same implementation in Mule 3 and now I need to migrate to 4.0. How can we expose web service developed using Apache CXF’s @WebService annotation.on Mule 4. We are using mule 4 community edition. the component CXF is no longer available in Mule 4.

    Thank you again and appreciate the time and response.

Add Comment