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