1

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>
  • Your question is not clear. Do you want to access query params of the initial request coming into WSO2 in the out sequence? – ycr Sep 04 '22 at 17:42
  • yes, I want to use initial request info in response flow and change response payload according to it. @ycr – m.feyzollahi Sep 05 '22 at 08:11

2 Answers2

1

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>
ycr
  • 12,828
  • 2
  • 25
  • 45
  • I think we don't have inSequence and outSequence and if we have, Unfortunately I coud not use this one. but I upload two separately meditator for this and I explain it in my answer. Thank you for your help. Thank you! @ycr – m.feyzollahi Sep 05 '22 at 11:59
  • 1
    Glad it helped. Yes, since you are using API Manager you can't really alter the in-sequence and out-sequence, you have to wrap the mediators with a Sequence and use it as the `in` or `out` sequence. – ycr Sep 05 '22 at 12:04
0

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>