Adding parameters to the endpoint url wso2 esb
Asked Answered
P

4

7

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?

Pleione answered 11/11, 2013 at 12:23 Comment(2)
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?Myrica
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 ).Pleione
T
4

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>
Tussore answered 18/3, 2014 at 10:47 Comment(3)
How to prevent ESB from replacing special characters in curly brackets? Etc., I want yo use {uri.var.query} that has a value ?text=Test, but ? and = are replaced by %3F and %3D.Taiga
use {+uri.var.query} to prevent the encoding.Pouter
Can this + sign be used in logger? etc., something like this: expression="get-property('{+uri.var.query}')"/>?Taiga
V
5

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.

Vicenta answered 2/1, 2014 at 8:59 Comment(0)
T
4

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>
Tussore answered 18/3, 2014 at 10:47 Comment(3)
How to prevent ESB from replacing special characters in curly brackets? Etc., I want yo use {uri.var.query} that has a value ?text=Test, but ? and = are replaced by %3F and %3D.Taiga
use {+uri.var.query} to prevent the encoding.Pouter
Can this + sign be used in logger? etc., something like this: expression="get-property('{+uri.var.query}')"/>?Taiga
S
3

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>
Saxophone answered 7/1, 2014 at 17:58 Comment(0)
O
1

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"/>
Oxidate answered 22/3, 2014 at 4:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.