axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shantanu Sen <s...@pacbell.net>
Subject Re: org.apache.axis.message.MessageElement question
Date Sat, 13 Nov 2004 02:13:18 GMT
I was in the process of doing that, but ran into this
issue. Wondering if you could point to any problems
related with the test code or is this another bug.

Compile the ClassCasTest.java and run it as 

java ClassCastTest book2.xml. 

It throws the following exception:

[57 bug-fix]> java ClassCastTest book2.xml
Exception in thread "main"
java.lang.IllegalArgumentException: invalid QName loc
al part
        at
javax.xml.namespace.QName.<init>(QName.java:75)
        at
javax.xml.namespace.QName.<init>(QName.java:60)
        at
org.apache.axis.message.PrefixedQName.<init>(PrefixedQName.java:30)
        at
org.apache.axis.message.MessageElement.copyNode(MessageElement.java:2
044)
        at
org.apache.axis.message.MessageElement.copyNode(MessageElement.java:1
997)
        at
org.apache.axis.message.MessageElement.<init>(MessageElement.java:195
)
        at
org.apache.axis.message.SOAPBodyElement.<init>(SOAPBodyElement.java:7
0)
        at
org.apache.axis.message.SOAPBody.addDocument(SOAPBody.java:220)
        at ClassCastTest.main(ClassCastTest.java:36)


I was hoping to add this document to the SOAP Body and
then use a parser to get the nodes and try to
reproduce the original problem as a standalone test
case...

Thanks,
Shantanu

--- Davanum Srinivas <davanum@gmail.com> wrote:

> Shantanu,
> 
> Please open up a bug report with the small test case
> that we can use
> to validate the problem and fix it (hopefully before
> we go final)
> 
> thanks,
> dims
> 
> 
> On Thu, 11 Nov 2004 11:15:47 -0800 (PST), Shantanu
> Sen <ssen@pacbell.net> wrote:
> > 
> > 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) {
> >        
> soapBody.addDocument(payload[0].getDocument());
> >  } 
> > 
> > //soapMsg.writeTo(System.out); 
> > 
> > --------- 
> > 
> > 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 Message. 
> > 
> > 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? 
> > 
> > Thanks, 
> > 
> > Shantanu
> > 
> > 
> > 
> > Davanum Srinivas <davanum@gmail.com> wrote:
> > 
> > 
> > 
> >  
> > Question: Are u creating the MessageElement by
> hand or is Axis
> > generating this one (based on say the SAAJ API's
> for you)?
> > 
> > Thanks,
> > dims
> > 
> > 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) {
> > > return CDATA_SECTION_NODE;
> > > } 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 -
> http://webservices.apache.org/~dims/
> >  
> 
> 
> -- 
> Davanum Srinivas -
> http://webservices.apache.org/~dims/
> 
Mime
View raw message