2

I am new to Web Service development. I am developing a web service using Spring WS. I need to add soap header in request so below is my code to add header in request at client side.

 getWebServiceTemplate()
                .sendSourceAndReceiveToResult(source, 
                    new WebServiceMessageCallback(){
                        public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException{
                            SaajSoapMessage soapMessage = (SaajSoapMessage) message;
                            SoapHeaderElement messageId =  soapMessage.getSoapHeader().addHeaderElement(new QName("http://www.w3.org/2005/08/addressing", "messageId", "wsa"));
                            messageId.setText("Test Security Token");
                        }
                },result);

How do I get this header out of the request in my server side class?

I have used the Eclipse Axis plugin to generate my wsdl to class skeleton. I am using Spring 2.

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
Kevin Shah
  • 43
  • 1
  • 5

2 Answers2

1

I got the solution. Code that I have written in method of BindingImpl of server skeleton :

MessageContext messageContext = MessageContext.getCurrentContext();

SOAPHeader header = (SOAPHeader) 
    messageContext.getCurrentMessage().getSOAPHeader();

header.getChildElements();

It will give you list of SOAPHeaderElement. And from that you can take element name and its value.

Thank you all of you... :)

VirtualTroll
  • 3,077
  • 1
  • 30
  • 47
Kevin Shah
  • 43
  • 1
  • 5
0

Hmm, the question is, which version of Spring-WS are you using? The header you want to add belongs to the WS-Addressing specification, right? I know that Spring-WS also supports WS-Addressing directly. It's better to use Spring's support as much as possible and not to interfere with the message headers (although this is also possible).

Oliver Marienfeld
  • 1,154
  • 9
  • 17