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);
}
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);
}
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;
}
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;
}
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);
}
});
}
Aggregations