Proxying Web Services
Mule can act as a Web Service gateway/proxy. Gateways can 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
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.
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:
1 <?xml version="1.0" encoding="UTF-8"?><mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:http="http://www.mulesoft.org/schema/mule/http" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.1/mule-http.xsd"> <flow name="HttpProxyService"> <http:inbound-endpoint address="+http://localhost:8888+" exchange-pattern="request-response"/> <http:outbound-endpoint address="http://www.webservicex.net#[header:INBOUND:http.request]" exchange-pattern="request-response"/> </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.
Alternatively, you can use Bridge Pattern.
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 for your service, you must first define a WSProxyService bean with your WSDL:
1 <?xml version="1.0" encoding="UTF-8"?><mule xmlns="http://www.mulesoft.org/schema/mule/core/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:http="http://www.mulesoft.org/schema/mule/http/2.2" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.mulesoft.org/schema/mule/core/2.2 http://www.mulesoft.org/schema/mule/core/2.2/mule.xsd http://www.mulesoft.org/schema/mule/http/2.2 http://www.mulesoft.org/schema/mule/http/2.2/mule-http.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:
1 <service name="HttpWebServiceBridge"> <inbound> <inbound-endpoint address="http://localhost:8080/my/service" synchronous="true"/> </inbound> <component> <spring-object bean="WSProxyService" /> </component> <outbound> <chaining-router> <outbound-endpoint address="http://acme.come/remote/web/service" synchronous="true"/> </chaining-router> </outbound></service>
Now any request to "http://localhost:8080/my/service?wsdl" will cause your WSDL to be served.
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.