tags:

views:

675

answers:

3

Hey 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. Anyone know how to do this. This should be dumb simple I just can't find it with all my googling.

+1  A: 

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
Yeah, the problem is they removed that constant in Axis 1.4.x and higher.
Mike C.
Thanks again for your help though!
Mike C.
+2  A: 

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);

Sorry to answer my own question here I worked on this about 2 hours before posting.

Mike C.
A: 

very helpfull dude! i have to deliver this project in 10 min, and this make it work! thaks to god and you

carajo
You're welcome :)
Mike C.