/** * prepend a child element <p/> * * @param parent element of this child element * @param child the element to append * @return the child element */ public static Element prependChildElement( Element parent, Element child ) { Node firstChild = parent.getFirstChild(); Element domChild = null; try { domChild = (Element)getDomElement(child); } catch (WSSecurityException e) { LOG.debug("Error when try to get Dom Element from the child", e); } if (firstChild == null) { return (Element)parent.appendChild(domChild); } else { return (Element)parent.insertBefore(domChild, firstChild); } }
/** * Register the javax.xml.soap.Node with new Cloned Dom Node with java9 * @param doc The SOAPDocumentImpl * @param clonedElement The cloned Element * @return new clonedElement which already associated with the SAAJ Node * @throws WSSecurityException */ public static Element cloneElement(Document doc, Element clonedElement) throws WSSecurityException { clonedElement = (Element)clonedElement.cloneNode(true); if (isSAAJ14) { // here we need regiter the javax.xml.soap.Node with new instance clonedElement = (Element)doc.importNode(clonedElement, true); clonedElement = (Element)getDomElement(clonedElement); } return clonedElement; }
header = (Element)getDomElement(header); header = prependChildElement(envelope, header); foundSecurityHeader.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS); doc.importNode(foundSecurityHeader, true); foundSecurityHeader = (Element)getDomElement(foundSecurityHeader);