4
votes

I have to mapping query params to send request to endpoint in API resource in WSO2 ESB.

Those query params are optional. For example, the following are examples of calls to resource:

http://server:port/service?q1={q1}
http://server:port/service?q2={q2}&q3={q3}

I need to have a single resource to do this.

How can I do this?

Basically, I have to read query params in request and put it in the call to endpoint uri.

1

1 Answers

6
votes

You can have dynamic URIs using url-mapping attribute.

Here is an example:

<api xmlns="http://ws.apache.org/ns/synapse" name="test_api" context="/testService">
   <resource methods="GET" url-mapping="/*">
      <inSequence>
         <log level="full">
            <property name="paramQ1" expression="$ctx:query.param.q1"></property>
            <property name="paramQ2" expression="$ctx:query.param.q2"></property>
            <property name="paramQ3" expression="$ctx:query.param.q3"></property>
         </log>
         <send>
            <endpoint>
               <address uri="http://localhost:9766/services/"></address>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send></send>
      </outSequence>
   </resource>
</api>

To validate the presence of those query params its possible to use Filter Mediator. A good example of it can be found here.

Hope it helps.