16

I'm trying to figure out how to do Basic Authentication with an ADB Axis2 version 1.5 Client.

I'm trying the following:

HttpTransportProperties.Authenticator basicAuth = new HttpTransportProperties.Authenticator();
basicAuth.setUsername(username);
basicAuth.setPassword(password);
final Options clientOptions = serviceStub._getServiceClient().getOptions();
clientOptions.setProperty(HTTPConstants.AUTHENTICATE, basicAuth);

However this does not work and the needed line in the message header is not being added.

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Mike C.
  • 1,035
  • 2
  • 8
  • 13

2 Answers2

21

Got the answer from the following site:

http://www.inpc.de/blog/2007/05/axis2-12-basic-authentication.html

Apparently I was missing:

basicAuth.setPreemptiveAuthentication(true);
Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Mike C.
  • 1,035
  • 2
  • 8
  • 13
2

I think you're close, your code looks really close to this? The following is the difference:

clientOptions.setProperty(
   org.apache.axis2.transport.http.HTTPConstants.BASIC_AUTHENTICATION,
                basicAuth);
Michael Sharek
  • 5,043
  • 2
  • 30
  • 33