use of org.apache.cxf.io.CachedWriter in project cxf by apache.
the class XSLTInterceptorsTest method outXMLStreamTest.
@Test
public void outXMLStreamTest() throws XMLStreamException, SAXException, IOException, ParserConfigurationException {
CachedWriter cWriter = new CachedWriter();
cWriter.holdTempFile();
XMLStreamWriter xWriter = StaxUtils.createXMLStreamWriter(cWriter);
message.setContent(XMLStreamWriter.class, xWriter);
outInterceptor.handleMessage(message);
XMLStreamWriter tXWriter = message.getContent(XMLStreamWriter.class);
StaxUtils.copy(new StreamSource(messageIS), tXWriter);
tXWriter.close();
cWriter.releaseTempFileHold();
Document doc = StaxUtils.read(cWriter.getReader());
Assert.assertTrue("Message was not transformed", checkTransformedXML(doc));
}
use of org.apache.cxf.io.CachedWriter in project cxf by apache.
the class LoggingInInterceptor method logReader.
protected void logReader(Message message, Reader reader, LoggingMessage buffer) {
try {
CachedWriter writer = new CachedWriter();
IOUtils.copyAndCloseInput(reader, writer);
message.setContent(Reader.class, writer.getReader());
if (writer.getTempFile() != null) {
// large thing on disk...
buffer.getMessage().append("\nMessage (saved to tmp file):\n");
buffer.getMessage().append("Filename: " + writer.getTempFile().getAbsolutePath() + "\n");
}
if (writer.size() > limit && limit != -1) {
buffer.getMessage().append("(message truncated to " + limit + " bytes)\n");
}
writer.writeCacheTo(buffer.getPayload(), limit);
} catch (Exception e) {
throw new Fault(e);
}
}
use of org.apache.cxf.io.CachedWriter in project cxf by apache.
the class XSLTInterceptorsTest method outWriterStreamTest.
@Test
public void outWriterStreamTest() throws Exception {
CachedWriter cWriter = new CachedWriter();
message.setContent(Writer.class, cWriter);
outInterceptor.handleMessage(message);
Writer tWriter = message.getContent(Writer.class);
IOUtils.copy(new InputStreamReader(messageIS), tWriter, IOUtils.DEFAULT_BUFFER_SIZE);
tWriter.close();
Document doc = StaxUtils.read(cWriter.getReader());
Assert.assertTrue("Message was not transformed", checkTransformedXML(doc));
}
use of org.apache.cxf.io.CachedWriter in project cxf by apache.
the class XSLTOutInterceptor method transformXWriter.
protected void transformXWriter(Message message, XMLStreamWriter xWriter) {
CachedWriter writer = new CachedWriter();
XMLStreamWriter delegate = StaxUtils.createXMLStreamWriter(writer);
XSLTStreamWriter wrapper = new XSLTStreamWriter(getXSLTTemplate(), writer, delegate, xWriter);
message.setContent(XMLStreamWriter.class, wrapper);
message.put(AbstractOutDatabindingInterceptor.DISABLE_OUTPUTSTREAM_OPTIMIZATION, Boolean.TRUE);
}
use of org.apache.cxf.io.CachedWriter in project cxf by apache.
the class XSLTUtils method transform.
public static Reader transform(Templates xsltTemplate, Reader inReader) {
CachedWriter outWriter = new CachedWriter();
try {
XMLStreamReader reader = StaxUtils.createXMLStreamReader(inReader);
Source beforeSource = new StaxSource(reader);
Transformer trans = xsltTemplate.newTransformer();
trans.transform(beforeSource, new StreamResult(outWriter));
return outWriter.getReader();
} catch (IOException e) {
throw new Fault("GET_CACHED_INPUT_STREAM", LOG, e, e.getMessage());
} catch (TransformerException e) {
throw new Fault("XML_TRANSFORM", LOG, e, e.getMessage());
} finally {
try {
inReader.close();
} catch (Exception e) {
// ignore
}
try {
outWriter.close();
} catch (Exception e) {
// ignore
}
}
}
Aggregations