Package org.apache.cxf.io

Examples of org.apache.cxf.io.CachedOutputStream


                endpoint.getHeaderFilterStrategy(), exchange, false);
        org.apache.cxf.message.Exchange cxfExchange = outMessage.getExchange();
        InterceptorChain chain = OutgoingChainInterceptor.getOutInterceptorChain(cxfExchange);
        outMessage.setInterceptorChain(chain);
        chain.doIntercept(outMessage);
        CachedOutputStream outputStream = (CachedOutputStream)outMessage.getContent(OutputStream.class);
        exchange.getOut().setBody(outputStream.getInputStream());
    }
View Full Code Here


        }
       
        @Override
        public void close() throws IOException {
            if (!chunking && wrappedStream != null) {
                CachedOutputStream out = (CachedOutputStream)wrappedStream;
                this.basicEntity.setContentLength(out.size());
                wrappedStream = null;
                handleHeadersTrustCaching();
                out.writeCacheTo(wrappedStream);
            }
            super.close();
        }
View Full Code Here

        @Override
        protected void onFirstWrite() throws IOException {
            if (chunking) {
                super.onFirstWrite();
            } else {
                wrappedStream = new CachedOutputStream();
            }
        }
View Full Code Here

                  Type genericType, String enc, OutputStream os, boolean isCollection) throws Exception {
        OutputStream actualOs = os;
       
        MessageContext mc = getContext();
        if (mc != null && MessageUtils.isTrue(mc.get(Marshaller.JAXB_FORMATTED_OUTPUT))) {
            actualOs = new CachedOutputStream();   
        }
        XMLStreamWriter writer = createWriter(actualObject, actualClass, genericType, enc,
                                              actualOs, isCollection);
        ms.marshal(actualObject, writer);
        writer.close();
View Full Code Here

            }
        }
    }

    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 {
            StaxUtils.close(xReader);
            try {
                cachedOS.close();
            } catch (IOException e) {
                LOG.warning("Cannot close stream after transformation: " + e.getMessage());
            }
        }
    }
View Full Code Here

    }

    private InputStream getInputStream(XMLStreamReader input)
        throws XMLStreamException, IOException {
       
        CachedOutputStream out = new CachedOutputStream();
        try {
            StaxUtils.copy(input, out);
            return out.getInputStream();
        } finally {
            out.close();
        }
    }
View Full Code Here

    public static InputStream transform(Templates xsltTemplate, InputStream in) {
        try {
            XMLStreamReader reader = StaxUtils.createXMLStreamReader(in);
            Source beforeSource = new StaxSource(reader);
            CachedOutputStream out = new CachedOutputStream();

            Transformer trans = xsltTemplate.newTransformer();
            trans.transform(beforeSource, new StreamResult(out));

            return out.getInputStream();
        } catch (IOException e) {
            throw new Fault("GET_CACHED_INPUT_STREAM", LOG, e, e.getMessage());
        } catch (TransformerException e) {
            throw new Fault("XML_TRANSFORM", LOG, e, e.getMessage());
        }
View Full Code Here

            // It appears adopting and removing nodes
            // leaves some stale refs/state with adopted nodes and thus the digest ends up
            // being wrong on the server side if XML sig is applied later in the enveloped mode
            // TODO: this is not critical now - but figure out if we can avoid copying
            // DOMs
            CachedOutputStream bos = new CachedOutputStream();
            StaxUtils.writeTo(newDoc, bos);
            return StaxUtils.read(bos.getInputStream());
        } else {
            return newDoc;
        }
    }
View Full Code Here

            //cache this inputstream since it's defer to use in case of async
            try {
                InputStream in = inMessage.getContent(InputStream.class);
                if (in != null) {
                    CachedOutputStream cos = new CachedOutputStream();
                    IOUtils.copy(in, cos);
                    inMessage.setContent(InputStream.class, cos.getInputStream());
                }
                incomingObserver.onMessage(inMessage);
            } catch (IOException e) {
                e.printStackTrace();
            }
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

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.