use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class AttachmentUtilTest method bigIntAsAttachmentMemoryThreshold.
@Test
public void bigIntAsAttachmentMemoryThreshold() throws IOException {
BigInteger bigInteger = new BigInteger(String.valueOf(Long.MAX_VALUE));
try (CachedOutputStream cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, bigInteger)) {
assertEquals(bigInteger.longValue(), cos.getThreshold());
}
// Overflow long value
bigInteger = bigInteger.add(BigInteger.ONE);
try (CachedOutputStream cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, bigInteger)) {
assertEquals(AttachmentDeserializer.THRESHOLD, cos.getThreshold());
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class AttachmentUtilTest method bigIntAsAttachmentMaxSize.
@Test
public void bigIntAsAttachmentMaxSize() throws IOException {
CachedOutputStream cos = createMock(CachedOutputStream.class);
BigInteger bigInteger = new BigInteger(String.valueOf(Long.MAX_VALUE));
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, bigInteger, cos);
replay(cos);
cos.setMaxSize(bigInteger.longValue());
cos.setThreshold(102400L);
verify(cos);
// Overflow long value
bigInteger = bigInteger.add(BigInteger.ONE);
cos = createMock(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, bigInteger, cos);
replay(cos);
cos.setThreshold(102400L);
verify(cos);
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class JAXRSOutInterceptor method checkCachedStream.
private void checkCachedStream(Message m, OutputStream osOriginal, boolean enabled) throws Exception {
final XMLStreamWriter writer;
if (enabled) {
writer = m.getContent(XMLStreamWriter.class);
} else {
writer = (XMLStreamWriter) m.get(XMLStreamWriter.class.getName());
}
if (writer instanceof CachingXmlEventWriter) {
CachingXmlEventWriter cache = (CachingXmlEventWriter) writer;
if (!cache.getEvents().isEmpty()) {
XMLStreamWriter origWriter = null;
try {
origWriter = StaxUtils.createXMLStreamWriter(osOriginal);
for (XMLEvent event : cache.getEvents()) {
StaxUtils.writeEvent(event, origWriter);
}
} finally {
StaxUtils.close(origWriter);
}
}
m.setContent(XMLStreamWriter.class, null);
return;
}
if (enabled) {
OutputStream os = m.getContent(OutputStream.class);
if (os != osOriginal && os instanceof CachedOutputStream) {
CachedOutputStream cos = (CachedOutputStream) os;
if (cos.size() != 0) {
cos.writeCacheTo(osOriginal);
}
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class JAXRSOutInterceptor method checkBufferingMode.
private boolean checkBufferingMode(Message m, List<WriterInterceptor> writers, boolean firstTry) {
if (!firstTry) {
return false;
}
WriterInterceptor last = writers.get(writers.size() - 1);
MessageBodyWriter<Object> w = ((WriterInterceptorMBW) last).getMBW();
Object outBuf = m.getContextualProperty(OUT_BUFFERING);
boolean enabled = PropertyUtils.isTrue(outBuf);
boolean configurableProvider = w instanceof AbstractConfigurableProvider;
if (!enabled && outBuf == null && configurableProvider) {
enabled = ((AbstractConfigurableProvider) w).getEnableBuffering();
}
if (enabled) {
boolean streamingOn = configurableProvider && ((AbstractConfigurableProvider) w).getEnableStreaming();
if (streamingOn) {
m.setContent(XMLStreamWriter.class, new CachingXmlEventWriter());
} else {
m.setContent(OutputStream.class, new CachedOutputStream());
}
}
return enabled;
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class PersistInInterceptor method getSoapRequest.
/**
* Copied from LoggingInInterceptor
*
* @param soapMessage
*/
private void getSoapRequest(Message soapMessage, ExchangeData exchange) {
InputStream is = soapMessage.getContent(InputStream.class);
if (is != null) {
CachedOutputStream bos = new CachedOutputStream();
try {
IOUtils.copy(is, bos);
bos.flush();
is.close();
soapMessage.setContent(InputStream.class, bos.getInputStream());
StringBuilder builder = new StringBuilder();
bos.writeCacheTo(builder, bos.size());
bos.close();
exchange.setRequest(builder.toString());
exchange.setRequestSize((int) bos.size());
} catch (IOException e) {
throw new Fault(e);
}
}
}
Aggregations