Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add Cookie http header in the soap request

 
Aarti Roshan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Aarti Roshan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and how can I add header in HTTP req and not in soap? (always in the handler)
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic