Thursday, October 2, 2008

Axis2 - Calling a Service which is Protected by HTTP Basic Authentication

If you need to call a service which is protected using HTTP Basic Authentication with Apache Axis2, then you could do so by setting the following property on the options object.

HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
authenticator.setUsername("keith");
authenticator.setPassword("keith");
authenticator.setPreemptiveAuthentication(true);
options.setProperty(HTTPConstants.AUTHENTICATE, authenticator);

If you are using a generated stub you could get hold of the options object as,

stub._serviceClient.getOptions();

3 comments:

Unknown said...

java.lang.reflect.InvocationTargetException

Hai everyone .

i m using Axis2_Codegen_Wizard_1.3.0 to generate java server side skelton through eclipse..but every time i m getting this exception..

plzzzzzzzzz solve it.

Keith Chapman said...

The description you have given would not help anybody answer your question. There is not enough information.

Ayush said...

Hi Keith,

Could you give us some example to writing the server side code to enable the basic authentication .

I have written some services, and can access by using rest and different clients. Now I want to add basic authentication,

Thanks,
ayush