JAX RS Client API API Interceptor

Is there a way to add a header to the request through interceptors, but not through explicit header settings when using the JAX RS Client API:

Client client = ClientBuilder.newClient();
Response response = client.target("someUrl").path("somePath").request().get();

In the AOP method

+4
source share
1 answer

Create ClientRequestFilter:

@Provider
public class MyClientRequestFilter implements ClientRequestFilter {

    @Override
    public void filter(ClientRequestContext requestContext) throws IOException {
        requestContext.getHeaders().add("Authorization", "value");
    }
}

And register it in Client:

Client client = ClientBuilder.newClient().register(MyClientRequestFilter.class);
+5
source

Source: https://habr.com/ru/post/1610795/


All Articles