Search code examples
javaplayframeworkbitbucketunirest

playframework route is only two times accessable


in my playframework project I've got a GET route:

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

The Method looks like this:

@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);
}

When I call the Route two Times I can't call it a thrid time. I have to restart the project.

What could be a problem in this case?

Thanks


Solution

  • I never use Unirest, but there is a point in the documentation that you need to be aware of:

    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();

    Usually I use WSClient with Play. It works perfectly: https://www.playframework.com/documentation/2.5.x/JavaWS