Meaningless Drivel is fun!*
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
JavaRanch » Java Forums » Java » Web Services
Bookmark "Adding authentication in SOAP header.." Watch "Adding authentication in SOAP header.." New topic
Author

Adding authentication in SOAP header..

hchandran krishnan
Greenhorn

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("http://my.name.space/headers", "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.)
*******

s.setUsername("TPS");
s.setPassword("TPSPASS");


Way 4.)
*******
SOAPHeaderElement wsseSecurity = new SOAPHeaderElement(new PrefixedQName("http://schemas.xmlsoap.org/ws/2002/07/secext", "Security","wsse"));
MessageElement usernameToken = new MessageElement("","wsse:UsernameToken");
MessageElement username = new MessageElement("", "wsse:Username");
MessageElement password = new MessageElement("", "wsse assword");

username.setObjectValue("johnsmith");
usernameToken.addChild(username);
password.setObjectValue("johns_passwd");
password.addAttribute("","Type", "wsse asswordText");
usernameToken.addChild(password);
wsseSecurity.addChild(usernameToken);
s.setHeader(wsseSecurity);



Is there any other way to add header ?

Requesting your help..

Regards
Harikrishnan
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41620
    
  55
#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.


Ping & DNS - my free Android networking tools app
Andy Gherna
Greenhorn

Joined: Sep 20, 2005
Posts: 1
Have you seen http://www-128.ibm.com/developerworks/xml/library/x-tipsoap.html?
Kalaiselvi Senthil
Greenhorn

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: http://aspose.com/file-tools
 
subject: Adding authentication in SOAP header..