Java Code Examples for org.apache.cxf.staxutils.StaxUtils#writeDocument()

The following examples show how to use org.apache.cxf.staxutils.StaxUtils#writeDocument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WSDLGetOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Document doc = (Document)message.get(WSDLGetInterceptor.DOCUMENT_HOLDER);
    if (doc == null) {
        return;
    }
    message.remove(WSDLGetInterceptor.DOCUMENT_HOLDER);

    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
    if (writer == null) {
        return;
    }
    message.put(Message.CONTENT_TYPE, "text/xml");
    try {
        StaxUtils.writeDocument(doc, writer,
                                !MessageUtils.getContextualBoolean(message,
                                                                   StaxOutInterceptor.FORCE_START_DOCUMENT,
                                                                   false),
                                true);
    } catch (XMLStreamException e) {
        throw new Fault(e);
    }
}
 
Example 2
Source File: WSS4JInOutTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);
    StaxUtils.writeDocument(doc, byteArrayWriter, false);
    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 3
Source File: AbstractSecurityTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected byte[] getMessageBytes(Document doc) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);
    StaxUtils.writeDocument(doc, byteArrayWriter, false);
    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 4
Source File: HWSAXSourcePayloadProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
private File getSOAPBodyFile(Document doc) throws Exception {
    File file = FileUtils.createTempFile("cxf-systest", "xml");
    try (FileOutputStream out = new FileOutputStream(file)) {
        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
        StaxUtils.writeDocument(doc, writer, true);
        writer.close();
        return file;
    }
}
 
Example 5
Source File: SamlTokenTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);
    StaxUtils.writeDocument(doc, byteArrayWriter, false);
    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 6
Source File: SignatureConfirmationTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    // XMLOutputFactory factory = XMLOutputFactory.newInstance();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    // XMLStreamWriter byteArrayWriter =
    // factory.createXMLStreamWriter(outputStream);
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);

    StaxUtils.writeDocument(doc, byteArrayWriter, false);

    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 7
Source File: WSS4JInOutTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);
    StaxUtils.writeDocument(doc, byteArrayWriter, false);
    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 8
Source File: WSS4JFaultCodeTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    // XMLOutputFactory factory = XMLOutputFactory.newInstance();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    // XMLStreamWriter byteArrayWriter =
    // factory.createXMLStreamWriter(outputStream);
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);

    StaxUtils.writeDocument(doc, byteArrayWriter, false);

    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 9
Source File: SamlTokenTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);
    StaxUtils.writeDocument(doc, byteArrayWriter, false);
    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 10
Source File: SignatureConfirmationTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    // XMLOutputFactory factory = XMLOutputFactory.newInstance();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    // XMLStreamWriter byteArrayWriter =
    // factory.createXMLStreamWriter(outputStream);
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);

    StaxUtils.writeDocument(doc, byteArrayWriter, false);

    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 11
Source File: WSS4JInOutTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);
    StaxUtils.writeDocument(doc, byteArrayWriter, false);
    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 12
Source File: XMLStreamDataWriter.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void writeNode(Node nd, XMLStreamWriter writer) throws XMLStreamException {
    if (writer instanceof W3CDOMStreamWriter) {
        W3CDOMStreamWriter dw = (W3CDOMStreamWriter)writer;

        if (dw.getCurrentNode() != null) {
            if (nd instanceof DocumentFragment
                && nd.getOwnerDocument() == dw.getCurrentNode().getOwnerDocument()) {
                Node ch = nd.getFirstChild();
                while (ch != null) {
                    nd.removeChild(ch);
                    dw.getCurrentNode().appendChild(org.apache.cxf.helpers.DOMUtils.getDomElement(ch));
                    ch = nd.getFirstChild();
                }
            } else if (nd.getOwnerDocument() == dw.getCurrentNode().getOwnerDocument()) {
                dw.getCurrentNode().appendChild(nd);
                return;
            } else if (nd instanceof DocumentFragment) {
                nd = dw.getDocument().importNode(nd, true);
                dw.getCurrentNode().appendChild(nd);
                return;
            }
        } else if (dw.getCurrentFragment() != null) {
            if (nd.getOwnerDocument() == dw.getCurrentFragment().getOwnerDocument()) {
                dw.getCurrentFragment().appendChild(nd);
                return;
            } else if (nd instanceof DocumentFragment) {
                nd = dw.getDocument().importNode(nd, true);
                dw.getCurrentFragment().appendChild(nd);
                return;
            }
        }
    }
    if (nd instanceof Document) {
        StaxUtils.writeDocument((Document)nd,
                                writer, false, true);
    } else {
        StaxUtils.writeNode(nd, writer, true);
    }

}
 
Example 13
Source File: SamlTokenTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);
    StaxUtils.writeDocument(doc, byteArrayWriter, false);
    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 14
Source File: SignatureConfirmationTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    // XMLOutputFactory factory = XMLOutputFactory.newInstance();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    // XMLStreamWriter byteArrayWriter =
    // factory.createXMLStreamWriter(outputStream);
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);

    StaxUtils.writeDocument(doc, byteArrayWriter, false);

    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 15
Source File: WSS4JInOutTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);
    StaxUtils.writeDocument(doc, byteArrayWriter, false);
    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 16
Source File: WSS4JFaultCodeTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    // XMLOutputFactory factory = XMLOutputFactory.newInstance();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    // XMLStreamWriter byteArrayWriter =
    // factory.createXMLStreamWriter(outputStream);
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);

    StaxUtils.writeDocument(doc, byteArrayWriter, false);

    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 17
Source File: SamlTokenTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);
    StaxUtils.writeDocument(doc, byteArrayWriter, false);
    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 18
Source File: SignatureConfirmationTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    // XMLOutputFactory factory = XMLOutputFactory.newInstance();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    // XMLStreamWriter byteArrayWriter =
    // factory.createXMLStreamWriter(outputStream);
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);

    StaxUtils.writeDocument(doc, byteArrayWriter, false);

    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 19
Source File: WSS4JFaultCodeTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    // XMLOutputFactory factory = XMLOutputFactory.newInstance();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    // XMLStreamWriter byteArrayWriter =
    // factory.createXMLStreamWriter(outputStream);
    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);

    StaxUtils.writeDocument(doc, byteArrayWriter, false);

    byteArrayWriter.flush();
    return outputStream.toByteArray();
}
 
Example 20
Source File: ParseBodyTest.java    From cxf with Apache License 2.0 3 votes vote down vote up
private byte[] getMessageBytes(Document doc) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);

    StaxUtils.writeDocument(doc, byteArrayWriter, false);

    byteArrayWriter.flush();
    return outputStream.toByteArray();
}