use of org.apache.cxf.staxutils.CachingXmlEventWriter in project tomee 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.staxutils.CachingXmlEventWriter in project tomee 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);
}
}
}
}
Aggregations