package at.gv.egiz.moazs.scheme; import at.gv.egiz.eaaf.core.impl.utils.DOMUtils; import org.apache.cxf.binding.soap.Soap11; import org.springframework.stereotype.Component; import org.w3c.dom.Element; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder; @Component public class SOAPUtils { public Element toDOM(byte[] bytes) throws IOException, SAXException, ParserConfigurationException { var stream = new ByteArrayInputStream(bytes); return DOMUtils.parseXmlNonValidating(stream); } public byte[] unwrapSoapEnvelope(Element document) { try { var body = document.getElementsByTagNameNS(Soap11.SOAP_NAMESPACE, "Body"); var item = body.item(0).getFirstChild(); return DOMUtils.serializeNode(item, true) .getBytes(StandardCharsets.UTF_8); } catch (IOException | TransformerException e) { throw moaZSExceptionBuilder("Error while parsing message. ").withCause(e).build(); } } public String getAppDeliveryIDFrom(Element document) { var elements = document.getElementsByTagNameNS(NameSpace.MSG, "AppDeliveryID"); var appDeliveryIdElement = elements.item(0).getFirstChild(); return appDeliveryIdElement.getNodeValue(); } }