[Dev] How can we send query parameters with http endpoint in WSO2 ESB?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Dev] How can we send query parameters with http endpoint in WSO2 ESB?

Chanaka Fernando
Hi,

I am trying to send some query parameters with http endpoint which is defined as below.

<api xmlns="http://ws.apache.org/ns/synapse" name="SampleAPI" context="/sample">
   <resource methods="GET">
      <inSequence>
         <property name="uri.var.version" expression="get-property('transport','Version')" scope="default" type="STRING"></property>
         <send>
            <endpoint>
               <http method="get" uri-template="<a href="http://localhost:8280/TestAPI/{uri.var.version}">http://localhost:8280/TestAPI/{uri.var.version}"></http>
            </endpoint>
         </send>
      </inSequence>
   </resource>
</api>


In the above REST API, I am getting the "version" information from the header and recreate the URL with uri-template and send the request to the appropriate URL. When I am calling this endpoint, I need to send some query parameters to the actual REST endpoint. I am calling this REST API as below.

Ex: http://localhost:8280/sample?a=2&b=3

I need this should be translated in to the below URL from my REST API.

http://localhost:8280/TestAPI/2.0.0?a=2&b=3


But the issue is, the query parameters are not getting passed in to the backend REST endpoint.

Is this a limitation in the uri-template support in the WSO2 ESB or how can I achieve this?


Thanks,
Chanaka

--
--
Chanaka Fernando
Technical Lead
WSO2, Inc.; http://wso2.com
lean.enterprise.middleware

mobile: +94 773337238
Blog : http://soatutorials.blogspot.com
LinkedIn:http://www.linkedin.com/pub/chanaka-fernando/19/a20/5b0
Twitter:https://twitter.com/chanakaudaya
Wordpress:http://chanakaudaya.wordpress.com




_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: [Dev] How can we send query parameters with http endpoint in WSO2 ESB?

Chanaka Fernando
After going through the source code, I found this comment in the Axis2FlexibleMEPClient.Java file.

            // HTTP Endpoint : use the specified HTTP method and remove REST_URL_POSTFIX, it's not supported in HTTP Endpoint
            if (endpoint.isHTTPEndpoint()) {
                axisOutMsgCtx.setProperty(Constants.Configuration.HTTP_METHOD, synapseOutMessageContext.getProperty(Constants.Configuration.HTTP_METHOD));
                axisOutMsgCtx.removeProperty(NhttpConstants.REST_URL_POSTFIX);
            }

Which means we are not supporting REST_URL_POSTFIX for http-endpoints.


Is there any workaround that we can achieve this?


On Fri, Jan 17, 2014 at 2:15 PM, Chanaka Fernando <[hidden email]> wrote:
Hi,

I am trying to send some query parameters with http endpoint which is defined as below.

<api xmlns="http://ws.apache.org/ns/synapse" name="SampleAPI" context="/sample">
   <resource methods="GET">
      <inSequence>
         <property name="uri.var.version" expression="get-property('transport','Version')" scope="default" type="STRING"></property>
         <send>
            <endpoint>
               <http method="get" uri-template="http://localhost:8280/TestAPI/{uri.var.version}"></http>
            </endpoint>
         </send>
      </inSequence>
   </resource>
</api>


In the above REST API, I am getting the "version" information from the header and recreate the URL with uri-template and send the request to the appropriate URL. When I am calling this endpoint, I need to send some query parameters to the actual REST endpoint. I am calling this REST API as below.

Ex: http://localhost:8280/sample?a=2&b=3

I need this should be translated in to the below URL from my REST API.

http://localhost:8280/TestAPI/2.0.0?a=2&b=3


But the issue is, the query parameters are not getting passed in to the backend REST endpoint.

Is this a limitation in the uri-template support in the WSO2 ESB or how can I achieve this?


Thanks,
Chanaka

--
--
Chanaka Fernando
Technical Lead
WSO2, Inc.; http://wso2.com
lean.enterprise.middleware

mobile: <a href="tel:%2B94%20773337238" value="+94773337238" target="_blank">+94 773337238
Blog : http://soatutorials.blogspot.com
LinkedIn:http://www.linkedin.com/pub/chanaka-fernando/19/a20/5b0
Twitter:https://twitter.com/chanakaudaya
Wordpress:http://chanakaudaya.wordpress.com






--
--
Chanaka Fernando
Technical Lead
WSO2, Inc.; http://wso2.com
lean.enterprise.middleware

mobile: +94 773337238
Blog : http://soatutorials.blogspot.com
LinkedIn:http://www.linkedin.com/pub/chanaka-fernando/19/a20/5b0
Twitter:https://twitter.com/chanakaudaya
Wordpress:http://chanakaudaya.wordpress.com




