I'm creating a sequence in WSO2 Api Manager which needs to receive a request A, transform this request to B and send it to a service S1. When response comes I need to update some elements of the original request based on the response body and send it to the service S2.
I was trying to build such sequence, and I'm almost there. The only problem I have is the 2nd part: my headers are lost and they are not passed to the S2 (but they are passed to S1). How can preserve headers in this second call, or maybe I'm doing something incorrectly?
orignial RQ -> build a new RQ -> send to S1 -> enrich the original RQ -> send to S2
<sequence name="CustomSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="json-eval($.)" name="Message" scope="default" type="STRING"/>
<class description="MyCustomMediator" name="com.sample.MyCustomMediator"/>
<payloadFactory description="MyRequestUpdater" media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="get-property('MY_SECRET_DATA')"/>
</args>
</payloadFactory>
<call>
<endpoint>
<http method="post" trace="disable" uri-template="https://<url to service S1>"/>
</endpoint>
</call>
<property expression="json-eval($.)" name="ResponseFromS1" scope="default" type="STRING"/>
<class description="MyCustomMediator2" name="com.sample.MyCustomMediator2"/>
<send>
<endpoint>
<http trace="disable" uri-template="http://<url to service S2>"/>
</endpoint>
</send>
</sequence>
Save your Headers in property and set it again before S2. S1 rewrites your headers and you need to remove headers form s1 and set your header again. for example:
<property name="header1" expression="get-property('transport','name-of-header')" type="STRING" />
<property name="header2" expression="get-property('transport','name-of-header2')" type="STRING" />
...
<S1>
<!-- this property remove all transport headers that S1 makes -->
<property action="remove" name="TRANSPORT_HEADERS" scope="axis2"/>
<property name="name-of-header" scope="transport" expression="get-property('header1')" type="STRING" />
<property name="name-of-header" scope="transport" expression="get-property('header2')" type="STRING" />
<S2>