从响应式弹簧服务调用阻塞假客户端

问题描述

我正在尝试像这样从反应性弹簧通量中调用生成的假客户端:

            .doOnNext(user1 -> {
            ResponseEntity<Void> response = recorderClient.createuserProfile(new UserProfileDto().principal(user1.getLogin()));
            if (!response.getStatusCode().equals(HttpStatus.OK)) {
                log.error("recorder backend Could not create user profile for user: {} ",user1.getLogin());
                throw new RuntimeException("recorder backend Could not create user profile for login name" + user1.getLogin());
            }
        })

调用已执行,但是当我尝试从响应式安全上下文(在请求拦截器中)检索 jwt 令牌时,如下所示:

    public static Mono<String> getCurrentUserJWT() {
    return reactivesecuritycontextholder
        .getContext()
        .map(SecurityContext::getAuthentication)
        .filter(authentication -> authentication.getCredentials() instanceof String)
        .map(authentication -> (String) authentication.getCredentials());
}

....

SecurityUtils.getCurrentUserJWT().blockOptional().ifPresent(s -> template.header(AUTHORIZATION_HEADER,String.format("%s %s",BEARER,s)));

上下文为空。由于我对反应式 spring 还很陌生,所以我肯定会胡思乱想一些愚蠢而重要的事情。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)