在单元测试中,我通过REST客户端(通过@RegisterRestClient带注释的接口)调用@Authenticated终结点。如何在REST调用中提供令牌?
答案 0 :(得分:0)
界面:
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
}
}