@With
注釈スタイルで使用できるアクションを作成したいと思います。この動作はRPC呼び出しに進む必要があるので、私が正しくドキュメントを理解していれば、これをむしろ非同期の方法で記述する必要があります。JavaのPlay Framework 2.5でのアクションの構成と非同期
これは私が今までやってみましたものです:
token
は常に空で、
authenticationManager
が設定されていない、これはただの速い無意味例であるという事実を脇に置きます
public class GetUserIdAction extends play.mvc.Action.Simple {
@Override
public CompletionStage<Result> call(Http.Context context) {
String token = "";
if (StringUtils.isEmpty(token)) {
return delegate.call(context);
}
CompletionStage<Http.Context> promiseOfUpdatedContext = CompletableFuture.supplyAsync(() -> setUserIdForToken(context, token));
return promiseOfUpdatedContext.thenApply(ctx -> delegate.call(ctx));
}
private Http.Context setUserIdForToken(Http.Context context, String token) {
context.args.put("user_id", authenticationManager.getUserIdForToken(token));
// The AuthenticationManager is issuing an RPC call and thus may take some time to complete.
return context;
}
}
、私のIDEが上不平を言っていますthenApply
部分。私が理解するところでは、それはCompletionStage<Result>
を期待しており、より多くのものをCompletionStage<CompletionStage<Result>>
のようにしています。
どうすれば対処できますか?私が望むのは、コンテキストにいくつかの情報を入れてからdelegate.call
チェーンを続けることです。
私は何か愚かなことをしようとしていて、作ったアクションはすでに非同期ですか?
に追加し、それが機能するようになりましたありがとうございました! –