Call me stupid, but I spent the better part of the afternoon to figure out how to soap a server that expects user credentials encoded in BASIC authentication. (You know, like user:password scrambled with base64.)
Players in this drama: Apache Axis2 1.2, therefrom the wsdl2java compiler with databinding xmlbeans, the custom target server (sporting Axis2 1.1.1 himself) and yours truly.
The wsdl2java compiler (generator) works perfectly and leaves you a Stub class to start from. But there’s no way to tell this stub straightforwardly that we’re needing to basic authenticate with the server to get our call through.
To guess from the Axis2 JIRA and documentation, all you need is access to the
Options object, create an
Auhenticator and set some of its properties. As to which properties, the documentation is incorrect (as of 2007-05-22, I’ll open a JIRA ticket on it).
Update: The bug is already fixed in subversion.
It tells us:
Options options = new Options();
auth = new HttpTransportProperties.Authenticator();
// set if realm or domain is know
When it should be (in the context of a generated Stub):
- YourStub stub = new YourStub(„– your service endpoint –„);
- Options options = stub._getServiceClient().getOptions();
- HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
Note how it’s
HTTPConstants.AUTHENTICATE, because client and server ought to discuss which specific authentication scheme to use. If that doesn’t work (as with my stuff), add the statement
auth.setPreemptiveAuthentication(true);, which seems to end all discussions and just gets the BASIC authentication through.
I put it down here in length, because there are so many places where older versions of this are presented, and they just don’t work.