Building a WS-SOAP Proxy with Mule ESB

A common integration scenario is that a company/organisation has a old internal web-service that they want to expose as a public interface.
Often these internal services have a less than ideal interface which is often auto-generated from some business logic so you do not want to simply expose the existing contract. Instead we want to have a interface more suited for use by external entities. However it is not always practical or possible to rewrite the internal service.

The solution is to build a SOAP proxy with transformation.

Lets say we have a internal service that gets a name and returns a greeting for that name. Here is a example of the request and response for this imaginary internal service.

Pontus

Hello Pontus

As you can see the inner service has alot to wish for when it comes to naming. Fortunately with Mule ESB it is simple to create a SOAP proxy that remedies this.

The Mule flow starts with a inbound HTTP endpoint and a CXF Proxy service which exposes the desired interface.

The payload from these initial steps will be the body of the incomming SOAP request. So we want to translate this to comply with the interface of the inner service.

The default return type from the XSLT transformer is a byte array. Since we want the payload as a String we set the returnClass attribute.

After this we want to call the inner service and then get the response body. This is the only really tricky bit. Since we only want the SOAP body from the response we must let the CXF component handle the response before we send it to the transformation. This is done by breaking out this part into a subflow.

This subflow is then called from the main flow

And finaly we transform the response body into a response that complies with the external interface.

And with that we're done and can start using the public interface.

Pontus

Hello Pontus

Full code example is available at github.