토큰을 얻기 위해 외부 서비스에 로그인 할 수 있도록 재생을 시작할 때 WS
청원서를 제출해야합니다. 나는 미래의 탄원을하기 위해 토큰이 필요합니다. WS 탄원서를 작성하는 방법을 알고 있습니다. 시작시 실행할 코드를 어디에 두어야할지 모르겠습니다. 이때 컨트롤러의 기능을합니다.Playframework 2.5에서 함수를 시작 및 주기적으로 호출하는 방법
이 일부 코드합니다 : 24 시간 그래서 함수에게 그 토큰을 새로 고쳐 매 12 시간마다 전화를 예를 들어 원하는 후
// login data
ObjectNode tvdbaccount = Json.newObject();
tvdbaccount.put("apikey", "*****");
tvdbaccount.put("username", "*****");
tvdbaccount.put("userkey", "*****");
// try to login
String token = "";
CompletionStage<JsonNode> request = WS.url("https://api.thetvdb.com/login")
.post(tvdbaccount)
.thenApply(WSResponse::asJson);
try {
JsonNode response = request.toCompletableFuture()
.get(5, TimeUnit.SECONDS);
token = response.get("token").asText();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
그 토큰이 만료을. 이 기능은 이전의 기능과 비슷합니다. 단지 WS 탄원서 일뿐입니다.
나는 GlobalSettings
가 사용되지 않으며 여기에 2.5에 대한 답변이 여러 개 표시되지 않으므로 완료하지 못했습니다.
추가 된 코드는 내가 당신에게 할 수 있습니다 – rcanovas
뭘하는지 보여
그럼,이 모듈을 바인더 제본 다음을보십시오 : https://stackoverflow.com/questions/31007478/was-asynchronous-jobs-removed-from-the-play-framework-what-is-a-better-alternat/31019858#31019858 2.5와 마찬가지로, Eager Singletons는 사용 중지 된 GlobalSettings 대신 시작시 사용할 것입니다. . 마이그레이션 가이드도 참조하십시오. https://www.playframework.com/documentation/2.5.x/GlobalSettings#Java –
작업을 반복하여 토큰을 가져 오면 매 12 분마다 호출되는 시작시 열심히 바인딩에서 액터를 만들 수 있습니다 시간은 정기적으로 실행되는 작업에 대한 https://www.playframework.com/documentation/2.5.x/JavaAkka#Scheduling-asynchronous-tasks의 문서를 참조하십시오. –