Adding parameters to the endpoint url wso2 esb

Ajmal M A picture Ajmal M A · Nov 11, 2013 · Viewed 9.6k times · Source

I am new to the WSO2 esb. I want to create a api in which i want to add a dynamic parameter from api Url to endpoint url.

My end point url is like http://example.com/api/sync/{session_id}.json

I tried to create api like

<api name="rest" context="/sync">
          <resource methods="GET" uri-template="/{id}">
             <inSequence>
             <log level="full">
                <property xmlns:ns="http://org.apache.synapse/xsd"
                          name="uri.var.session"
                          expression="get-property('uri.var.id')"
                          scope="axis2"/>
                </log>
                <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
                <send>
                   <endpoint name="Mecars">
                      <http trace="enable"
                            method="get"
                            uri-template="http://example.com/sync/{+uri.var.session}.json"/>
                   </endpoint>
                </send>
            </inSequence>
          </resource>
       </api>

In log i get the value of uri.var.session But on the endpoint Uri-template it is not appending.

Please guid me how append the {id} value in the api uri-template to end point uri-template?

Answer

Ratha picture Ratha · Jan 2, 2014

Check this sample I recommend you to do string concatenation at property mediator adn use that directly at uri-template, rather adding "variable +.json" at uri-template.

That is;

<property xmlns:ns="http://org.apache.synapse/xsd"
                          name="uri.var.session"
                          expression="get-property('uri.var.id')"
                          scope="axis2"/>

In the above for expression do string concatenation to construct full variable with ".json" ending.