Package org.apache.camel

Examples of org.apache.camel.StreamCache


            resultId = getParameter(RESULT_ID, exchange, USE_BODY, NOT_OPTIONAL);
        }
        bulkClient.getQueryResult(jobId, batchId, resultId, new BulkApiClient.StreamResponseCallback() {
            @Override
            public void onResponse(InputStream inputStream, SalesforceException ex) {
                StreamCache body = null;
                if (inputStream != null) {
                    // read the result stream into a StreamCache temp file
                    // ensures the connection is read
                    try {
                        body = StreamCacheConverter.convertToStreamCache(inputStream, exchange);
View Full Code Here


    @Test
    public void testBlobStorePutWithStreamAndGet() throws InterruptedException, TransformerException {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(MESSAGE.getBytes());
        Exchange exchange = new DefaultExchange(context);
        StreamCache streamCache = StreamCacheConverter.convertToStreamCache(new SAXSource(new InputSource(inputStream)), exchange);
        template.sendBody("direct:put-and-get", streamCache);
        Object result = template.requestBodyAndHeader("direct:put-and-get", null, JcloudsConstants.OPERATION, JcloudsConstants.GET, String.class);
        assertEquals(MESSAGE, result);
    }
View Full Code Here

    public static String extractBodyAsString(Message message) {
        if (message == null) {
            return null;
        }

        StreamCache newBody = message.getBody(StreamCache.class);
        if (newBody != null) {
            message.setBody(newBody);
        }

        Object answer = message.getBody(String.class);
        if (answer == null) {
            answer = message.getBody();
        }

        if (newBody != null) {
            // Reset the InputStreamCache
            newBody.reset();
        }

        return answer != null ? answer.toString() : null;
    }
View Full Code Here

                return prepend + "[Body is file based: " + obj + "]";
            }
        }

        // is the body a stream cache or input stream
        StreamCache cache = null;
        InputStream is = null;
        if (obj instanceof StreamCache) {
            cache = (StreamCache)obj;
            is = null;
        } else if (obj instanceof InputStream) {
            cache = null;
            is = (InputStream) obj;
        }

        // grab the message body as a string
        String body = null;
        if (message.getExchange() != null) {
            try {
                body = message.getExchange().getContext().getTypeConverter().tryConvertTo(String.class, message.getExchange(), obj);
            } catch (Throwable e) {
                // ignore as the body is for logging purpose
            }
        }
        if (body == null) {
            try {
                body = obj.toString();
            } catch (Throwable e) {
                // ignore as the body is for logging purpose
            }
        }

        // reset stream cache after use
        if (cache != null) {
            cache.reset();
        } else if (is != null && is.markSupported()) {
            try {
                is.reset();
            } catch (IOException e) {
                // ignore
View Full Code Here

   
    public void testConvertToStreamCache() throws Exception {
        context.start();

        ByteArrayInputStream inputStream = new ByteArrayInputStream(MESSAGE.getBytes());
        StreamCache streamCache = StreamCacheConverter.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

    public void testConvertToStreamCacheStreamSource() throws Exception {
        context.start();

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

    public void testConvertToSerializable() throws Exception {
        context.start();

        InputStream is = getTestFileStream();
        StreamCache cache = StreamCacheConverter.convertToStreamCache(is, exchange);
        Serializable ser = StreamCacheConverter.convertToSerializable(cache, exchange);
        assertNotNull(ser);
    }
View Full Code Here

    public void testConvertToByteArray() throws Exception {
        context.start();

        InputStream is = getTestFileStream();
        StreamCache cache = StreamCacheConverter.convertToStreamCache(is, exchange);
        byte[] bytes = StreamCacheConverter.convertToByteArray(cache, exchange);
        assertNotNull(bytes);
    }
View Full Code Here

        File file = new File("target/cachedir");
        String[] files = file.list();
        assertEquals("we should have a temp file", files.length, 1);
        assertTrue("The file name should start with cos" , files[0].startsWith("cos"));

        StreamCache cache = cos.newStreamCache();
        assertTrue("Should get the FileInputStreamCache", cache instanceof FileInputStreamCache);
        String temp = toString((InputStream)cache);

        ((InputStream)cache).close();
        assertEquals("we should have a temp file", files.length, 1);
        assertEquals("Cached a wrong file", temp, TEST_STRING);
        exchange.getUnitOfWork().done(exchange);

        try {
            cache.reset();
            // The stream is closed, so the temp file is gone.
            fail("we expect the exception here");
        } catch (Exception exception) {
            // do nothing
        }
View Full Code Here

        java.io.FileInputStream tmpin = new java.io.FileInputStream(new File(file, files[0]));
        String temp = toString(tmpin);
        assertTrue("The content is not encrypted", temp.length() > 0 && temp.indexOf("aaa") < 0);
        tmpin.close();
       
        StreamCache cache = cos.newStreamCache();
        assertTrue("Should get the FileInputStreamCache", cache instanceof FileInputStreamCache);
        temp = toString((InputStream)cache);

        ((InputStream)cache).close();
        assertEquals("we should have a temp file", files.length, 1);
        assertEquals("Cached a wrong file", temp, TEST_STRING);
        exchange.getUnitOfWork().done(exchange);

        try {
            cache.reset();
            // The stream is closed, so the temp file is gone.
            fail("we expect the exception here");
        } catch (Exception exception) {
            // do nothing
        }
View Full Code Here

TOP

Related Classes of org.apache.camel.StreamCache

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.