requestwso2wso2-api-managermediatorapi-manager

Extract information of request in response mediator in wso2 apim 4.1.0


I need to use some information from request such as "query params" or "headers" in response mediator. for example use url query parameter in response flow. I tried to use <"inSequence"> and <"outSequence"> but I could'nt get any result.

For example I want to use this "log mediator" in response flow. "firstname" is query param in request:

<log level="custom">
    <property name="firstname" expression="$url:firstname"/>
</log>

Solution

  • If you want to access the query parameters being sent in the original request from the out-sequence, simply set it to a property in the in-sequence. Then that property will be accessible in the out-sequence. See the example below.

    In Sequence

    <inSequence>
        <property expression="$url:firstname" name="firstname" scope="default" type="STRING"/>
        <log level="simple">
          <property expression="$ctx:firstname" name="Firstname====" scope="default" type="STRING"/>
        </log>
    </inSequence>
    

    Out Sequence

    <outSequence>
        <log level="simple">
            <property expression="$ctx:firstname" name="Firstname====" scope="default" type="STRING"/>
        </log>
        <send/>
    </outSequence>