Contact Us 1-800-596-4880

Proxying Web Services

Mule can act as a Web Service proxy to perform several useful functions:

  • Routing to the appropriate backend service (whether remote or local)

  • Message transformations, such as converting from old versions of the message format

  • Protocol bridging, such as HTTP to JMS

  • Validation

  • Security enforcement

  • WS-Policy enforcement

Instead of building a proxy application from scratch, consider using an Anypoint Platform Proxy. Mule provides several utilities that help you do this:

  • Protocol bridging - allows you to forward requests from one endpoint to another. This is generally the best option for proxying Web Services.

  • WSProxyService - allows you to service WSDLs locally while proxying remote web services.

  • Proxying Web Services - perform WS-Security or WS-Policy actions, route based on information such as the operation or SOAP Action, and easily work with just the payload by taking advantage of CXF’s web service capabilities.

The following sections provide more information on these utilities.

Protocol Bridging

The simplest type of Web Service proxy just involves forwarding a request from one endpoint to another via service bridging. You can forward the data streams directly, or you can process and transform the XML. If you are doing content-based routing, this is often the best option, as it will add less overhead than a full CXF proxy (which is only needed in certain cases).

Following is a simple configuration example that forwards a request from one HTTP endpoint to another:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8888" doc:name="HTTP Listener Configuration"/>
    <http:request-config name="HTTP_Request_Configuration" host="www.webservicex.net#[header:INBOUND:http.request]" port="8888" doc:name="HTTP Request Configuration"/>



  <flow name="HttpProxyService">
      <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <http:request config-ref="HTTP_Request_Configuration" path="#[message.inboundProperties.'http.listener.path']" method="#[message.inboundProperties.'http.method']" doc:name="HTTP"/>
  </flow>
</mule>

This type of bridge can be combined with filters for easy message routing. For fast XPath routing of messages, you can use the SXC Module Reference.

WSProxyService

The WSProxyService allows you to serve WSDLs locally while proxying remote web services. This is handy when you have an alternate WSDL you want to service, or if you don’t want WSDL requests to be routed with all the other SOAP message requests. Any request that comes in with a "?wsdl" attached to the HTTP URL will be redirected, and the specified WSDL will be served instead.

To configure this in your flow, you must first define a WSProxyService bean with your WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">

    <spring:bean name="WSProxyService" class="org.mule.module.cxf.WSProxyService">
        <spring:property name="wsdlFile" value="localWsdl.wsdl"/>
    </spring:bean>

Next, define your service bridge to use this component:

<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8080" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="acme.come" port="8080" basePath="remote/web/service" doc:name="HTTP Request Configuration"/>


<flow name="HttpWebServiceBridge">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/my/service" doc:name="HTTP"/>
        <component>
         <spring-object bean="WSProxyService" />
        </component>
        <http:request config-ref="HTTP_Request_Configuration" path="#[message.inboundProperties.'http.listener.path']" method="#[message.inboundProperties.'http.method']" doc:name="HTTP"/>
</flow>

Now any request to "http://localhost:8080/my/service?wsdl" will cause your WSDL to be served.

Using CXF Proxy

While many times you can proxy web services without using CXF, 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

See the Proxying Web Services with CXF for more details.