Search in sources :

Example 6 with CachingXmlEventWriter

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;
}
Also used : WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) WriterInterceptorMBW(org.apache.cxf.jaxrs.impl.WriterInterceptorMBW) AbstractConfigurableProvider(org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider) CachingXmlEventWriter(org.apache.cxf.staxutils.CachingXmlEventWriter) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 7 with CachingXmlEventWriter

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);
            }
        }
    }
}
Also used : XMLStreamWriter(javax.xml.stream.XMLStreamWriter) OutputStream(java.io.OutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) XMLEvent(javax.xml.stream.events.XMLEvent) CachingXmlEventWriter(org.apache.cxf.staxutils.CachingXmlEventWriter) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Aggregations

CachingXmlEventWriter (org.apache.cxf.staxutils.CachingXmlEventWriter)7 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)5 XMLEvent (javax.xml.stream.events.XMLEvent)5 OutputStream (java.io.OutputStream)4 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)4 XMLStreamException (javax.xml.stream.XMLStreamException)3 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)3 WriterInterceptor (javax.ws.rs.ext.WriterInterceptor)2 Fault (org.apache.cxf.interceptor.Fault)2 WriterInterceptorMBW (org.apache.cxf.jaxrs.impl.WriterInterceptorMBW)2 AbstractConfigurableProvider (org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider)2 Service (org.apache.cxf.service.Service)2 NamespaceContext (javax.xml.namespace.NamespaceContext)1 NSStack (org.apache.cxf.helpers.NSStack)1 MessageContentsList (org.apache.cxf.message.MessageContentsList)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1