简体   繁体   中英

Preemptive authentication method in Apache Axis?

I sort of understand that I'm using Apache Axis 1.4 for querying a web service.

I was given a WSDL file, and that generated a XXXXImplServiceLocator class that extends org.apache.axis.client.Service and implements a generated interface that extends javax.xml.rpc.Service .

My "bussiness code" calls the getXXXXImplPort(URL) method on a new XXXXImplServiceLocator instance, and then calls:

((Stub) port).setTimeout(timeout);
((Stub) port).setUsername(username);
((Stub) port).setPassword(password);

Stub is org.apache.axis.client.Stub .

After setting those parameters, I simply call some getYYY() method, that represents the query to one of the services exposed by the remote service and gives me back a "domain" object with the results.

The problem is that I have to use preemptive authentication with this service. I've tried querying via soapUI, and I won't have any result unless I set the preemptive authentication mode.

I've tried googling how to set that mode, but found nothing. All they say about is Preemptive authentication with Apache HttpClient , that can be very well "embedded" or used by Axis, but I really didn't see how to mix this.

The only code I have that interacts with this ServiceLocator is the initial setup, and then just queries.

How can I set that preemptive authentication mode? Am I missing something? What am I not understanding so that I can't solve this issue?

Smells like a pretty trivial problem, but maybe the fact I don't understand this very well prevents me from solving the issue.

Thanks in advance, yeah :)

To force Apache Axis to use pre-emptive authentication, set the username and password like so:

import org.apache.axis.client.Call;
import org.apache.axis.client.Stub;
....
....
((Stub) client)._setProperty(Call.USERNAME_PROPERTY, "username");
((Stub) client)._setProperty(Call.PASSWORD_PROPERTY, "password");

That said, if you still want to use the Apache HttpClient as the transport, you can do so by setting the following in Axis client configuration file which in my case is client_config.wsdd :

<deployment xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
.....
.....
<!-- use CommonsHTTPSender instead of the default HTTPSender -->
<!-- <transport name="http" pivot="java:org.apache.axis.transport.http.HTTPSender" /> -->
<transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender" />
.....
.....
</deployment>

I got the above from here .

You can use the Apache Rampart module to implement WS Security . It plugs in at the service level and will handle all things WS-Security like username/token, X.509 auth, etc.

Its not trivial, but its not that difficult either. We did it here to get an Axis server talking to an Oracle SOA server using WSS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM