user3012653
user3012653

Reputation: 93

How to retain inbound properties across transport barrier

I am building a restful proxy using mule where I have a need to call two web services in a single flow. The call to the first WS is supposed to do user authentication and if the authentication succeeds, then the ORIGINAL HTTP request will be proxied to the correct REST end point by a second WS call. I have a problem after the first authentication web service call returns. When this call returns, the original HTTP request is lost.

How do I retain the original HTTP request that comes in, save it across the first authentication web service call and then set the original headers just before the second web service call?

Please suggest to me the right approach to achieve this.

Upvotes: 0

Views: 1223

Answers (4)

user1760178
user1760178

Reputation: 6697

I would suggest to go with enricher in this case.

The scenario here looks like the first call is only to authenticate. So use and enricher to call the first WS and save the response as a flow varaible.

This way u still have your payload and all the properties same as they came in from the original request. You can the enriched flow varaible to decide on whether to call the second WS or not.

Here is a sample flow.

<flow>
    <http:inbound  ... />
    ...
    <enricher target="#[variable:authenticationSuccessful]" source="#[payload]" >
        <processor-chain>
            <!--  YOu call to first WS and then the status whether authentication is succesful or not.
        </processor-chain>
    </enricher>

    <choice>
        <when expression="#[flowVars['authenticationSuccessful']]" />
            <http:outbound  to second WS />
        </when>
        <otherwise>
            <logger level="INFO" message="Authentication Failed" />
        </otherwise>
    </choice>
</flow>

Hope this helps.

Upvotes: 1

justin.saliba
justin.saliba

Reputation: 734

As the Mohan and Anirban suggested, you're able to make use of flow variables or session variables to keep a reference to your HTTP request. I suggest using flow variables since session variables are serialized and sent off as part of the message.

You can also make use of the enricher scope to "enrich" your current Mule message with the data from the first HTTP request.

Upvotes: 0

Anirban Sen Chowdhary
Anirban Sen Chowdhary

Reputation: 8311

As Mohan suggested save the inbound properties in variables.. There are 2 type of variables in Mule :- 1) Flow Variables 2) Session variables

So as per your requirement if you want to retain your inbound properties across the transport barrier then use Session variable as it is global and can be used in any of the flows

Flow variables on the other hand in local to the flow in which it is defined..

You can check this to see how to save in a variable :- http://www.mulesoft.org/documentation/display/current/Variable+Transformer+Reference

Upvotes: 0

Mohan
Mohan

Reputation: 520

save the original request in flow variable before the first web-service call. After first web-service call drag set-payload component to flow and assign the value to it from the flow variable which contains the original request.

Upvotes: 0

Related Questions