private static OMElement convertToOMelement(Element elem, SOAPConstants constants) throws WSSecurityException {
try {
XMLSerializer xmlSer = new XMLSerializer();
/*
*When we extract the wsse:Security header by serializing it
*The namespaces declared globally will not be copied into the
*serialized element. Therefore we have to add the missing namespaces
*in to the element before DOm serialization
*/
elem.setAttribute("xmlns:soapenv",constants.getEnvelopeURI());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
xmlSer.setOutputByteStream(baos);
xmlSer.serialize(elem);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(bais);
StAXOMBuilder builder = new StAXOMBuilder(reader);
builder.setCache(true);