Java Code Examples for org.apache.cxf.message.message#removeContent()

The following examples show how to use org.apache.cxf.message.message#removeContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WSS4JStaxOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void handleMessageInternal(Message mc) throws Fault {
    try {
        XMLStreamWriter xtw = mc.getContent(XMLStreamWriter.class);
        if (xtw != null) {
            xtw.writeEndDocument();
            xtw.flush();
            xtw.close();
        }

        OutputStream os = (OutputStream) mc.get(OUTPUT_STREAM_HOLDER);
        if (os != null) {
            mc.setContent(OutputStream.class, os);
        }
        mc.removeContent(XMLStreamWriter.class);
    } catch (XMLStreamException e) {
        throw new Fault(e);
    }
}
 
Example 2
Source File: XmlSecOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(Message mc) throws Fault {
    try {
        XMLStreamWriter xtw = mc.getContent(XMLStreamWriter.class);
        if (xtw != null) {
            xtw.writeEndDocument();
            xtw.flush();
            xtw.close();
        }

        OutputStream os = (OutputStream) mc.get(OUTPUT_STREAM_HOLDER);
        if (os != null) {
            mc.setContent(OutputStream.class, os);
        }
        mc.removeContent(XMLStreamWriter.class);
    } catch (XMLStreamException e) {
        throw new Fault(e);
    }
}
 
Example 3
Source File: AbstractHTTPDestination.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void close(Message msg) throws IOException {
    super.close(msg);
    if (msg.getExchange() == null) {
        return;
    }
    Message m = msg.getExchange().getInMessage();
    if (m == null) {
        return;
    }
    InputStream is = m.getContent(InputStream.class);
    if (is != null) {
        try {
            is.close();
            m.removeContent(InputStream.class);
        } catch (IOException ioex) {
            //ignore
        }
    }
}
 
Example 4
Source File: TransformOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    if (!isHttpVerbSupported(message)) {
        return;
    }

    if (contextPropertyName != null
        && !MessageUtils.getContextualBoolean(message.getExchange().getInMessage(),
                                           contextPropertyName,
                                           false)) {
        return;
    }

    if (skipOnFault && null != message.getContent(Exception.class)
        || MessageUtils.getContextualBoolean(message, TRANSFORM_SKIP, false)) {
        return;
    }

    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
    OutputStream out = message.getContent(OutputStream.class);

    XMLStreamWriter transformWriter = createTransformWriterIfNeeded(writer, out);
    if (transformWriter != null) {
        message.setContent(XMLStreamWriter.class, transformWriter);
        if (message.getContextualProperty(DISABLE_OUTPUTSTREAM_OPTIMIZATION) == null) {
            message.put(DISABLE_OUTPUTSTREAM_OPTIMIZATION, Boolean.TRUE);
        }
        if (MessageUtils.isRequestor(message)) {
            message.removeContent(OutputStream.class);
            message.put(OUTPUT_STREAM_HOLDER, out);
            message.getInterceptorChain().add(ENDING);
        }
    }
}
 
Example 5
Source File: OutgoingChainInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void closeInput(Message message) {
    InputStream is = message.getContent(InputStream.class);
    if (is != null) {
        try {
            is.close();
            message.removeContent(InputStream.class);
        } catch (IOException ioex) {
            //ignore
        }
    }
}
 
Example 6
Source File: StaxInEndingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    XMLStreamReader xtr = message.getContent(XMLStreamReader.class);
    if (xtr != null && !MessageUtils.getContextualBoolean(message, STAX_IN_NOCLOSE, false)) {
        try {
            StaxUtils.close(xtr);
        } catch (XMLStreamException ex) {
            throw new Fault(ex);
        }
        message.removeContent(XMLStreamReader.class);
    }
}
 
Example 7
Source File: StaxOutEndingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    try {
        XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
        if (xtw != null) {
            try {
                xtw.writeEndDocument();
                xtw.flush();
            } finally {
                StaxUtils.close(xtw);
            }
        }

        OutputStream os = (OutputStream)message.get(outStreamHolder);
        if (os != null) {
            message.setContent(OutputStream.class, os);
        }
        if (writerHolder != null) {
            Writer w = (Writer)message.get(writerHolder);
            if (w != null) {
                message.setContent(Writer.class, w);
            }
        }
        message.removeContent(XMLStreamWriter.class);
    } catch (XMLStreamException e) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
    }
}
 
Example 8
Source File: StaxOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("resource")
public void handleMessage(Message message) {
    OutputStream os = message.getContent(OutputStream.class);
    XMLStreamWriter xwriter = message.getContent(XMLStreamWriter.class);
    Writer writer = null;
    if (os == null) {
        writer = message.getContent(Writer.class);
    }
    if ((os == null && writer == null) || xwriter != null) {
        return;
    }

    String encoding = getEncoding(message);

    try {
        XMLOutputFactory factory = getXMLOutputFactory(message);
        if (factory == null) {
            if (writer == null) {
                os = setupOutputStream(os);
                xwriter = StaxUtils.createXMLStreamWriter(os, encoding);
            } else {
                xwriter = StaxUtils.createXMLStreamWriter(writer);
            }
        } else {
            if (PropertyUtils.isTrue(message.getContextualProperty(Message.THREAD_SAFE_STAX_FACTORIES))) {
                if (writer == null) {
                    os = setupOutputStream(os);
                    xwriter = factory.createXMLStreamWriter(os, encoding);
                } else {
                    xwriter = factory.createXMLStreamWriter(writer);
                }
            } else {
                synchronized (factory) {
                    if (writer == null) {
                        os = setupOutputStream(os);
                        xwriter = factory.createXMLStreamWriter(os, encoding);
                    } else {
                        xwriter = factory.createXMLStreamWriter(writer);
                    }
                }
            }
        }
        if (MessageUtils.getContextualBoolean(message, FORCE_START_DOCUMENT, false)) {
            xwriter.writeStartDocument(encoding, "1.0");
            message.removeContent(OutputStream.class);
            message.put(OUTPUT_STREAM_HOLDER, os);
            message.removeContent(Writer.class);
            message.put(WRITER_HOLDER, writer);
        }
    } catch (XMLStreamException e) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("STREAM_CREATE_EXC", BUNDLE), e);
    }
    message.setContent(XMLStreamWriter.class, xwriter);

    // Add a final interceptor to write end elements
    message.getInterceptorChain().add(ENDING);
}