package at.gv.egiz.moazs.scheme; import at.gv.egiz.eaaf.core.impl.utils.DOMUtils; import at.gv.egiz.moazs.MoaZSException; 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; @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 MoaZSException.moaZSException("Error while parsing message. ", e); } } public String getAppDeliveryIDFrom(Element document) { var elements = document.getElementsByTagNameNS(NameSpace.MSG, NameSpace.MSG_APP_DELIVERY_ID); var appDeliveryIdElement = elements.item(0).getFirstChild(); return appDeliveryIdElement.getNodeValue(); } }