rest - quarkus:如何通过休息客户端提供令牌
问题描述
在单元测试中,我通过 REST 客户端(通过 @RegisterRestClient 注释接口)调用 @Authenticated 端点。如何在 REST 调用中提供令牌?
解决方案
界面:
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@RegisterRestClient
public interface MyAuthenticatedService {
@GET
public void myAuthenticatedCall(@HeaderParam("Authorization") String token);
}
和调用本身:
import javax.inject.Inject;
import org.eclipse.microprofile.rest.client.inject.RestClient;
public class FoobarService {
@Inject
@RestClient
MyAuthenticatedService myService;
public void foobar(String token) {
myService.myAuthenticatedCall("Bearer " + token); // beware of the space
}
}
推荐阅读
- javascript - 如何在嵌套组件中处理 EmberJS 中的操作
- sql-server - 数据建模设计
- arrays - 如何在列表中找到存储另一个列表的元素并获取索引?
- ms-access - MS Access 不会链接到已编译后端中的表
- django - Django 按两个字段的值计数和分组
- matlab - 如何从给定的起点获取新数据?
- php - 如何在 PHP、Laravel 中管理标签的翻译?
- uml - 具有缓冲区优先级 OCL 的生产者消费者模式
- c# - 触摸注入后恢复被抑制的光标
- hibernate - 将 cdi bean 注入 jax-rs 控制器时,$Proxy$_$$_WeldClientProxy 无法转换为 javassist.util.proxy.ProxyObject