_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: [Dev] How can we send query parameters with http endpoint in WSO2 ESB?

Kasun Indrasiri-2
Hi Chanaka,

HTTP Endpoint can connect with any RESTful BE with any preferred URI template. There is no need of using REST_URL_POST with HTTP endpoint (after all, the reason for introducing HTTP EP to get rid of such tweaks when doing RESTful integration) 

Please check the following example would address your requirement. (ESB 4.8)
<endpoint>
 <http method="get" uri-template="http://127.0.0.1:9764/pizzashop-rs_1.0/services/menu/pizza?q={query.param.val}&type={query.param.type}"></http>
</endpoint>


On Sat, Jan 18, 2014 at 1:24 AM, Chanaka Fernando <[hidden email]> wrote:
After going through the source code, I found this comment in the Axis2FlexibleMEPClient.Java file.

            // HTTP Endpoint : use the specified HTTP method and remove REST_URL_POSTFIX, it's not supported in HTTP Endpoint
            if (endpoint.isHTTPEndpoint()) {
                axisOutMsgCtx.setProperty(Constants.Configuration.HTTP_METHOD, synapseOutMessageContext.getProperty(Constants.Configuration.HTTP_METHOD));
                axisOutMsgCtx.removeProperty(NhttpConstants.REST_URL_POSTFIX);
            }

Which means we are not supporting REST_URL_POSTFIX for http-endpoints.


Is there any workaround that we can achieve this?


On Fri, Jan 17, 2014 at 2:15 PM, Chanaka Fernando <[hidden email]> wrote:
Hi,

I am trying to send some query parameters with http endpoint which is defined as below.

<api xmlns="http://ws.apache.org/ns/synapse" name="SampleAPI" context="/sample">
   <resource methods="GET">
      <inSequence>
         <property name="uri.var.version" expression="get-property('transport','Version')" scope="default" type="STRING"></property>
         <send>
            <endpoint>
               <http method="get" uri-template="http://localhost:8280/TestAPI/{uri.var.version}"></http>
            </endpoint>
         </send>
      </inSequence>
   </resource>
</api>


In the above REST API, I am getting the "version" information from the header and recreate the URL with uri-template and send the request to the appropriate URL. When I am calling this endpoint, I need to send some query parameters to the actual REST endpoint. I am calling this REST API as below.

Ex: http://localhost:8280/sample?a=2&b=3

I need this should be translated in to the below URL from my REST API.

http://localhost:8280/TestAPI/2.0.0?a=2&b=3


But the issue is, the query parameters are not getting passed in to the backend REST endpoint.

Is this a limitation in the uri-template support in the WSO2 ESB or how can I achieve this?


Thanks,
Chanaka

--
--
Chanaka Fernando
Technical Lead
WSO2, Inc.; http://wso2.com
lean.enterprise.middleware

mobile: <a href="tel:%2B94%20773337238" value="+94773337238" target="_blank">+94 773337238
Blog : http://soatutorials.blogspot.com
LinkedIn:http://www.linkedin.com/pub/chanaka-fernando/19/a20/5b0
Twitter:https://twitter.com/chanakaudaya
Wordpress:http://chanakaudaya.wordpress.com






--
--
Chanaka Fernando
Technical Lead
WSO2, Inc.; http://wso2.com
lean.enterprise.middleware

mobile: <a href="tel:%2B94%20773337238" value="+94773337238" target="_blank">+94 773337238
Blog : http://soatutorials.blogspot.com
LinkedIn:http://www.linkedin.com/pub/chanaka-fernando/19/a20/5b0
Twitter:https://twitter.com/chanakaudaya
Wordpress:http://chanakaudaya.wordpress.com






--
Kasun Indrasiri
Software Architect
WSO2, Inc.; http://wso2.com
lean.enterprise.middleware

cell: +94 77 556 5206
Blog : http://kasunpanorama.blogspot.com/

_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: [Dev] How can we send query parameters with http endpoint in WSO2 ESB?

chanaka777
In reply to this post by Chanaka Fernando
Hi Chanaka,
As you mentioned in your example your uri.var.version value should be "2.0.0?a=2&b=3". But if you check your wire log you may be see url encoded version of the above appended string (2.0.0%3Fa%3D2%26b%3D3). Due to this, end point will not be able to identify your query parameters. Instead, try some thing like following uri-template.
uri-template="http://localhost:8280/TestAPI/{uri.var.version}?a={uri.var.a}&b={uri.var.b}"
Regards !
--
Chanaka Dharmarathna