Quarkus/MicroProfile Rest客户端会话Cookie



我使用Quarkus Rest客户端与外部服务通信,该服务使用两个cookie来验证所有请求。这两个cookie是从身份验证API和随后的每个API调用返回的。有没有办法自动处理这些cookie?目前,我正在从身份验证API的响应对象获取Cookie,并使用@CookieParam在每个请求中手动发送它们。

我还没有尝试过,但你不能做这样的事情吗:

//pseudo code !!!
@RestClient
public interface UsersClient {
@POST
String backendCall(@CookieParam("Token1") token1, @CookieParam("Token2") String token2)
@POST
Map<String,String> authenticate(String param)
default String makeCall(String param) {
var tokens = authenticate(param);
return backendCall(tokens.get(0), tokens.get(1));
}
}

从您的服务注入这个rest客户端并调用makeCall(…(方法。这应该根据您的服务器对您进行身份验证,并使用响应中的令牌,并将这些令牌作为cookie发送到后端调用。

对代码中的任何错误表示歉意:我是用平板电脑写的。但我希望这个想法是明确的。

还可以查看Microprofile Rest客户端文档以了解更多信息:

https://download.eclipse.org/microprofile/microprofile-rest-client-2.0/microprofile-rest-client-spec-2.0.html#_sample_definitions

最新更新