Search in sources :

Example 91 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.

the class LoggingOutInterceptorTest method testCachedOutputStreamThreshold.

@Test
public void testCachedOutputStreamThreshold() throws Exception {
    byte[] mex = "<test><threshold/></test>".getBytes();
    LoggingOutInterceptor p = new LoggingOutInterceptor();
    p.setInMemThreshold(mex.length);
    CachedOutputStream cos = handleAndGetCachedOutputStream(p);
    cos.write(mex);
    assertNull(cos.getTempFile());
    cos.write("a".getBytes());
    assertNotNull(cos.getTempFile());
}
Also used : CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Test(org.junit.Test)

Example 92 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.

the class XSLTInterceptorsTest method outStreamTest.

@Test
public void outStreamTest() throws Exception {
    CachedOutputStream cos = new CachedOutputStream();
    cos.holdTempFile();
    message.setContent(OutputStream.class, cos);
    outInterceptor.handleMessage(message);
    OutputStream os = message.getContent(OutputStream.class);
    IOUtils.copy(messageIS, os);
    os.close();
    cos.releaseTempFileHold();
    Document doc = StaxUtils.read(cos.getInputStream());
    Assert.assertTrue("Message was not transformed", checkTransformedXML(doc));
}
Also used : OutputStream(java.io.OutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Document(org.w3c.dom.Document) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Test(org.junit.Test)

Example 93 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.

the class StreamInterceptor method handleMessage.

public void handleMessage(Message message) {
    // TODO
    boolean isOutbound = false;
    isOutbound = message == message.getExchange().getOutMessage() || message == message.getExchange().getOutFaultMessage();
    if (isOutbound) {
        OutputStream os = message.getContent(OutputStream.class);
        CachedStream cs = new CachedStream();
        message.setContent(OutputStream.class, cs);
        message.getInterceptorChain().doIntercept(message);
        try {
            cs.flush();
            CachedOutputStream csnew = (CachedOutputStream) message.getContent(OutputStream.class);
            GZIPOutputStream zipOutput = new GZIPOutputStream(os);
            CachedOutputStream.copyStream(csnew.getInputStream(), zipOutput, 1024);
            cs.close();
            zipOutput.close();
            os.flush();
            message.setContent(OutputStream.class, os);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    } else {
        try {
            InputStream is = message.getContent(InputStream.class);
            GZIPInputStream zipInput = new GZIPInputStream(is);
            message.setContent(InputStream.class, zipInput);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) IOException(java.io.IOException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 94 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.

the class HugeResponseInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    if (type.equals(ResponseInterceptorType.overflow)) {
        throw new StackOverflowError();
    } else if (type.equals(ResponseInterceptorType.ElementLevelThreshold)) {
        InputStream is = message.getContent(InputStream.class);
        if (is != null) {
            CachedOutputStream bos = new CachedOutputStream();
            try {
                is = getClass().getClassLoader().getResourceAsStream("org/apache/cxf/systests/forked/dispatch/GreetMeDocLiteralRespBreakThreshold.xml");
                IOUtils.copy(is, bos);
                bos.flush();
                is.close();
                message.setContent(InputStream.class, bos.getInputStream());
                bos.close();
                message.setContent(InputStream.class, bos.getInputStream());
            } catch (IOException e) {
                throw new Fault(e);
            }
        }
    } else if (type.equals(ResponseInterceptorType.ElementCountThreshold)) {
        InputStream is = message.getContent(InputStream.class);
        if (is != null) {
            CachedOutputStream bos = new CachedOutputStream();
            try {
                is = getClass().getClassLoader().getResourceAsStream("org/apache/cxf/systests/forked/dispatch/" + "GreetMeDocLiteralRespBreakElementCountThreshold.xml");
                IOUtils.copy(is, bos);
                bos.flush();
                is.close();
                message.setContent(InputStream.class, bos.getInputStream());
                bos.close();
                message.setContent(InputStream.class, bos.getInputStream());
            } catch (IOException e) {
                throw new Fault(e);
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) Fault(org.apache.cxf.interceptor.Fault) IOException(java.io.IOException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 95 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.

the class MalformedResponseInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    InputStream is = message.getContent(InputStream.class);
    if (is != null) {
        CachedOutputStream bos = new CachedOutputStream();
        try {
            // intend to change response as malformed message
            is = getClass().getClassLoader().getResourceAsStream("org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralRespMalformed.xml");
            IOUtils.copy(is, bos);
            bos.flush();
            is.close();
            message.setContent(InputStream.class, bos.getInputStream());
            bos.close();
            message.setContent(InputStream.class, bos.getInputStream());
        } catch (IOException e) {
            throw new Fault(e);
        }
    }
}
Also used : InputStream(java.io.InputStream) Fault(org.apache.cxf.interceptor.Fault) IOException(java.io.IOException) 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