[Play 2.1-RCx] Docs changes required

110 views
Skip to first unread message

Sarvesh Kumar Singh

unread,
Feb 2, 2013, 7:30:04 PM2/2/13
to play-fr...@googlegroups.com
So the WS documentation of Play-2.1-RCx says,

"Any calls made by play.api.libs.ws.WS should return a Promise[play.api.libs.ws.Response] which we can later handle with Play’s asynchronous mechanisms."

But starting from Play 2.1, WS is returning scala.concurrent.Future.

Also there are many other docs where the changes are required owing to the shift to scala.concurrent.Future .

Sarvesh Kumar Singh

unread,
Feb 2, 2013, 7:36:17 PM2/2/13
to play-fr...@googlegroups.com
Also, how can I achieve a behaviour similar to this using new WS api..? ,

    WS.url(url).post(postParams).await(10000).fold( onError =>
      {
        Logger.error("timed out)
        throw new Exception()
      },
      response =>  doSomethingUseful(response)
    )

Sarvesh Kumar Singh

unread,
Feb 2, 2013, 9:06:35 PM2/2/13
to play-fr...@googlegroups.com
I ended up doing this.. please guide me if there is a more similar way to do this,

    // the "Future" reply
    val replyFuture = WS.url(url).post(postParams)

    try {
      val awaitedReply = Await.result(replyFuture, Duration(10000, "millis"))
      return doSomethinUseful(awaitedReply)
    } catch {
      case te: TimeoutException => {
        Logger.error("timed out)
        throw new CustomException()
      }
    }

Nilanjan Raychaudhuri

unread,
Feb 3, 2013, 9:42:33 AM2/3/13
to play-fr...@googlegroups.com
The docs will be updated before 2.1 release. Now coming back to your await question.Could we avoid Await and replace it with an AsyncResult? The problem with Await is it will block a thread. Only place Await.result should be applicable is in test.

Nilanjan, Developer & Consultant
Typesafe Inc.
Twitter: @nraychaudhuri

Sarvesh Kumar Singh

unread,
Feb 4, 2013, 7:40:45 AM2/4/13
to play-fr...@googlegroups.com
It is a part of the getAccessToken() method for the facebook connectivity part of the app.

I could not figure out how can I use AsyncResult in OAuth2 flow so I used Await even though it is blocking.

I want to wait for the response for 10 seconds maximum and 

  • throw timout exception if I don't get the response within this time period.
  • If I get a response form facebook then I will proceed as the OAuth2 implementation works .

Any ideas?

regards,
Sarvesh

Gaëtan Renaudeau

unread,
Feb 4, 2013, 7:49:55 AM2/4/13
to play-fr...@googlegroups.com
With Play 2.1, If you want to achieve a 10 seconds maximum request time with WS, just use:

    WS.url(...).withTimeout(10000)


Note:
It's maybe not obvious but the current WS "timeout" is the total request timeout, which mean even if you are getting a response it will be kill if the time is reached and throw a timeout exception.
( BTW this is a purpose to make it more straightforward: https://github.com/playframework/Play20/pull/638/files )

Regards,
gre


2013/2/4 Sarvesh Kumar Singh <sarve...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Gaëtan Renaudeau, greweb.fr

adel alfar

unread,
Feb 4, 2013, 11:05:34 AM2/4/13
to play-fr...@googlegroups.com
Can you please tell me what is the equivalent Java API to accomplish the same effect?  Thanks!

Nilanjan Raychaudhuri

unread,
Feb 4, 2013, 12:27:35 PM2/4/13
to play-fr...@googlegroups.com
you can use setTimeout(...) or configure the timeout in the conf file using the ws.timeout property


Nilanjan, Developer & Consultant
Typesafe Inc.
Twitter: @nraychaudhuri

adel alfar

unread,
Feb 4, 2013, 4:01:55 PM2/4/13
to play-fr...@googlegroups.com
Thanks Nilanjan!  I guess using the conf property will apply it to all WS calls...while setTimeout(...) will set it in a case-by-case bases....

Nilanjan Raychaudhuri

unread,
Feb 4, 2013, 4:04:31 PM2/4/13
to play-fr...@googlegroups.com
yes

Sarvesh Kumar Singh

unread,
Feb 5, 2013, 12:44:20 AM2/5/13
to play-fr...@googlegroups.com
Oh... thanks a lot.
Reply all
Reply to author
Forward
0 new messages