On Thu, Nov 8, 2012 at 11:49 PM, Brian Reinhold <[email protected]> wrote: > 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? >
The Javadoc says this: "Get an iterator over all descendants of the container. The items are returned in document order. Note that attributes and namespace declarations are not considered descendants." It doesn't restrict the result to elements. > > Thanks > > > > Brian --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
