http-headersendpointwso2-micro-integrator

Get value of header in WSO2 Micro Integrator endpoint response


We have an HTTP endpoint of WSO2 Micro Integrator. This mediator points to an REST API that returns a 201 message with a validation token (it is a login sequence). The token is not included in the JSON body, but in a special custom header of the response message (called X-Subject_Token). How can I get this header of the response? Thanks in advance

In fact, I have obtained values of JSON body fields easily, but I cannot see any procedure to do the same with headers values. Browsing official documentation gave no result, as well as search in the Internet. Therefore, no tries so far, as I do not know how to start.


Solution

  • You can use the get-property('transport','HEADER_NAME') expression to get any header value. In your case it will be as follows,

    <call>
        <endpoint>
            <http method="get" uri-template="http://localhost:5000/api/pet1"/>
        </endpoint>
    </call>
    <property name="TOKEN_HEADER" expression="get-property('transport','X-Subject_Token')"/>
    <log category="INFO" level="custom">
        <property name="TOKEN_HEADER" expression="$ctx:TOKEN_HEADER"/>
    </log>
    

    For more information about the expressions and scopes, refer the documentation https://mi.docs.wso2.com/en/latest/reference/synapse-properties/scopes/#transport-scope