This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Services and the fly likes How to add Cookie http header in the soap request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to add Cookie http header in the soap request" Watch "How to add Cookie http header in the soap request" New topic
Author

How to add Cookie http header in the soap request

Aarti Roshan
Greenhorn

Joined: May 09, 2008
Posts: 13
Hi,
I want to add http header - Cookie when the soap request is fired? I tried using call.addHeader ,but this puts the header within the soap envelope and not like normal http header...
Any help on this would really be helpful.

thanks
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Why do you want to add a Cookie HTTP header to the SOAP request of a web service call? This does not make any sense. Please explain.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41182
    
  45
If you have a SAAJ client, and know how to create a proper cookie header, then check out http://faq.javaranch.com/java/WebServicesHowTo#http-headers
It describes how to add HTTP headers to SAAJ messages.


Ping & DNS - my free Android networking tools app
Aarti Roshan
Greenhorn

Joined: May 09, 2008
Posts: 13
This is code am using james, its a standalone client am using to invoke a server for webservices, which expects some http headers of Cookie to be set.

String endpoint = "https://www.test.com/testServices/services/SocketBroker";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName("toString"));
ret = (String) call.invoke( new Object[] { } );
System.out.println("Sent 'Hello!', got '" + ret + "'");


I was unable to figure out where to set the code you gave?

I have to set the Cookie http header in soap webservice , as the server where these webservices are deployed at the customer end , has some authentication done everytime something is being accessed by outside world.

So if i have set these headers it would understand that webservice request is good to go and wont authenticate again. Else currently its sending back html login page as response instead of call to exposed method.
Hope am clear?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Are you saying that in order to call the web service, it is expecting a HTTP Cookie header?

This is strange. Note that there is a difference between HTTP headers and SOAP headers.

First, a Cookie header is for processing at a client's HTTP browser, not at the web server.

So, if the web service code is checking for a HTTP Cookie header for some security purpose...oh well.

Anyway, you need to get the Axis SOAP Engine to invoke a Handler class. The code in the Handler class
will be passed a MesageContext object that contains the SOAP request generated for the call below.



So, the code above will not and should not contain the code for adding the security header, it will be in the Handler (see below).

In the handleRequest() method of the Handler, you can then add the "Cookie" HTTP header to the SOAP request.




The security handler will be invoked by the SOAP Engine. All you need to do is add the Handler to the Service object via HandlerRegistry object, e.g.



If what I state sounds foreign to you, then you need to learn more about writing handler code for SOAP Engines and writing code using the javax.xml.soap API.

Good luck!

brutala brutal
Greenhorn

Joined: Dec 21, 2012
Posts: 2
Hi and how can I add header in HTTP req and not in soap? (always in the handler)
Thanks
 
 
subject: How to add Cookie http header in the soap request
 
Similar Threads
SOAP header in SOAP request
Web Service SOAP exception when security access denied.
how to write http header for soap request
Doubt about header
Trouble hand rolling SOAP request