use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class LoggingOutInterceptorTest method testCachedOutputStreamThreshold.
@Test
public void testCachedOutputStreamThreshold() throws Exception {
byte[] mex = "<test><threshold/></test>".getBytes();
LoggingOutInterceptor p = new LoggingOutInterceptor();
p.setInMemThreshold(mex.length);
CachedOutputStream cos = handleAndGetCachedOutputStream(p);
cos.write(mex);
assertNull(cos.getTempFile());
cos.write("a".getBytes());
assertNotNull(cos.getTempFile());
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class XSLTInterceptorsTest method outStreamTest.
@Test
public void outStreamTest() throws Exception {
CachedOutputStream cos = new CachedOutputStream();
cos.holdTempFile();
message.setContent(OutputStream.class, cos);
outInterceptor.handleMessage(message);
OutputStream os = message.getContent(OutputStream.class);
IOUtils.copy(messageIS, os);
os.close();
cos.releaseTempFileHold();
Document doc = StaxUtils.read(cos.getInputStream());
Assert.assertTrue("Message was not transformed", checkTransformedXML(doc));
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class StreamInterceptor method handleMessage.
public void handleMessage(Message message) {
// TODO
boolean isOutbound = false;
isOutbound = message == message.getExchange().getOutMessage() || message == message.getExchange().getOutFaultMessage();
if (isOutbound) {
OutputStream os = message.getContent(OutputStream.class);
CachedStream cs = new CachedStream();
message.setContent(OutputStream.class, cs);
message.getInterceptorChain().doIntercept(message);
try {
cs.flush();
CachedOutputStream csnew = (CachedOutputStream) message.getContent(OutputStream.class);
GZIPOutputStream zipOutput = new GZIPOutputStream(os);
CachedOutputStream.copyStream(csnew.getInputStream(), zipOutput, 1024);
cs.close();
zipOutput.close();
os.flush();
message.setContent(OutputStream.class, os);
} catch (IOException ioe) {
ioe.printStackTrace();
}
} else {
try {
InputStream is = message.getContent(InputStream.class);
GZIPInputStream zipInput = new GZIPInputStream(is);
message.setContent(InputStream.class, zipInput);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class HugeResponseInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
if (type.equals(ResponseInterceptorType.overflow)) {
throw new StackOverflowError();
} else if (type.equals(ResponseInterceptorType.ElementLevelThreshold)) {
InputStream is = message.getContent(InputStream.class);
if (is != null) {
CachedOutputStream bos = new CachedOutputStream();
try {
is = getClass().getClassLoader().getResourceAsStream("org/apache/cxf/systests/forked/dispatch/GreetMeDocLiteralRespBreakThreshold.xml");
IOUtils.copy(is, bos);
bos.flush();
is.close();
message.setContent(InputStream.class, bos.getInputStream());
bos.close();
message.setContent(InputStream.class, bos.getInputStream());
} catch (IOException e) {
throw new Fault(e);
}
}
} else if (type.equals(ResponseInterceptorType.ElementCountThreshold)) {
InputStream is = message.getContent(InputStream.class);
if (is != null) {
CachedOutputStream bos = new CachedOutputStream();
try {
is = getClass().getClassLoader().getResourceAsStream("org/apache/cxf/systests/forked/dispatch/" + "GreetMeDocLiteralRespBreakElementCountThreshold.xml");
IOUtils.copy(is, bos);
bos.flush();
is.close();
message.setContent(InputStream.class, bos.getInputStream());
bos.close();
message.setContent(InputStream.class, bos.getInputStream());
} catch (IOException e) {
throw new Fault(e);
}
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class MalformedResponseInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
InputStream is = message.getContent(InputStream.class);
if (is != null) {
CachedOutputStream bos = new CachedOutputStream();
try {
// intend to change response as malformed message
is = getClass().getClassLoader().getResourceAsStream("org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralRespMalformed.xml");
IOUtils.copy(is, bos);
bos.flush();
is.close();
message.setContent(InputStream.class, bos.getInputStream());
bos.close();
message.setContent(InputStream.class, bos.getInputStream());
} catch (IOException e) {
throw new Fault(e);
}
}
}
Aggregations