axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shantanu Sen <>
Subject Re: org.apache.axis.message.MessageElement question
Date Thu, 11 Nov 2004 19:15:47 GMT
No I am not creating it by hand. I am using the SAAJ APis. Here is the code snippet:

// create a SOAPMessage - this contains an empty SOAP Envelope by
// default. We need to add the content of the payload - which in this case
// is a simple xml fragment - to the SOAP envelope
MessageFactory soapMsgFactory = MessageFactory.newInstance();
SOAPMessage soapMsg = soapMsgFactory.createMessage();    
SOAPPart soapPart = soapMsg.getSOAPPart();
SOAPEnvelope soapEnv = soapPart.getEnvelope();
SOAPBody soapBody = soapEnv.getBody();

// payload.getDocument returns a org.w3c.dom.Document object   
 if (payload != null && payload.length > 0 && payload[0] != null) {



After the above code executes, we use a third party XML document reader to parse the SOAPPart,
which is a org.w3c.dom.Document object. In the course of parsing this the parser checks the
nodetype of each Node which is a MessageElement and if the nodetype returns TEXT_NODE, it
casts the node to org.w3c.dom.Text. This will throw a ClassCastException since a MessageElement
does not implement Text. 

Now note this: if I uncomment the soapMsg.writeTo line, above, it works. This is because the
writeTo in turn does a save, which stores the SOAPPart.currentMessage as FORM_OPTIMIZED. This
results in a Deserializer to parse the content and in this course a RPCElement is created
(not a MessageElement). Thus there is no errors when the third party parser parses the SOAP

But if the soapMsg.writeTo is commented out, then the SOAPPart.currentMessages is stored as
FORM_SOAPENVELOPE - which uses MessageElement.

Any ideas on this or pointers how we can work around this (without using soapMsg.writeTo).
Basically I feel that MessageElement has a bug, but RPCElement has not, and if we can use
SAAJ APIs to generate RPCElement instead of MessageElement, we'll be ok. Is there a switch
somewhere that allows us to do that?



Davanum Srinivas <> wrote:
Question: Are u creating the MessageElement by hand or is Axis
generating this one (based on say the SAAJ API's for you)?


On Thu, 11 Nov 2004 00:53:57 -0800 (PST), Shantanu Sen wrote:
> The org.apache.axis.message.MessageElement extends
> NodeImpl as shown below
> ....
> public class MessageElement extends NodeImpl
> implements SOAPElement, Serializable,
> org.w3c.dom.NodeList, Cloneable
> ....
> NodelImpl has the method getNodeType that returns
> TEXT_NODE, if the node value has text:
> ------
> public short getNodeType() {
> if (this.textRep != null) {
> if (textRep instanceof Comment) {
> return COMMENT_NODE;
> } else if (textRep instanceof CDATASection) {
> } else {
> return TEXT_NODE;
> }
> -------
> This means that any client that calls getNodeType on a
> MessageElement and obtains a TEXT_NODE as return may
> cast the MessageElement to org.w3c.dom.Text. But this
> will throw a ClassCastException since MessageElement
> does not implement this interface.
> Any comments on this? Is'nt it mandatory for the
> specific node that returns a TEXT_NODE type implement
> the dom.Text interface?
> Thanks for any help.
> Shantanu Sen

Davanum Srinivas -

View raw message