Tags

, ,

When we use REST endpoints within the Wso2 ESB REST API (or Proxy service), sometimes we need to dynamically change the endpoint context and values of the query string parameters. To achieve that kind of requirement, we can use HTTP endpoint within Wso2 ESB with URI Template. You can populate the query string parameters during mediation runtime, using property values whose names have the “uri.var.” prefix.

example:

<property name="uri.var.service.user" scope="default" type="STRING" value="testuser"/>

And then you can access that query string parameter value within the URI like below.

{uri.var.service.user}

See the following example and you can see I have set the values to query string parameters, using property mediators.
Then I have access those values within the HTTP endpoint like below.

<http method="GET" uri-template="http://localhost:9000/{uri.var.service.host}/{uri.var.service.path}?USERNAME={uri.var.service.user}&amp;PASSWORD={uri.var.service.pass}&amp;ioName={uri.var.service.wfName}"/>

Also within the API configuration, we can use “POST_TO_URI” property to make the outgoing URL of the ESB a complete URL.

API Configuration:

<api xmlns="http://ws.apache.org/ns/synapse" name="TririgaApi" context="/tririga">
<resource methods="GET" url-mapping="/employee">
<inSequence>
<log>
<property name="====== API IN =====" value="==== INSEQ ===="/>
</log>
<property name="uri.var.service.user" scope="default" type="STRING" value="testuser"/>
<property name="uri.var.service.pass" scope="default" type="STRING" value="testpasswd"/>
<property name="uri.var.service.host" scope="default" type="STRING" value="testhost"/>
<property name="uri.var.service.path" scope="default" type="STRING" value="testpath"/>
<property name="uri.var.service.wfName" scope="default" type="STRING" value="testwfName"/>
<property name="POST_TO_URI" value="true" scope="axis2"/>
<send>
<endpoint>
<http method="GET" uri-template="http://localhost:9000/{uri.var.service.host}/{uri.var.service.path}?USERNAME={uri.var.service.user}&amp;PASSWORD={uri.var.service.pass}&amp;ioName={uri.var.service.wfName}"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>

When we are invoking above API, we can see the endpoint URI like below.

http://localhost:9000/testhost/testpath?USERNAME=testuser&PASSWORD=testpasswd&ioName=testwfName

Thanks.

Advertisements