axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Reinhold" <brianreinh...@lampreynetworks.com>
Subject Axiom Class cast exception on iterator of that class!
Date Thu, 08 Nov 2012 22:49:03 GMT
Why does this code throw a java.lang.ClassCastException:
org.apache.axiom.om.impl.llom.OMTextImpl cannot be cast to
org.apache.axiom.om.OMElement

 

             MessageContext msgContext = data.getInMessageContext();

             SOAPHeader header = msgContext.getEnvelope().getHeader();

             Iterator<OMElement> iter = header.getDescendants(false);

             String user = "";

             while(iter.hasNext())

             {

                 OMElement element = iter.next();

                 if(element.getType() == OMNode.ELEMENT_NODE)

                 {

                     element = element.getFirstChildWithName(new
QName(wsseNamespace, "Username"));

                     if(element != null)

                     {

                         user = element.getText();

                     }

                 }

             }

 

The getDescendants() method of Axiom states that it returns an iterator over
OMElements. Yet I get that class cast exception with no way to guard against
it. Can someone explain how this can happen?

 

Thanks

 

Brian


Mime
View raw message