playframework 路线只能访问两次

playframework route is only two times accessable

在我的 playframework 项目中,我有一条 GET 路线:

GET             /dashboard/issues                    @controllers.Dashboard.getBitBucketTickets()

方法如下所示:

@Singleton
public Result getBitBucketTickets() {

    String credentials = "J:Eb";
    String encoded = DatatypeConverter.printBase64Binary(credentials.getBytes());

    String json = null;
    try {
        json = new Gson().toJson(Unirest.get("https://api.bitbucket.org/1.0/repositories/t/frontend/issues?limit=5&status=new")
                .header("Authorization", "Basic " + encoded)
                .header("Content-Type", "application/json; charset=UTF-8")
                .header("Accept", "application/json; charset=UTF-8").asJson());
    } catch (UnirestException e) {
        System.out.println(e);
    }  
    return ok(json);
}

当我调用路由两次时,我无法调用它第三次。我必须重新启动项目。

在这种情况下可能有什么问题?

谢谢

我从不使用 Unirest,但是 documentation 中有一点您需要注意:

Unirest starts a background event loop and your Java application won't be able to exit until you manually shutdown all the threads by invoking:

Unirest.shutdown();

通常我用 WSClient 玩。它完美运行:https://www.playframework.com/documentation/2.5.x/JavaWS