Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

WS post problem

853 views
Skip to first unread message

Eric Jacob

unread,
Apr 8, 2011, 10:13:29 AM4/8/11
to play-framework
Hi players,

I'm trying to post a form using the WS library. But so far, I'm unable
to make it works.

This code:

String formParams = WS.encode("access_token=" + getAccessToken() +
"&message=Hello World!");
WS.url("https://graph.facebook.com/me/
feed").body(formParams).mimeType("multipart/form-data").post();

Gives me the following error:

RuntimeException occured : java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected

play.exceptions.JavaExecutionException: java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:285)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.post(WSUrlFetch.java:58)
at controllers.Application.writeReview(Application.java:63)
at
play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:408)
at
play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:403)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:176)
... 1 more
Caused by: java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.prepare(WSUrlFetch.java:126)
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.post(WSUrlFetch.java:56)
... 5 more
Caused by: java.lang.IllegalStateException: Already connected
at
sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:
2371)
at
sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestProperty(HttpsURLConnectionImpl.java:
296)
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.checkFileBody(WSUrlFetch.java:170)
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.prepare(WSUrlFetch.java:113)
... 6 more

However, it works as expected using the Apache HttpClient library:

List<NameValuePair> formParams = new ArrayList<NameValuePair>();
formParams.add(new BasicNameValuePair("access_token",
getAccessToken()));
formParams.add(new BasicNameValuePair("message", "Hello World!"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams,
"UTF-8");
HttpPost post = new HttpPost("https://graph.facebook.com/me/feed");
post.setHeader("Content-Type", "multipart/form-data");
post.setEntity(entity);
HttpClient client = new DefaultHttpClient();
org.apache.http.HttpResponse resp = (org.apache.http.HttpResponse)
client.execute(post);

Did I miss something about the WS library and the post method? Is
there a bug?

I'm using Play! 1.1.

Thank you in advance for your help.

Eric

Guillaume Bort

unread,
Apr 8, 2011, 1:03:28 PM4/8/11
to play-fr...@googlegroups.com
Why is it using WSUrlfetch? Have you configured something special?

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

Eric Jacob

unread,
Apr 8, 2011, 1:12:32 PM4/8/11
to play-framework
Not that I am aware of... Is there something in the configuration that
I can modify to change the behaviour?
> > sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnect...
> > 2371)
> >        at
> > sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestProperty(HttpsURL...

Guillaume Bort

unread,
Apr 8, 2011, 1:21:38 PM4/8/11
to play-fr...@googlegroups.com
Do you have webservice key somewhere in your application.conf

Eric Jacob

unread,
Apr 8, 2011, 1:27:44 PM4/8/11
to play-framework
No.

What is the expected behaviour?

Guillaume Bort

unread,
Apr 9, 2011, 5:10:23 AM4/9/11
to play-fr...@googlegroups.com
It should use Async HTTP. Perhaps you have a module that force a
particular implementation of WS?

Eric Jacob

unread,
Apr 9, 2011, 11:56:29 PM4/9/11
to play-framework
Thank you Guillaume for pointing that out.

You were right, it seems to be the GAE module (v1.4) that force the
"WSUrlFetch" implementation in "GAEPlugin.java":

Play.configuration.setProperty("webservice", "urlfetch");

So now, the $100 question: Is it possible to change that? My
application will be hosted on GAE, and it needs to simulate the
process of submitting an HTML form using the HTTP "post" method.

Thank you for help, I really appreciate.

Eric

Guillaume Bort

unread,
Apr 10, 2011, 1:40:40 PM4/10/11
to play-fr...@googlegroups.com
> So now, the $100 question: Is it possible to change that? My
> application will be hosted on GAE, and it needs to simulate the
> process of submitting an HTML form using the HTTP "post" method.

Sorry it is the only implementation available on GAE. But anyway it
should work. I'll check why, can you report the issue?

Guillaume Bort

unread,
Apr 10, 2011, 1:53:30 PM4/10/11
to play-fr...@googlegroups.com
Ok I think that it is fixed in the master. Can you try it? (commit
67339058874782989a3f4e4250514423dbad302e)

Erwan Loisant

unread,
Apr 11, 2011, 3:50:41 AM4/11/11
to play-fr...@googlegroups.com, Guillaume Bort
There is a GAE specific API to do asynchronous calls. We could
implement a GAE-specific implementation and include it in the GAE
module.

http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/urlfetch/URLFetchService.html

--
Erwan Loisant

Eric Jacob

unread,
Apr 11, 2011, 8:21:21 AM4/11/11
to play-framework
Hi Guillaume,

Thank you for your fix, it works now.

Eric


On Apr 10, 1:53 pm, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> Ok I think that it is fixed in the master. Can you try it? (commit
> 67339058874782989a3f4e4250514423dbad302e)
>
> On Sun, Apr 10, 2011 at 7:40 PM, Guillaume Bort
>
>
>
> <guillaume.b...@gmail.com> wrote:
> >> So now, the $100 question: Is it possible to change that? My
> >> application will be hosted on GAE, and it needs to simulate the
> >> process of submitting an HTML form using the HTTP "post" method.
>
> > Sorry it is the only implementation available on GAE. But anyway it
> > should work. I'll check why, can you report the issue?
>
> Guillaume Bort,http://guillaume.bort.fr

kus

unread,
Jun 2, 2011, 4:15:48 PM6/2/11
to play-framework
Hello,

I have the same problem... Yet I use play 1.2.1, gae 1.4 and fbgraph
0.3... I don't understand and I can't find your commit
67339058874782989a3f4e4250514423dbad302e ...

do you have an idea ?

Thinks,

Another Guillaume

Eric Jacob

unread,
Jun 6, 2011, 9:39:48 AM6/6/11
to play-framework
Hi Guillaume,

I didn't test extensively, but I'm using fbgraph-0.3 with play-1.2.1
and gae-1.4 without any issue so far. Can you elaborate a little more?

Thank you.

Eric

kus

unread,
Jun 7, 2011, 2:21:03 AM6/7/11
to play-framework
ok, the connection works fine.
The problem happens when I want to post a message on the wall of the
user.

I use this method :

private static void sendMessage(String msg) {
try {
FbGraph.publish("me/feed", Parameter.with("message", msg)
.parameters());
} catch (FbGraphException e) {
Logger.warn("Send Message exception", e.getMessage());
}
}

And I have RuntimeException occured : java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected

I may have forgotten something?
Thinks,
Guillaume

kus

unread,
Jun 7, 2011, 11:21:30 AM6/7/11
to play-framework
Ok, sorry...
I found the problem...

private static void sendMessage(String msg) {
FacebookClient client = FbGraph.getFacebookClient();
client.publish("me/feed", FacebookType.class,
com.restfb.Parameter.with("message", msg));
}

Thinks, Guillaume

Eric Jacob

unread,
Jun 8, 2011, 9:54:00 AM6/8/11
to play-framework
The workaround is to use the RestFB client provided with the FbGraph
module.

But you were right, I tried to post a message with play-1.2.1,
fbgraph-0.3 and gae-1.4, and I got a the RuntimeException again.

Execution exception (In /app/controllers/Application.java around line
74)
RuntimeException occured : java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected

play.exceptions.JavaExecutionException: java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:227)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.post(WSUrlFetch.java:60)
at play.modules.facebook.FbGraph.makeRequest(FbGraph.java:122)
at play.modules.facebook.FbGraph.oauthRequest(FbGraph.java:
145)
at play.modules.facebook.FbGraph.api(FbGraph.java:162)
at play.modules.facebook.FbGraph.publish(FbGraph.java:368)
at controllers.Application.facebookPublishing(Application.java:
74)
at
play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:540)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:498)
at
play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:474)
at
play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:469)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:157)
... 1 more
Caused by: java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.prepare(WSUrlFetch.java:135)
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.post(WSUrlFetch.java:57)
... 11 more
Caused by: java.lang.IllegalStateException: Already connected
at
sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:
2378)
at
sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestProperty(HttpsURLConnectionImpl.java:
296)
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.checkFileBody(WSUrlFetch.java:180)
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.prepare(WSUrlFetch.java:127)
... 12 more

Guillaume Bort: It seems that there's a regression bug in play-1.2.1.
Is it possible to look at that? And as previously mentioned by the
other Guillaume, I can't find your commit
67339058874782989a3f4e4250514423dbad302e either...

Thank you.

Eric
Reply all
Reply to author
Forward
0 new messages