Reputation: 2136
I am using RESTEasy (implementation of JAX-RS). I can't find a way to set basic, preemptive, authentication to ClientRequest.
ClientRequest request = new ClientRequest("<url>");
// -- here I want to add basic-preemptive authentication --
ClientResponse response = request.get();
System.out.println(response.getEntity(String.class));
What the correct way to do it? Is there any other way to do it?
Thank you.
Upvotes: 1
Views: 3289
Reputation: 2349
If you look at the constructors in ClientRequest
, you will see that one of them takes a string and a ClientExecutor
.
So you can do something like this:
ApacheHttpClient4Executor executor = new ApacheHttpClient4Executor();
DefaultHttpClient client = (DefaultHttpClient) executor.getHttpClient();
client.addRequestInterceptor(new MyPreemptiveAuthInterceptor(), 0);
ClientRequest request = new ClientRequest("http://my-url", executor);
Upvotes: 1