Hi

I am fairly new to Axis so I appologise if this has been covered previously.
I have tried searching the mailing list archives but to no avail.

I have a client and a Web service which I wish to send SOAP messages
between.  I want to be able to:
1) Set a SOAP header in the client request.
2) Extract this header in the service.
3) Do something with the value obtained from this header.
4) Set the same header in the service response but with a diferent value.
5) Extract the header from the response in the client.

So far I can do 1) 2) and 3) but am having real problems understanding how
to set a SOAP header from within a Web service.  This seems pretty trivial
in a handler but seems to work differently in a service. Does anybody have
any advice? The code that I thought might work is below but the message is
not getting updated. As you can see, I am just trying to pass a simple
counter value around...

Client:
call.addHeader(new SOAPHeaderElement("namespace", "counter", new
Integer(555)));

Service:
// Get the current message context and extract the counter from the header
MessageContext msgContext = MessageContext.getCurrentContext();
Message msg = msgContext.getCurrentMessage();
SOAPEnvelope env = msg.getSOAPEnvelope();
SOAPHeaderElement headerElem = env.getHeaderByName("namespace", "counter");

if(headerElem == null)
        throw new Exception("No counter header found");

count = (Integer) headerElem.getValueAsType(Constants.XSD_INT);

// Add the counter header back to the SOAP envelope
env.addHeader(headerElem);
Message newMsg = new Message(env);
msgContext.setCurrentMessage(newMsg);


Should I be getting an instance of the Axis Engine in the service or
something? I am really pulling my hair out and I am sure it must be
possible!!!

Note:I am using Axis 1.1

Thanks in advance for any help.

Regards
Jim Harris


Reply via email to