Search in sources :

Example 21 with StreamCache

use of org.apache.camel.StreamCache in project camel by apache.

the class MixedStreamCachingInterceptorTest method testStreamCaching.

public void testStreamCaching() throws Exception {
    MockEndpoint a = getMockEndpoint("mock:a");
    a.expectedMessageCount(1);
    StreamSource message = new StreamSource(new StringReader("<hello>world!</hello>"));
    template.sendBody("direct:a", message);
    assertMockEndpointsSatisfied();
    Exchange exchange = a.getExchanges().get(0);
    StreamCache cache = assertIsInstanceOf(StreamCache.class, exchange.getIn().getBody());
    assertNotNull(cache);
    assertNotSame(message, cache);
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StreamCache(org.apache.camel.StreamCache) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader)

Example 22 with StreamCache

use of org.apache.camel.StreamCache in project camel by apache.

the class StreamCachingInterceptorTest method testStreamCachingInterceptorEnabled.

public void testStreamCachingInterceptorEnabled() throws Exception {
    MockEndpoint a = getMockEndpoint("mock:a");
    a.expectedMessageCount(1);
    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);
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StreamCache(org.apache.camel.StreamCache) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader)

Example 23 with StreamCache

use of org.apache.camel.StreamCache in project camel by apache.

the class ZipkinClientRequestAdapter method requestAnnotations.

@Override
public Collection<KeyValueAnnotation> requestAnnotations() {
    KeyValueAnnotation key1 = KeyValueAnnotation.create("camel.client.endpoint.url", url);
    KeyValueAnnotation key2 = KeyValueAnnotation.create("camel.client.exchange.id", exchange.getExchangeId());
    KeyValueAnnotation key3 = KeyValueAnnotation.create("camel.client.exchange.pattern", exchange.getPattern().name());
    KeyValueAnnotation key4 = null;
    if (eventNotifier.isIncludeMessageBody() || eventNotifier.isIncludeMessageBodyStreams()) {
        boolean streams = eventNotifier.isIncludeMessageBodyStreams();
        StreamCache cache = prepareBodyForLogging(exchange, streams);
        String body = MessageHelper.extractBodyForLogging(exchange.hasOut() ? exchange.getOut() : exchange.getIn(), "", streams, streams);
        key4 = KeyValueAnnotation.create("camel.client.exchange.message.request.body", body);
        if (cache != null) {
            cache.reset();
        }
    }
    List<KeyValueAnnotation> list = new ArrayList<>();
    list.add(key1);
    list.add(key2);
    list.add(key3);
    if (key4 != null) {
        list.add(key4);
    }
    return list;
}
Also used : StreamCache(org.apache.camel.StreamCache) KeyValueAnnotation(com.github.kristofa.brave.KeyValueAnnotation) ArrayList(java.util.ArrayList)

Example 24 with StreamCache

use of org.apache.camel.StreamCache in project camel by apache.

the class ZipkinServerRequestAdapter method requestAnnotations.

@Override
public Collection<KeyValueAnnotation> requestAnnotations() {
    KeyValueAnnotation key1 = KeyValueAnnotation.create("camel.server.endpoint.url", url);
    KeyValueAnnotation key2 = KeyValueAnnotation.create("camel.server.exchange.id", exchange.getExchangeId());
    KeyValueAnnotation key3 = KeyValueAnnotation.create("camel.server.exchange.pattern", exchange.getPattern().name());
    KeyValueAnnotation key4 = null;
    if (eventNotifier.isIncludeMessageBody() || eventNotifier.isIncludeMessageBodyStreams()) {
        boolean streams = eventNotifier.isIncludeMessageBodyStreams();
        StreamCache cache = prepareBodyForLogging(exchange, streams);
        String body = MessageHelper.extractBodyForLogging(exchange.hasOut() ? exchange.getOut() : exchange.getIn(), "", streams, streams);
        key4 = KeyValueAnnotation.create("camel.server.exchange.message.request.body", body);
        if (cache != null) {
            cache.reset();
        }
    }
    List<KeyValueAnnotation> list = new ArrayList<>();
    list.add(key1);
    list.add(key2);
    list.add(key3);
    if (key4 != null) {
        list.add(key4);
    }
    return list;
}
Also used : StreamCache(org.apache.camel.StreamCache) KeyValueAnnotation(com.github.kristofa.brave.KeyValueAnnotation) ArrayList(java.util.ArrayList)

Example 25 with StreamCache

use of org.apache.camel.StreamCache in project camel by apache.

the class BulkApiProcessor method processGetQueryResult.

private void processGetQueryResult(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String jobId;
    BatchInfo batchBody;
    String batchId;
    batchBody = exchange.getIn().getBody(BatchInfo.class);
    String resultId;
    if (batchBody != null) {
        jobId = batchBody.getJobId();
        batchId = batchBody.getId();
        resultId = getParameter(RESULT_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
    } else {
        jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        batchId = getParameter(BATCH_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        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) {
                // ensures the connection is read
                try {
                    body = StreamCacheConverter.convertToStreamCache(inputStream, exchange);
                } catch (IOException e) {
                    String msg = "Error retrieving query result: " + e.getMessage();
                    ex = new SalesforceException(msg, e);
                } finally {
                    // close the input stream to release the Http connection
                    try {
                        inputStream.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
            processResponse(exchange, body, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) StreamCache(org.apache.camel.StreamCache) InputStream(java.io.InputStream) IOException(java.io.IOException) DefaultBulkApiClient(org.apache.camel.component.salesforce.internal.client.DefaultBulkApiClient) BulkApiClient(org.apache.camel.component.salesforce.internal.client.BulkApiClient) BatchInfo(org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)

Aggregations

StreamCache (org.apache.camel.StreamCache)38 InputStream (java.io.InputStream)14 IOException (java.io.IOException)10 File (java.io.File)7 Exchange (org.apache.camel.Exchange)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ArrayList (java.util.ArrayList)5 StreamSource (javax.xml.transform.stream.StreamSource)5 KeyValueAnnotation (com.github.kristofa.brave.KeyValueAnnotation)4 StringReader (java.io.StringReader)4 OutputStream (java.io.OutputStream)3 SAXSource (javax.xml.transform.sax.SAXSource)3 Message (org.apache.camel.Message)3 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)3 BatchInfo (org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)3 BulkApiClient (org.apache.camel.component.salesforce.internal.client.BulkApiClient)3 DefaultBulkApiClient (org.apache.camel.component.salesforce.internal.client.DefaultBulkApiClient)3 DefaultExchange (org.apache.camel.impl.DefaultExchange)3 Writer (java.io.Writer)2 Source (javax.xml.transform.Source)2