use of javax.xml.stream.XMLStreamWriter in project webservices-axiom by apache.
the class TestWriteStartDocumentWithNullEncoding method runTest.
protected void runTest() throws Throwable {
XMLStreamWriter writer = staxImpl.newNormalizedXMLOutputFactory().createXMLStreamWriter(System.out, "UTF-8");
try {
writer.writeStartDocument(null, "1.0");
} catch (Throwable ex) {
// Expected
return;
}
fail("Expected writeStartDocument to throw an exception");
}
use of javax.xml.stream.XMLStreamWriter in project webservices-axiom by apache.
the class MTOMLogSample method logMessage.
// START SNIPPET: variant2
private void logMessage(SOAPEnvelope env) throws XMLStreamException {
StringWriter sw = new StringWriter();
XMLStreamWriter writer = new LogWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(sw));
env.serialize(writer);
writer.flush();
log.info("Message: " + sw.toString());
}
use of javax.xml.stream.XMLStreamWriter in project webservices-axiom by apache.
the class TestSerialize method runTest.
@Override
protected void runTest() throws Throwable {
OMText text = metaFactory.getOMFactory().createOMText("test", type);
XMLStreamWriter writer = mock(XMLStreamWriter.class);
text.serialize(writer);
if (type == OMNode.CDATA_SECTION_NODE) {
verify(writer).writeCData(text.getText());
} else {
verify(writer).writeCharacters(text.getText());
}
verify(writer, atMost(1)).flush();
verifyNoMoreInteractions(writer);
}
use of javax.xml.stream.XMLStreamWriter in project webservices-axiom by apache.
the class TestSerialize method runTest.
@Override
protected void runTest() throws Throwable {
OMDocType doctype = metaFactory.getOMFactory().createOMDocType(null, "root", null, "my.dtd", null);
XMLStreamWriter writer = mock(XMLStreamWriter.class);
doctype.serialize(writer);
verify(writer).writeDTD("<!DOCTYPE root SYSTEM \"my.dtd\">");
verify(writer, atMost(1)).flush();
verifyNoMoreInteractions(writer);
}
use of javax.xml.stream.XMLStreamWriter in project webservices-axiom by apache.
the class PushOMDataSourceReader method proceed.
@Override
public boolean proceed() throws StreamException {
// TODO: we might want to unwrap the NamespaceRepairingFilter (and some other filters) here
XmlHandler handler = this.handler;
OMOutputFormat format = null;
XmlHandler current = handler;
while (current instanceof XmlHandlerWrapper) {
if (current instanceof XmlDeclarationRewriterHandler) {
format = ((XmlDeclarationRewriterHandler) current).getFormat();
break;
}
current = ((XmlHandlerWrapper) current).getParent();
}
if (format == null) {
// This is for the OMSourcedElement expansion case
format = new OMOutputFormat();
format.setDoOptimize(true);
handler = new PushOMDataSourceXOPHandler(handler);
}
try {
XMLStreamWriter writer = new XmlHandlerStreamWriter(handler, null, AxiomXMLStreamWriterExtensionFactory.INSTANCE);
// Seed the namespace context with the namespace context from the parent
OMContainer parent = root.getParent();
if (parent instanceof OMElement) {
for (Iterator<OMNamespace> it = ((OMElement) parent).getNamespacesInScope(); it.hasNext(); ) {
OMNamespace ns = it.next();
writer.setPrefix(ns.getPrefix(), ns.getNamespaceURI());
}
}
handler.startFragment();
dataSource.serialize(new MTOMXMLStreamWriterImpl(new PushOMDataSourceStreamWriter(writer), format));
handler.completed();
} catch (XMLStreamException ex) {
Throwable cause = ex.getCause();
if (cause instanceof StreamException) {
throw (StreamException) cause;
} else {
throw new StreamException(ex);
}
}
return true;
}
Aggregations