简体   繁体   中英

await() in play 1.2.5

I am using play 1.2.5 and in that I am giving async call to REST service.

For that I have created a promise object and then have given this promise object as parameter to await() method. await() method returns me a httpResponse object.

It works fine then the REST service returns a response. But if the REST service do not respond (may be because the REST service is down) then I get a null in the httpResponse. But it takes some time to get the response back.

Can I configure the time it should wait for the rest service to respond for the promise? If not then what is the default wait time?

Any help will be greatly appreciated

如果使用play WS lib,则在WSRequest对象上有一个超时方法,您可以在该方法中定义在无响应的情况下调用返回之前所花费的时间(以秒为单位)

There is a timeout call on the WSRequest.

WS.WSRequest wsReq = WS.url("http://whatever");
wsReq.timeout("1min");

...

When you do a postAsync() , you get a promise back. You can also call promise.onRedeem() to add a handler to handle errors etc. You could use that to catch the timeout exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM