use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class XSLTInInterceptor method transformXReader.
protected void transformXReader(Message message, XMLStreamReader xReader) {
CachedOutputStream cachedOS = new CachedOutputStream();
try {
StaxUtils.copy(xReader, cachedOS);
InputStream transformedIS = XSLTUtils.transform(getXSLTTemplate(), cachedOS.getInputStream());
XMLStreamReader transformedReader = StaxUtils.createXMLStreamReader(transformedIS);
message.setContent(XMLStreamReader.class, transformedReader);
} catch (XMLStreamException e) {
throw new Fault("STAX_COPY", LOG, e, e.getMessage());
} catch (IOException e) {
throw new Fault("GET_CACHED_INPUT_STREAM", LOG, e, e.getMessage());
} finally {
try {
StaxUtils.close(xReader);
} catch (XMLStreamException ex) {
throw new Fault(ex);
}
try {
cachedOS.close();
} catch (IOException e) {
LOG.warning("Cannot close stream after transformation: " + e.getMessage());
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class XSLTUtils method transform.
public static InputStream transform(Templates xsltTemplate, InputStream in) {
try (InputStream inputStream = in;
CachedOutputStream out = new CachedOutputStream()) {
Source beforeSource = new StaxSource(StaxUtils.createXMLStreamReader(inputStream));
Transformer trans = xsltTemplate.newTransformer();
trans.transform(beforeSource, new StreamResult(out));
return out.getInputStream();
} 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());
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class AttachmentUtilTest method numberStringAsAttachmentMaxSize.
@Test
public void numberStringAsAttachmentMaxSize() throws IOException {
CachedOutputStream cos = createMock(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, "12345", cos);
replay(cos);
cos.setMaxSize(12345);
cos.setThreshold(102400L);
verify(cos);
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class AttachmentUtilTest method stringAsAttachmentDirectory.
@Test
public void stringAsAttachmentDirectory() throws IOException {
String attachmentDirectory = "/dev/null";
CachedOutputStream cos = createMock(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_DIRECTORY, attachmentDirectory, cos);
replay(cos);
cos.setOutputDir(new File(attachmentDirectory));
cos.setThreshold(102400L);
verify(cos);
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class AttachmentUtilTest method shortAsAttachmentMaxSize.
@Test
public void shortAsAttachmentMaxSize() throws IOException {
CachedOutputStream cos = createMock(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Short.MAX_VALUE, cos);
replay(cos);
cos.setMaxSize(Short.MAX_VALUE);
cos.setThreshold(102400L);
verify(cos);
}
Aggregations