Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding parameters to the endpoint url wso2 esb

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?

like image 820
Ajmal M A Avatar asked Nov 11 '13 12:11

Ajmal M A


People also ask

How do you call an endpoint in WSO2?

If you specify an endpoint, the Call mediator sends the message based on the specified endpoint. The endpoint type can be Leaf Endpoint (i.e. Address/WSDL/Default/HTTP) or Group Endpoint (i.e. Failover/Load balance/Recipient list).

What is endpoint in WSO2?

An endpoint defines an external destination for an outgoing message through WSO2 Enterprise Integrator. Typically, the endpoint is the address of a proxy service, which acts as the front end to the actual service.

What is EI in WSO2?

WSO2 Enterprise Integrator (WSO2 EI) is an open-source hybrid integration platform providing graphical and CLI tooling, integration runtimes, and monitoring with a variety of deployment options. The integration runtime engine is capable of playing multiple roles in your enterprise architecture.

What is proxy service in WSO2 ESB?

A Proxy service is a way of triggering a mediation flow defined in the ESB of WSO2 Enterprise Integrator (WSO2 EI). Alternatively, you can use REST APIs, Inbound Endpoints, Scheduled Tasks or Topics and Events. Overview of proxy services. Elements of a proxy service.


2 Answers

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.

like image 182
Ratha Avatar answered Nov 25 '22 14:11

Ratha


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>
like image 21
Jamsheer Avatar answered Nov 25 '22 14:11

Jamsheer