Search in sources :

Example 11 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.

the class SchemaValidationPolicyAbstractInterceptor method loadCustomSchema.

protected void loadCustomSchema(Message message, String customSchemaPath, @SuppressWarnings("rawtypes") Class c) throws IOException {
    if (customSchemaPath == null || customSchemaPath.trim().isEmpty()) {
        throw new IllegalArgumentException("Path to custom schema is not set or empty");
    }
    String absoluteSchemaPath = null;
    CachedOutputStream cos = new CachedOutputStream();
    absoluteSchemaPath = loadResource(customSchemaPath, cos);
    InputStream customSchemaStream = cos.getInputStream();
    Schema customSchema;
    SchemaResourceResolver resourceResolver = null;
    try {
        if (customSchemaStream == null) {
            throw new IllegalArgumentException("Cannot load custom schema from path: " + customSchemaPath);
        }
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        resourceResolver = new SchemaResourceResolver(absoluteSchemaPath, customSchemaPath);
        factory.setResourceResolver(resourceResolver);
        Source src = new StreamSource(customSchemaStream);
        customSchema = factory.newSchema(src);
    } catch (SAXException e) {
        throw new IllegalArgumentException("Cannot create custom schema from path: " + customSchemaPath + "\n" + e.getMessage(), e);
    } finally {
        try {
            cos.close();
            if (resourceResolver != null) {
                resourceResolver.cleanupCache();
            }
        } catch (IOException e) {
        }
    }
    message.getExchange().getService().getServiceInfos().get(0).setProperty(Schema.class.getName(), customSchema);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Schema(javax.xml.validation.Schema) StreamSource(javax.xml.transform.stream.StreamSource) IOException(java.io.IOException) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) SAXException(org.xml.sax.SAXException)

Example 12 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.

the class InputXSLTUtil method transformXReader.

protected void transformXReader(Message message, XMLStreamReader xReader) {
    CachedOutputStream cachedOS = new CachedOutputStream();
    try {
        StaxUtils.copy(xReader, cachedOS);
        InputStream transformedIS = XSLTUtils.transform(getXSLTTemplate(), cachedOS.getInputStream());
        XMLStreamReader transformedReader = StaxUtils.createXMLStreamReader(transformedIS);
        message.setContent(XMLStreamReader.class, transformedReader);
    } catch (XMLStreamException e) {
        throw new Fault("STAX_COPY", LOG, e, e.getMessage());
    } catch (IOException e) {
        throw new Fault("GET_CACHED_INPUT_STREAM", LOG, e, e.getMessage());
    } finally {
        try {
            StaxUtils.close(xReader);
        } catch (XMLStreamException e) {
            LOG.warning("Cannot close stream after transformation: " + e.getMessage());
        }
        try {
            cachedOS.close();
        } catch (IOException e) {
            LOG.warning("Cannot close stream after transformation: " + e.getMessage());
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) Fault(org.apache.cxf.interceptor.Fault) IOException(java.io.IOException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 13 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.

the class OutputXSLTUtil method transformOS.

protected void transformOS(Message message, OutputStream out) {
    CachedOutputStream wrapper = new CachedOutputStream();
    message.setContent(OutputStream.class, wrapper);
    TransformationOutEndingInterceptor si = new TransformationOutEndingInterceptor(getXSLTTemplate(), out);
    message.getInterceptorChain().add(si);
}
Also used : CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 14 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.

the class CompressionOutInterceptor method wrapOriginalOutputStream.

public void wrapOriginalOutputStream(Message message) throws Fault {
    // remember the original output stream, we will write compressed
    // data to this later
    OutputStream os = message.getContent(OutputStream.class);
    if (os == null) {
        return;
    }
    // new stream to cache the original os
    CachedOutputStream wrapper = new CachedOutputStream();
    CachedOutputStreamCallback callback = new CompressionCachedOutputStreamCallback(os, threshold, message);
    wrapper.registerCallback(callback);
    message.setContent(OutputStream.class, wrapper);
}
Also used : CachedOutputStreamCallback(org.apache.cxf.io.CachedOutputStreamCallback) OutputStream(java.io.OutputStream) AbstractThresholdOutputStream(org.apache.cxf.io.AbstractThresholdOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 15 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.

the class MessageScanerOutInterceptor method wrapOriginalOutputStream.

public void wrapOriginalOutputStream(Message message) throws Fault {
    // remember the original output stream, we will write compressed
    // data to this later
    OutputStream os = message.getContent(OutputStream.class);
    if (os == null) {
        return;
    }
    // new stream to cache the original os
    CachedOutputStream wrapper = new CachedOutputStream();
    callback = new CompressionCachedOutputStreamCallback(os, pattern, throwPatternNotMatchedException);
    wrapper.registerCallback(callback);
    message.setContent(OutputStream.class, wrapper);
}
Also used : OutputStream(java.io.OutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Aggregations

CachedOutputStream (org.apache.cxf.io.CachedOutputStream)105 InputStream (java.io.InputStream)38 IOException (java.io.IOException)35 Test (org.junit.Test)24 Message (org.apache.cxf.message.Message)22 OutputStream (java.io.OutputStream)18 Fault (org.apache.cxf.interceptor.Fault)18 MessageImpl (org.apache.cxf.message.MessageImpl)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 XMLStreamException (javax.xml.stream.XMLStreamException)10 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)10 PrintWriter (java.io.PrintWriter)8 XMLStreamReader (javax.xml.stream.XMLStreamReader)6 StreamSource (javax.xml.transform.stream.StreamSource)6 Endpoint (org.apache.cxf.endpoint.Endpoint)6 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)6 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Source (javax.xml.transform.Source)5 ArrayList (java.util.ArrayList)4