Monday, 4 April 2016

How to use HTTP Authentication in Axis 2x client stubs ?


If your web service requires you to use HTTP Basic Authentication, you can adjust your Axis client code.
Here we have used service stub class and calling its operation "GetStockInfo".

Example
StockInfoServiceStub serviceStub = new StockInfoServiceStub(
                      Axis2Utils.getConfigurationContext(), url);
// Set credentials in authenticator and set authentoicator 
// to stub object for basic authentication
Authenticator auth = new Authenticator();
auth.setUsername(“username");
auth.setPassword(“password”);
auth.setPreemptiveAuthentication(true);
serviceStub._getServiceClient().getOptions()
                  .setProperty(HTTPConstants.AUTHENTICATE, auth);
serviceStub._getServiceClient().getOptions()
                 .setProperty(HTTPConstants.CHUNKED, Boolean.FALSE);

// Call web service method
serviceStub.GetStockInfo("FOO");

No comments:

Post a Comment

Note: only a member of this blog may post a comment.