Examples of StreamCache


Examples of org.apache.camel.StreamCache

        File file = new File("./target/cachedir");
        String[] files = file.list();

        assertEquals("we should have no temp file", files.length, 0);
        StreamCache cache = cos.getStreamCache();
        assertTrue("Should get the InputStreamCache", cache instanceof InputStreamCache);
        String temp = IOConverter.toString((InputStream)cache, null);
        assertEquals("Cached a wrong file", temp, TEST_STRING);

        exchange.getUnitOfWork().done(exchange);
View Full Code Here

Examples of org.apache.camel.StreamCache

        this.exchange = new DefaultExchange(context);
    }
   
    public void testConvertToStreamCache() throws Exception {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(MESSAGE.getBytes());
        StreamCache streamCache = converter.convertToStreamCache(new SAXSource(new InputSource(inputStream)), exchange);
        String message = exchange.getContext().getTypeConverter().convertTo(String.class, streamCache);
        assertNotNull(message);
        assertEquals("The converted message is wrong", MESSAGE, message);
    }
View Full Code Here

Examples of org.apache.camel.StreamCache

        assertEquals("The converted message is wrong", MESSAGE, message);
    }

    public void testConvertToStreamCacheStreamSource() throws Exception {
        StreamSource source = new StreamSource(getTestFileStream());
        StreamCache cache = converter.convertToStreamCache(source, exchange);
        //assert re-readability of the cached StreamSource
        XmlConverter converter = new XmlConverter();
        assertNotNull(converter.toString((Source)cache));
        cache.reset();
        assertNotNull(converter.toString((Source)cache));
    }
View Full Code Here

Examples of org.apache.camel.converter.stream.StreamCache

    public StreamCachingInterceptor() {
        super();
        setInterceptorLogic(new Processor() {
            public void process(Exchange exchange) throws Exception {
                try {
                    StreamCache newBody = exchange.getIn().getBody(StreamCache.class);
                    if (newBody != null) {
                        newBody.reset();
                        exchange.getIn().setBody(newBody);
                    }
                } catch (NoTypeConversionAvailableException ex) {
                    // ignore if in is not of StreamCache type
                }
View Full Code Here

Examples of org.apache.camel.converter.stream.StreamCache

        UnitOfWork unitOfWork = exchange.getUnitOfWork();
        return unitOfWork.getId();
    }

    protected Object getBodyAsString(Message in) {
        StreamCache newBody = null;
        try {
            newBody = in.getBody(StreamCache.class);
            if (newBody != null) {
                in.setBody(newBody);
            }
        } catch (NoTypeConversionAvailableException ex) {
            // ignore, in not of StreamCache type
        }
       
        Object answer = null;
        try {
            answer = in.getBody(String.class);
        } catch (NoTypeConversionAvailableException ex) {
            answer = in.getBody();
        }
       
        if (newBody != null) {
            // Reset the InputStreamCache
            newBody.reset();
        }
        return answer;
    }
View Full Code Here

Examples of org.apache.camel.converter.stream.StreamCache

        StreamSource message = new StreamSource(new StringReader("<hello>world!</hello>"));
        template.sendBody("direct:a", message);

        assertMockEndpointsSatisifed();
        Exchange exchange = a.getExchanges().get(0);
        StreamCache streamCache = Assertions.assertInstanceOf(exchange.getIn().getBody(), StreamCache.class);
        //assertTrue(a.assertExchangeReceived(0).getIn().getBody() instanceof StreamCache);
    }
View Full Code Here

Examples of org.apache.camel.converter.stream.StreamCache

        MessageHelper.resetStreamCache((Message) null);
        MessageHelper.resetStreamCache(message);
       
        // handle StreamCache
        final ValueHolder<Boolean> reset = new ValueHolder<Boolean>(Boolean.FALSE);
        message.setBody(new StreamCache() {
            public void reset() {
                reset.set(Boolean.TRUE);
            }
        });
        MessageHelper.resetStreamCache(message);
View Full Code Here

Examples of org.apache.camel.converter.stream.StreamCache

        AsyncProcessorHelper.process(this, exchange);
    }

    public boolean process(Exchange exchange, AsyncCallback callback) {
        try {
            StreamCache newBody = exchange.getIn().getBody(StreamCache.class);
            if (newBody != null) {
                exchange.getIn().setBody(newBody);
            }
            MessageHelper.resetStreamCache(exchange.getIn());
        } catch (NoTypeConversionAvailableException ex) {
View Full Code Here

Examples of org.apache.camel.converter.stream.StreamCache

    protected Object getBodyAsString(Message in) {
        if (in == null) {
            return null;
        }
       
        StreamCache newBody = null;
        try {
            newBody = in.getBody(StreamCache.class);
            if (newBody != null) {
                in.setBody(newBody);
            }
        } catch (NoTypeConversionAvailableException ex) {
            // ignore, in not of StreamCache type
        }
       
        Object answer = null;
        try {
            answer = in.getBody(String.class);
        } catch (NoTypeConversionAvailableException ex) {
            answer = in.getBody();
        }
       
        if (newBody != null) {
            // Reset the InputStreamCache
            newBody.reset();
        }
        return answer;
    }
View Full Code Here

Examples of org.apache.camel.converter.stream.StreamCache

    }

    // Implementation methods
    //-------------------------------------------------------------------------
    protected Object getBodyAsString(Message message) {
        StreamCache newBody = null;
        try {
            newBody = message.getBody(StreamCache.class);
            if (newBody != null) {
                message.setBody(newBody);
            }
        } catch (NoTypeConversionAvailableException ex) {
            // ignore
        }
        Object answer = null;
        try {
            answer = message.getBody(String.class);
        } catch (NoTypeConversionAvailableException ex) {
            answer = message.getBody();
        }

        if (newBody != null) {
            // Reset the StreamCache
            newBody.reset();
        }
        return answer;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.