IllegalArgumentException with WS.url() and pipe character

ยอดดู 613 ครั้ง
ข้ามไปที่ข้อความที่ยังไม่อ่านรายการแรก

Nicholas C. Zakas

ยังไม่อ่าน,
6 ก.พ. 2554 11:30:436/2/54
ถึง play-framework
Hi there,

I'm trying to make a web service request for Facebook (OAuth2) using
WS. It generally works, but when the auth code has a pipe character in
it, I end up with an error (stack pasted below). I have verified that
the code is URL encoded, the code I use is:

public static String getTokenUrl(String code){
return "https://graph.facebook.com/oauth/access_token?
client_id=" + WS.encode(getAppId()) +
"&client_secret=" + WS.encode(getSecret()) + "&code="
+ WS.encode(code) +
"&redirect_uri=" +
WS.encode(Router.getFullUrl(callback));
}

The result of this method does have the pipe character properly
escaped. I then make the request like this:

String url = getTokenUrl(code);
WS.HttpResponse response = WS.url(url).get();

It's this last line that throws an error. I've omitted the sensitive
data in the stack trace below:

11:09:41,875 ERROR ~ java.lang.IllegalArgumentException
11:09:41,906 ERROR ~

@65cf0j89o
Internal Server Error (500) for request GET /auth/fbcallback?
code=<code omitted>

Execution exception (In /app/util/facebook/Facebook.java around line
33)
RuntimeException occured : java.lang.IllegalArgumentException

play.exceptions.JavaExecutionException:
java.lang.IllegalArgumentException
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:290)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.RuntimeException:
java.lang.IllegalArgumentException
at play.libs.ws.WSAsync$WSAsyncRequest.get(WSAsync.java:114)
at util.facebook.Facebook.getInstance(Facebook.java:33)
at controllers.Auth.fbcallback(Auth.java:28)
at
play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:413)

at
play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:408)

at play.mvc.ActionInvoker.invoke(ActionInvoker.java:182)
... 1 more
Caused by: java.lang.IllegalArgumentException
at java.net.URI.create(URI.java:842)
at
com.ning.http.util.AsyncHttpProviderUtils.createUri(AsyncHttpProvider
Utils.java:124)
at com.ning.http.client.providers.netty.NettyConnectListener
$Builder.bui
ld(NettyConnectListener.java:113)
at
com.ning.http.client.providers.netty.NettyAsyncHttpProvider.doConnect
(NettyAsyncHttpProvider.java:736)
at
com.ning.http.client.providers.netty.NettyAsyncHttpProvider.execute(N
ettyAsyncHttpProvider.java:664)
at
com.ning.http.client.AsyncHttpClient.executeRequest(AsyncHttpClient.j
ava:467)
at com.ning.http.client.AsyncHttpClient
$BoundRequestBuilder.execute(Asyn
cHttpClient.java:227)
at play.libs.ws.WSAsync$WSAsyncRequest.get(WSAsync.java:111)
... 6 more
Caused by: java.net.URISyntaxException: Illegal character in query at
index 176:
https://graph.facebook.com/oauth/access_token?client_id=<omitted>&client_
secret=<omitted>&code=<omitted - but shows a pipe
unescaped>&redirect_uri=<omitted>
at java.net.URI$Parser.fail(URI.java:2809)
at java.net.URI$Parser.checkChars(URI.java:2982)
at java.net.URI$Parser.parseHierarchical(URI.java:3072)
at java.net.URI$Parser.parse(URI.java:3014)
at java.net.URI.<init>(URI.java:578)
at java.net.URI.create(URI.java:840)
... 13 more


So even though the pipe character is escaped, the URISyntaxException
outputs the URL as if it were not escaped (not sure if that matters).
I've tried running this code:

String url = getTokenUrl(code);
java.net.URI.create(url);

This creates no exceptions, so I'm guessing somewhere along the line,
the URI params are being decoded.

Any help greatly appreciated.

-Nicholas

Ahmet Alp Balkan

ยังไม่อ่าน,
6 ก.พ. 2554 12:33:206/2/54
ถึง play-fr...@googlegroups.com
Try not using WS.encode for the part includes `|´ character. It worked for me on facebook.

Nicholas C. Zakas

ยังไม่อ่าน,
6 ก.พ. 2554 13:41:226/2/54
ถึง play-framework
Yeah, I already tried and got the same error.

-N

Nicholas C. Zakas

ยังไม่อ่าน,
6 ก.พ. 2554 13:57:186/2/54
ถึง play-framework
To be clear: Facebook will accept the URL is I just paste it into the
address bar, but when I try to use WS.url(), it gives me this error.
I've also tried not encoding the pipe-containing-code before using
WS.url(), but I get the same results.

-N

On Feb 6, 12:33 pm, Ahmet Alp Balkan <ahmetalpbal...@gmail.com> wrote:

Nicholas C. Zakas

ยังไม่อ่าน,
6 ก.พ. 2554 15:39:076/2/54
ถึง play-framework
Looks like someone else already filed a bug:
http://play.lighthouseapp.com/projects/57987/tickets/582-async-http-client-140-and-javaneturisyntaxexception#ticket-582-1


On Feb 6, 1:57 pm, "Nicholas C. Zakas" <nicholas.c.za...@gmail.com>
wrote:

D0uDa

ยังไม่อ่าน,
6 ก.พ. 2554 16:03:016/2/54
ถึง play-framework
Hi,

It's an async-http-client.1.4.0 bug.

Try using the async-http-client-1.5.0.jar (https://oss.sonatype.org/
content/repositories/releases/com/ning/async-http-client/1.5.0/async-
http-client-1.5.0.jar)

On Feb 6, 9:39 pm, "Nicholas C. Zakas" <nicholas.c.za...@gmail.com>
wrote:
> Looks like someone else already filed a bug:http://play.lighthouseapp.com/projects/57987/tickets/582-async-http-c...
ตอบทุกคน
ตอบกลับผู้สร้าง
ส่งต่อ
ข้อความใหม่ 0 รายการ