Search in sources :

Example 11 with NullResolver

use of org.apache.cxf.helpers.DOMUtils.NullResolver in project cxf by apache.

the class ParseBodyTest method testReadSOAPFault.

@Test
public void testReadSOAPFault() throws Exception {
    InputStream inStream = getClass().getResourceAsStream("soap12-fault.xml");
    Document doc = StaxUtils.read(inStream);
    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);
    SOAPMessage saajMsg = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
    SOAPPart part = saajMsg.getSOAPPart();
    SAAJStreamWriter writer = new SAAJStreamWriter(part);
    StaxUtils.copy(doc, writer);
    // Source s = new StaxSource(StaxUtils.createXMLStreamReader(doc));
    // part.setContent(s);
    saajMsg.saveChanges();
    msg.setContent(SOAPMessage.class, saajMsg);
    doc = part;
    // System.out.println("OUTPUT: " + StaxUtils.toString(doc));
    byte[] docbytes = getMessageBytes(doc);
    // System.out.println("OUTPUT: " + new String(docbytes));
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(docbytes));
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setValidating(false);
    dbf.setIgnoringComments(false);
    dbf.setIgnoringElementContentWhitespace(true);
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    db.setEntityResolver(new NullResolver());
    doc = StaxUtils.read(db, reader, false);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) NullResolver(org.apache.cxf.helpers.DOMUtils.NullResolver) Exchange(org.apache.cxf.message.Exchange) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SOAPPart(javax.xml.soap.SOAPPart) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)11 DocumentBuilder (javax.xml.parsers.DocumentBuilder)11 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)11 SOAPMessage (javax.xml.soap.SOAPMessage)11 XMLStreamReader (javax.xml.stream.XMLStreamReader)11 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)11 NullResolver (org.apache.cxf.helpers.DOMUtils.NullResolver)11 Exchange (org.apache.cxf.message.Exchange)11 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)11 MessageImpl (org.apache.cxf.message.MessageImpl)11 Document (org.w3c.dom.Document)11 Test (org.junit.Test)7 QName (javax.xml.namespace.QName)4 SoapFault (org.apache.cxf.binding.soap.SoapFault)3 WSHandlerResult (org.apache.wss4j.dom.handler.WSHandlerResult)3 HashMap (java.util.HashMap)2 WSSecurityEngineResult (org.apache.wss4j.dom.engine.WSSecurityEngineResult)2 InputStream (java.io.InputStream)1 SOAPPart (javax.xml.soap.SOAPPart)1 WSS4JInInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor)1