Package org.apache.cxf.io

Examples of org.apache.cxf.io.CachedOutputStream


        // Until then, we keep this interceptor here and utilize the robust
        // option to avoid the unnecessary message capturing/caching.
        if (!MessageUtils.isTrue(message.getContextualProperty(Message.ROBUST_ONEWAY))) {
            InputStream is = message.getContent(InputStream.class);
            if (is != null) {
                CachedOutputStream saved = new CachedOutputStream();
                try {
                    IOUtils.copy(is, saved);

                    saved.flush();
                    is.close();
                    saved.lockOutputStream();

                    LOG.fine("Capturing the original RM message");
                    RewindableInputStream ris = RewindableInputStream.makeRewindable(saved.getInputStream());
                    message.setContent(InputStream.class, ris);
                    message.put(RMMessageConstants.SAVED_CONTENT, ris);
                } catch (Exception e) {
                    throw new Fault(e);
                }
View Full Code Here


     */
    public static RewindableInputStream makeRewindable(InputStream is) throws IOException {
        if (is.markSupported()) {
            return new RewindableInputStream(is);
        }
        CachedOutputStream os = new CachedOutputStream(MEMORY_SIZE_LIMIT);
        CachedOutputStream.copyStream(is, os, COPY_BLOCK_SIZE);
        return new RewindableInputStream(os);
    }
View Full Code Here

            throw new Fault(e);
        }
    }
    protected void logInputStream(Message message, InputStream is, LoggingMessage buffer,
                                  String encoding, String ct) {
        CachedOutputStream bos = new CachedOutputStream();
        if (threshold > 0) {
            bos.setThreshold(threshold);
        }
        try {
            // use the appropriate input stream and restore it later
            InputStream bis = is instanceof DelegatingInputStream
                ? ((DelegatingInputStream)is).getInputStream() : is;
           

            //only copy up to the limit since that's all we need to log
            //we can stream the rest
            IOUtils.copyAtLeast(bis, bos, limit);
            bos.flush();
            bis = new SequenceInputStream(bos.getInputStream(), bis);
           
            // restore the delegating input stream or the input stream
            if (is instanceof DelegatingInputStream) {
                ((DelegatingInputStream)is).setInputStream(bis);
            } else {
                message.setContent(InputStream.class, bis);
            }

            if (bos.getTempFile() != null) {
                //large thing on disk...
                buffer.getMessage().append("\nMessage (saved to tmp file):\n");
                buffer.getMessage().append("Filename: " + bos.getTempFile().getAbsolutePath() + "\n");
            }
            if (bos.size() > limit) {
                buffer.getMessage().append("(message truncated to " + limit + " bytes)\n");
            }
            writePayload(buffer.getPayload(), bos, encoding, ct);
               
            bos.close();
        } catch (Exception e) {
            throw new Fault(e);
        }
    }
View Full Code Here

    private CxfUtils() {
        // helper class
    }
   
    public static String getStringFromInputStream(InputStream in) throws Exception {
        CachedOutputStream bos = new CachedOutputStream();
        IOUtils.copy(in, bos);
        in.close();
        bos.close();
        return bos.getOut().toString();
    }
View Full Code Here

    }
   
    @Test
    public void testContentCachedOutputStream() throws Exception {
        RMMessage msg = new RMMessage();
        CachedOutputStream co = new CachedOutputStream();
        co.write(DATA);
        msg.setContent(co.getInputStream());
       
        byte[] msgbytes = IOUtils.readBytesFromStream(msg.getContent());
       
        assertArrayEquals(DATA, msgbytes);
        co.close();
    }
View Full Code Here

   
    public static void restoreForm(FormEncodingProvider<Form> provider,
                                   Form form,
                                   Message message)
        throws Exception {
        CachedOutputStream os = new CachedOutputStream();
        writeForm(provider, form, os);
        message.setContent(InputStream.class, os.getInputStream());
    }
View Full Code Here

    @Override
    protected Object unmarshalFromReader(Unmarshaller unmarshaller, XMLStreamReader reader,
                                         Annotation[] anns, MediaType mt)
        throws JAXBException {
        CachedOutputStream out = new CachedOutputStream();
        try {
            XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
            StaxUtils.copy(new StaxSource(reader), writer);
            writer.writeEndDocument();
            writer.flush();
            writer.close();
            return unmarshalFromInputStream(unmarshaller, out.getInputStream(), anns, mt);
        } catch (Exception ex) {
            throw ExceptionUtils.toBadRequestException(ex, null);
        }
    }
View Full Code Here

   
    @Override
    protected void marshalToWriter(Marshaller ms, Object obj, XMLStreamWriter writer,
                                   Annotation[] anns, MediaType mt)
        throws Exception {
        CachedOutputStream out = new CachedOutputStream();
        marshalToOutputStream(ms, obj, out, anns, mt);
       
        StaxUtils.copy(new StreamSource(out.getInputStream()), writer);
    }
View Full Code Here

                    testFeature.faultInInterceptorCalled());
        }
    }

    private String getStringFromInputStream(InputStream in) throws Exception {       
        CachedOutputStream bos = new CachedOutputStream();
        IOUtils.copy(in, bos);
        in.close();
        bos.close();
        return bos.getOut().toString();       
    }
View Full Code Here

            get.releaseConnection();
        }
    }
   
    private InputStream copyIn(InputStream in) throws Exception {
        CachedOutputStream bos = new CachedOutputStream();
        IOUtils.copy(in, bos);
        in.close();
        in = bos.getInputStream();
        bos.close();
        return in;
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.io.CachedOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.