Contact Us 1-800-596-4880

Proxying Web Services with CXF

Normally when building CXF web services, you can databind the XML to POJOs. A CXF component might receive an OrderRequest object, or you might send an OrderRequest object via a CXF outbound router. However, it is often useful to work with the XML directly when building web services or consuming other web services. The CXF module provides the ability to do this.

Instead of building a proxy application from scratch, consider Setting Up and Deploying a Proxy.

Deciding How to Proxy Your Web Service

While many times you can proxy web services without using CXF (see Proxying Web Services), there are several cases where you might want to use CXF proxies:

  • To work directly with the SOAP body, such as adding XML directly to it

  • To take advantage of the CXF web service standards support to use WS-Security or WS-Addressing

  • To enforce WS-Policy assertions

  • To easily service a WSDL associated with your service

  • To transform a SOAP body

You would use wsdl-cxf instead of proxies when you want to invoke a service and one or more of the following applies:

  • You don’t want to generate a client from WSDL

  • You don’t have the raw XML

  • The service takes simple arguments such as string, int, long, or date

CXF proxies support working with the SOAP body or the entire SOAP envelope. By default only the SOAP body is sent as payload, but the payload mode can be set via the "payload" attribute to envelope if needed.

Server-Side Proxying

To proxy a web service so you can work with the raw XML, you can create a CXF proxy message processor:

<cxf:proxy-service />

This will make the SOAP body available in the Mule message payload as an XMLStreamReader. To service a WSDL using a CXF proxy, you must specify the WSDL namespace as a property:

<cxf:proxy-service wsdlLocation="foo.wsdl"
   service="YOUR_WSDL_SERVICE"
   namespace="YOUR_WSDL_NAMESPACE"/>

Client-Side Proxying

To send outbound requests to external web services, it’s highly recommended that you use the Web Service Consumer instead.

Similarly, you can create an outbound endpoint to send raw XML payloads:

<cxf:proxy-client/>

URL Rewriting

In order to direct the SOAP messages through the proxy, It is necessary to rewrite the endpoint URL of the service. In this way, the client reads the WSDL document with the endpoint URL pointing to the proxy instead of pointing to the service.