2

when I call two consecutive commands, I have the following compilation error:

no instance(s) of type variable(s) U exist so that CompletionStage<U> conforms to Pair<ResponseHeader, AuthenticationLoginResponseWrapper> inference variable U has incompatible bounds: equality constraints: Pair<ResponseHeader, AuthenticationLoginResponseWrapper> lower bounds: CompletionStage<U608599>

My HeaderServiceCall is the following :

@Override
public HeaderServiceCall<NotUsed, AuthenticationLoginResponseWrapper> refreshTokenAction() {
    return ((requestHeader, notUsed) -> {

        Optional<Authentication> auth;
        try {
            auth = authenticationRepository.getAuthByRefreshToken(requestHeader.getHeader(REFRESH_TOEKN_EXPIRED_MESSAGE).get())
                    .toCompletableFuture().get();
        } catch (InterruptedException | ExecutionException e) {
            auth = Optional.empty();
        }
        if (auth.isPresent()) {

            if (TokenUtils.verifyAccessTokenExpiration(auth.get().getRefreshTokenExpiration().toEpochMilli())) {

                Authentication newAuth = new Authentication(TokenUtils.generateToken(),
                        Instant.now(), TokenUtils.generateToken(), Instant.now(), auth.get().getUserId());

                String oldAccessToken = auth.get().getAccessToken();
                Optional<Authentication> finalAuth = auth;
                return authenticationEntityRef(newAuth.getAccessToken()).ask(new AuthenticationLoginCommand(newAuth)).thenApply(reply -> {

                    return authenticationEntityRef(oldAccessToken).ask(new AuthenticationRefreshCommand(finalAuth.get()))
                            .thenApply(finalReply -> {
                        AuthenticationLoginResponseWrapper response = new AuthenticationLoginResponseWrapper(newAuth.getUserId().toString(),
                                newAuth.getAccessToken(), newAuth.getRefreshToken());
                        return Pair.create(ResponseHeader.OK, response);

                    });

                    //return Pair.create(ResponseHeader.OK, response);
                });
            } else {
                throw new Forbidden(REFRESH_TOEKN_EXPIRED_MESSAGE);
            }
        } else {

            throw new Forbidden(REFRESH_TOEKN_EXPIRED_MESSAGE);
        }

    });
}

Am I doing this correct !!?

Tim Moore
  • 8,958
  • 2
  • 23
  • 34

0 Answers0