Oz Molaim
Oz Molaim

Reputation: 2136

RESTEasy - How to Set Basic Authentication to ClientRequest

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

Answers (1)

eiden
eiden

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

Related Questions