PassoGiau PassoGiau - 2 months ago 13x
reST (reStructuredText) Question

how to chain RESTful web service calls in Mule 3.5.2

I need to retrieve a JSON structure from a RESTful web service using HTTP GET,

modify that data and POST the resulting JSON to that web service and I would appreciate a suggestion how to get hold of that JSON and provide it to the second web service call.

<http:connector name="Service-Connector_restRef" proxyHostname="" proxyPassword="" proxyPort="${Service-Connector-One.ProxyPort}" proxyUsername="" />

<http:outbound-endpoint address="http://${Service.Host}:8080/#[header:_REST_PATH]" exchange-pattern="request-response" followRedirects="true" responseTimeout="10000" connector-ref="Service-Connector_restRef">

The Mule site provide some instructions using AnypointStudio but I have to modify an existing Mule flow, so I need to work with the XML configuration file.


You can still use studio to make editing an existing flow easier. Its a simple matter to either import, or even cut and paste into a project. Doing this will give you lots of advantages. Do you have an option to move to a new runtime? If you were using a more recent runtime you can use Dateweave to transform from one JSON format to another. If you are using an older version then use Datamapper instead of the example below.

However your question was on chaining Restful HTTP calls. When you call the first restful service you'll receive a #[payload] back which you can then transform using datamapper or dataweave into a new format. You then add a new http endpoint after the transformation and the new payload will go through to it as part of the call since it follows in the flow. You'll need to ensure you set the HTTP operation appropriately on both.

Skeleton Visually: Chain Skeleton

Skeleton as XML:

<http:request-config name="HTTP_Request_Configuration_1" host="localhost" port="8082" doc:name="HTTP Request Configuration"/>
    <http:request-config name="HTTP_Request_Configuration_2" host="localhost" port="8083" doc:name="HTTP Request Configuration"/>
    <flow name="chainFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/chain" doc:name="HTTP"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <http:request config-ref="HTTP_Request_Configuration_1" path="/path1" method="GET" doc:name="HTTP"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <http:request config-ref="HTTP_Request_Configuration_2" path="/path2" method="POST" doc:name="HTTP"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>