Displaying optional request parameters in a WSO2 ESB API resource

I need to match request parameters in order to send a request to an endpoint to an API resource in WSO2 ESB.

These request parameters are optional. For example, the following examples of calls to a resource:

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

      

I need to have a single resource for this.

How can i do this?

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

+3


source to share


1 answer


You can have dynamic URIs using the url-mapping attribute .

Here's 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>

      



You can use Filter Mediator to check for the presence of these query parameters . A good example of this can be found here .

Hope it helps.

+4


source







All Articles