my dog learned polymorphism
The moose likes Web Services and the fly likes Adding authentication in SOAP header.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Adding authentication in SOAP header.." Watch "Adding authentication in SOAP header.." New topic

Adding authentication in SOAP header..

hchandran krishnan

Joined: Sep 06, 2005
Posts: 1
Hi all,

I am using axis client for accessing webservice. I need to add authentication information in SOAP header.

using wsdl2Java i have generated the stub, skelaton stuff....

From the testClient i am trying the following codes.. But i am not able to view the SOAP Header in the SOAP request..

Way 1.)
TpsLocator locator = new TpsLocator();
org.apache.axis.client.Stub s=(org.apache.axis.client.Stub) locator.gettpsSoapDocPort();
s.setHeader("", "mysecurityheader", "This guy is OK");

Way 2.)
s._setProperty( javax.xml.rpc.Call.USERNAME_PROPERTY, "TPS" );
s._setProperty( javax.xml.rpc.Call.PASSWORD_PROPERTY, "TPSPASS" );

way 3.)


Way 4.)
SOAPHeaderElement wsseSecurity = new SOAPHeaderElement(new PrefixedQName("", "Security","wsse"));
MessageElement usernameToken = new MessageElement("","wsse:UsernameToken");
MessageElement username = new MessageElement("", "wsse:Username");
MessageElement password = new MessageElement("", "wsse assword");

password.addAttribute("","Type", "wsse asswordText");

Is there any other way to add header ?

Requesting your help..

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
#2 and #3 are setting HTTP headers, not SOAP headers.
As to #1 and #4, I don't know - I've never used SOAP headers.
Andy Gherna

Joined: Sep 20, 2005
Posts: 1
Have you seen
Kalaiselvi Senthil

Joined: Aug 08, 2012
Posts: 3
Hi Friends, I am new to webservices, I am creating a javaclient for our existing webservice, I sent request with username/password to the server and I got authentication token again I want to send request with my authentication token in the header
GeocodeRequest gcreq = new GeocodeRequest();
GeocoderProxy gp = new GeocoderProxy();
GeocoderSoap11Stub gcStub = (GeocoderSoap11Stub) gp.getGeocoder();
( gcStub)._setProperty(Call.SESSION_MAINTAIN_PROPERTY, new Boolean(true));
( gcStub)._setProperty(HTTPConstants.HEADER_AUTHORIZATION,m_strBase64AccessToken);
gres = gcStub.geocode(gcreq);

if I used the above code ,I got the response as (401)Non-Autorisé error like that,I am using jsp/servlet to create a java client, please help me how can I send authentication token with my request

I agree. Here's the link:
subject: Adding authentication in SOAP header..
It's not a secret anymore!