propertiesmuleinbound

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.


Solution

  • 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.