【问题标题】:how to catch timeout exception in async WSRequest in Play framework 2.x?如何在 Play 框架 2.x 中的异步 WSRequest 中捕获超时异常?
【发布时间】:2014-04-11 00:19:17
【问题描述】:

我试图在 Play 框架 2.1.x 的委托中捕获 TimeoutException,我的代码如下所示:

WSRequestHolder request = WS.url(url).setAuth(username,password);
Promise<WS.Response> response = request.get();
    response.onRedeem(new Callback<WS.Response>(){
    public void invoke(WS.Response response) {
        int status = response.getStatus();
        Logger.info("Sending result");
        Logger.info(response.getBody());
    }
});

在 Play 中,默认超时值为 120000 毫秒,我想捕获该超时异常。我尝试使用 try-catch 块,但它似乎不起作用。任何人都可以帮忙吗?我应该改用计时器吗?

【问题讨论】:

    标签: asynchronous playframework playframework-2.0 timeout


    【解决方案1】:

    您可以使用Promise 的以下方法之一处理TimeoutException 异常:onFailurerecoverrecoverWith

    【讨论】:

      猜你喜欢
      • 2018-04-29
      • 1970-01-01
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      • 1970-01-01
      相关资源
      最近更新 更多