axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jean-Marc Taillant" <>
Subject Re: SOAP Header, addHeader method
Date Tue, 10 Sep 2002 12:02:07 GMT
I joined the mail from the mailing list about the addHeader problem

	That helped quite a bit -- thanks. I tracked down the problem. First, the
reason I wasn't able to see the .addHeader method on the SOAPEnvelope object
is because the class I'm in (a holdover) imported
javax.xml.soap.SOAPEnvelope. So when I made a call to
		SOAPEnvelope envelope = msgContext.getRequestMessage().getSOAPEnvelope();

It was really returning a javax.xml.soap.SOAPEnvelope object not an
org.apache.axis.message.SOAPEnvelope. I didn't have to cast it, nor did I
get compile time errors because the Axis IMPL is a subclass of the Sun
interface. As a result the method addHeader() wasn't found.

So since I couldn't use addHeader(), the road I was going down was to call
addChildElement on the returned SOAPEnvelope object -- which in this case
was javax.xml.soap.SOAPEnvelope -- but the implementation is actually in the
parent class of org.apache.axis.message.SOAPEnvelope:

Now, I've looked through the source code for both the axis MessageElement
object and the SOAPEnvelope object, and it seems like the code for
addChildElement is stubbed out. However, if I use the addChildElement() call
instead of the addHeader() call, the element is not appended and my
modification doesn't take -- no error is thrown but the SOAP request isn't

The bug here is that both the org.apache.axis.message.SOAPHeader class and
the org.apache.axis.message.SOAPBody class don't override the
addChildElement of their parent. If you look at the code for both of these
classes, you'll see that they have a addHeaderElement() and addBodyElement()
respectively. SOAPEvenlope has a similar behavior. But none of the 3
sub-classes override the parent class's method so the header, envelope or
body is never really changed.

The solution to this (bug?) is for the SOAPHeader, SOAPBody and SOAPEnvelope
classes to override the addChildElement of the parent so that the element
doesn't go in the generic "children" ArrayList in the MessageElement parent
class but get added to the nested "bodyElements" Vector (in SOAPBody) and
"headers" Vector (in SOAPHeader). I'd be happy to help the Axis developers
with this change if necessary.


-----Original Message-----
From: Ricky Ho []
Sent: Friday, September 06, 2002 10:54 AM
Subject: RE: Handlers and SOAP message re-writing

Following is my exact code based on AXIS beta 2

import org.apache.axis.*;
import org.apache.axis.handlers.*;
import org.apache.axis.message.*;

public class PutHeaderHandler extends BasicHandler {
    public void invoke(MessageContext msgContext) throws AxisFault
        try {
                System.out.println(" -- PutHeaderHandler starts --");
                System.out.println("Options are :  " + getOptions());

                SOAPEnvelope envelope =
                System.out.println("Request message is : " + envelope);
                envelope.addHeader(new SOAPHeaderElement("TestNameSpace",
"isAuthenticated", new Boolean(true)));

                System.out.println("Add header");
       } catch (Exception e) {
            throw AxisFault.makeFault(e);

Rgds, Ricky

View raw message