Package org.apache.camel

Examples of org.apache.camel.StreamCache


    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


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

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

        assertMockEndpointsSatisfied();
        Exchange exchange = a.getExchanges().get(0);
        StreamCache streamCache = assertIsInstanceOf(StreamCache.class, exchange.getIn().getBody());
        assertNotNull(streamCache);
    }
View Full Code Here

        return "StreamCachingInterceptor[" + processor + "]";
    }

    @Override
    public boolean process(Exchange exchange, AsyncCallback callback) {
        StreamCache newBody = exchange.getIn().getBody(StreamCache.class);
        if (newBody != null) {
            exchange.getIn().setBody(newBody);
        }
        MessageHelper.resetStreamCache(exchange.getIn());
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

        } else if (obj instanceof GenericFile || obj instanceof File) {
            return prepend + "[Body is file based: " + obj + "]";
        }

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

        // grab the message body as a string
        String body;
        if (message.getExchange() != null) {
            body = message.getExchange().getContext().getTypeConverter().convertTo(String.class, obj);
        } else {
            body = obj.toString();
        }

        // reset stream cache after use
        if (cache != null) {
            cache.reset();
        }

        if (body == null) {
            return prepend + "[Body is null]";
        }
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
        StreamCache cache;
        if (obj instanceof StreamCache) {
            cache = (StreamCache)obj;
        } else {
            cache = null;
        }

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

        // reset stream cache after use
        if (cache != null) {
            cache.reset();
        }

        if (body == null) {
            return prepend + "[Body is null]";
        }
View Full Code Here

        bulkClient.getRequest(jobId, batchId, new BulkApiClient.StreamResponseCallback() {
            @Override
            public void onResponse(InputStream inputStream, SalesforceException ex) {
                // read the request stream into a StreamCache temp file
                // ensures the connection is read
                StreamCache body = null;
                if (inputStream != null) {
                    try {
                        body = StreamCacheConverter.convertToStreamCache(inputStream, exchange);
                    } catch (IOException e) {
                        String msg = "Error retrieving batch request: " + e.getMessage();
View Full Code Here

        bulkClient.getResults(jobId, batchId, new BulkApiClient.StreamResponseCallback() {
            @Override
            public void onResponse(InputStream inputStream, SalesforceException ex) {
                // read the result stream into a StreamCache temp file
                // ensures the connection is read
                StreamCache body = null;
                if (inputStream != null) {
                    try {
                        body = StreamCacheConverter.convertToStreamCache(inputStream, exchange);
                    } catch (IOException e) {
                        String msg = "Error retrieving batch results: " + e.getMessage();
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.