Property mediator being URL - encoded on ESB

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

Property mediator being URL - encoded on ESB

indika prasad
(Reposting)
Hi,

I am using the following Synapse template to query the LinkedIn APIs connections endpoint:

<template name="getConnections" xmlns="http://ws.apache.org/ns/synapse">
        <parameter name="accessToken"
                description="contains the security information for a login session and identifies the user, the users groups, and the users privileges" />
        <parameter name="fields"
                description="fields of the connections that are required to be returned" />


        <sequence>
                <property name="uri.var.fields" expression="$func:fields" />
               <property name="uri.var.accessToken" expression="$func:accessToken" />
               <call>
                                        <endpoint>
                                                       
                                                 <http method="get" uri-template="https://api.linkedin.com/v1/people/~/connections:({uri.var.fields})?oauth2_access_token={uri.var.accessToken}&amp;format=json" /> 
                                        </endpoint>
                                </call>

        </sequence>
</template>

Here, the uri.var.fields parameter is supposed to be sent as a comma separated list such as first-name,last-name,header.

However, when it is sent as a comma-separated list, the comma seems to get URL-encoded, causing the service call to fail.

Wire output when sending the fields first-name,last-name:

 DEBUG - wire << "GET /v1/people/~/connections:(first-name%2Clast-name)?oauth2_access_token=AQWE6N2hAjyHx9LIS6UU_0AktUN9aNN0ZFyIkUNYpSe10Vj559ppL4wur2QBOdCSOLBI3P2MEjHjV-Pz93xrZte3e2XfgrzkB30N5-twK9exifpuucMA5ZgvL7n2bpOx7dFxHfGM2eRfaoao0hKdSW1hnjL7i3GbrCeyrKhUZGECbv7agC4&format=json HTTP/1.1[\r][\n]"


Is there any way to prevent the comma from getting URL encoded?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: [Dev] Property mediator being URL - encoded on ESB

Ravi Undupitiya
The encoding is done by the URI Template library. There was a similar issue fixed to decode ':' and '/' in HTTP Endpoint. I think the correct fix is to use a decoding library that will handle all cases. 

Some thing like: 
            URL url = new URL(URLDecoder.decode(template.expand(), "UTF-8"));
            evaluatedUri = url.toURI().toString();

I've added JIRA at [1] to track this issue. 


On Tue, Dec 31, 2013 at 9:01 AM, indika prasad <[hidden email]> wrote:
(Reposting)
Hi,

I am using the following Synapse template to query the LinkedIn APIs
connections endpoint:

<template name="getConnections" xmlns="http://ws.apache.org/ns/synapse">
        <parameter name="accessToken"
                description="contains the security information for a login
session and identifies the user, the users groups, and the users privileges"
/>
        <parameter name="fields"
                description="fields of the connections that are required to
be returned" />


        <sequence>
                <property name="uri.var.fields" expression="$func:fields" />
               <property name="uri.var.accessToken"
expression="$func:accessToken" />
               <call>
                                        <endpoint>

                                                 <http method="get"
uri-template="<a href="https://api.linkedin.com/v1/people/~/connections:({uri.var.fields})?oauth2_access_token={uri.var.accessToken}&amp;amp;format=json" target="_blank">https://api.linkedin.com/v1/people/~/connections:({uri.var.fields})?oauth2_access_token={uri.var.accessToken}&amp;format=json"
/>
                                        </endpoint>
                                </call>

        </sequence>
</template>

Here, the uri.var.fields parameter is supposed to be sent as a comma
separated list such as first-name,last-name,header.

However, when it is sent as a comma-separated list, the comma seems to get
URL-encoded, causing the service call to fail.

Wire output when sending the fields first-name,last-name:

 DEBUG - wire << "GET
/v1/people/~/connections:(first-name%2Clast-name)?oauth2_access_token=AQWE6N2hAjyHx9LIS6UU_0AktUN9aNN0ZFyIkUNYpSe10Vj559ppL4wur2QBOdCSOLBI3P2MEjHjV-Pz93xrZte3e2XfgrzkB30N5-twK9exifpuucMA5ZgvL7n2bpOx7dFxHfGM2eRfaoao0hKdSW1hnjL7i3GbrCeyrKhUZGECbv7agC4&format=json
HTTP/1.1[\r][\n]"


Is there any way to prevent the comma from getting URL encoded?

Thanks.



--
View this message in context: http://wso2-oxygen-tank.10903.n7.nabble.com/Property-mediator-being-URL-encoded-on-ESB-tp90214.html
Sent from the WSO2 Development mailing list archive at Nabble.com.
_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev



--
Ravi Undupitiya
Software Engineer; WSO2 Inc.; http://wso2.com

E-mail: ravi@wso2.com
M: +94 772 930 712

Lean . Enterprise . Middleware

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

Re: [Dev] Property mediator being URL - encoded on ESB

indika prasad
This post was updated on .
Hi All,

I want to build the end point url (uri.var.query) dynamically based on the user input. I am passing the URL as below.

Template....

<call>
       <endpoint>
              <http method="get" uri-template="{uri.var.query}&amp;format=json" />
       </endpoint>
</call>

I can see the endpoint URL is encoded and invalid.
Expected Endpoint
http://localhost:8080/v1/people/~/connections?oauth2_access_token=token&start=1&count=10&format=json

Given Endpoint by ESB 
%7Buri.var.apiUrl%7D/v1/people/~/connections%3Foauth2_access_token%3D%7Buri.var.accessToken%7D%26start%3D1%26count%3D10&format=json

I have tested this in both 4.8.0 and 4.8.1 ESB versions even though it said to fix [1] in 4.8.1. I think the fix has addressed only ":" and "/". In this case we need to pass "&","{","}","=" and ",".

[1] - https://wso2.org/jira/browse/ESBJAVA-2860

Any suggession please?

Thanks
Indika Kularathne