• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to add Cookie http header in the soap request

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi and how can I add header in HTTP req and not in soap? (always in the handler)
Thanks
 
permaculture is giving a gift to your future self. After reading this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic