7
votes

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?

4
where is your uri.var.session defined? in the example above it is not visible... did you try to log uri.var.session in order to see if it's not empty?Laimoncijus
uri.var.session is a property variable. and i tried to assign the value of uri.var.id to uri.var.session. I logged the value and it shows uri.var.session = 123 ( The id value ).Ajmal M A

4 Answers

4
votes

Please remove the '+' symbol from your http end point.Its working fine to me

sample API

   <api xmlns="http://ws.apache.org/ns/synapse" name="Elastic Search Using NPI"     context="/api/npi/professional/npi.json">
 <resource methods="OPTIONS GET" uri-template="/{npi}">
    <inSequence>
       <log level="full">
        <property name="uri.var.npi" expression="get-property('uri.var.npi')"></property>
      </log>
     <send>
        <endpoint>
           <http method="get" uri-template="example.com/{uri.var.npi}"></http>
        </endpoint>
     </send>
    </inSequence>     
  </resource>
</api>
5
votes

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.

3
votes

Change the http endpoint uri template like follows.

<http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>

Following is the modified api configuration.

<api xmlns="http://ws.apache.org/ns/synapse" 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')"></property>
     </log>
     <property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
     <send>
        <endpoint name="Mecars">
           <http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>
        </endpoint>
     </send>
  </inSequence>
 </resource>
</api>
1
votes

You can do the string concatenation at the property mediator as follows.

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