users@jersey.java.net

[Jersey] Jersey 1 client pre-emptive authentication problems

From: Marko Asplund <marko.asplund_at_gmail.com>
Date: Thu, 30 May 2013 17:22:40 +0300

Hi,

I'm trying use pre-emptive HTTP basic authentication with Jersey
1.17.1 and Apache HttpClient.
HTTP basic auth headers do not seem get added in the HTTP request.

Is this the way credentials should be set for pre-emptive authentication?
Here's the code I'm using:

URL svcUrl = new URL("http://localhost:8080/foo/bar");
String userName = "foo";
String password = "bar";

ApacheHttpClientConfig acc = new DefaultApacheHttpClientConfig();
acc.getProperties().put(ApacheHttpClientConfig.PROPERTY_PREEMPTIVE_AUTHENTICATION,
Boolean.TRUE);
ApacheHttpClientState st = acc.getState();
st.setCredentials(null, svcUrl.getHost(), svcUrl.getPort(), userName, password);
ApacheHttpClient hc = ApacheHttpClient.create(acc);


marko