简体   繁体   中英

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>

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:q1" name="param1" scope="default" type="STRING"/>
    <log level="simple">
      <property expression="$ctx:param1" name="Params====" scope="default" type="STRING"/>
    </log>
</inSequence>

Out Sequence

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

I solved this problem by using two mediator. one for request flow and second for response flow. We can access in response flow, initial request properties.

This xml is for request flow:

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

</sequence>

This request is for response flow:

<sequence name="main">
    <log level="simple">
        <property value="response$$$$$$$$$$$$$$$$$$$$$$$$$$" name="resp" 
         scope="default"  type="STRING"/>
    </log>
    <log level="simple">
         <property expression="$ctx:firstname" name="Firstname" 
            scope="default" type="STRING"/>
    </log>
</sequence>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM