use of org.apache.camel.Exchange in project camel by apache.
the class LevelDBAggregationRepositoryAlotDataTest method testWithAlotOfDataTwoKesy.
@Test
public void testWithAlotOfDataTwoKesy() {
LevelDBAggregationRepository repo = new LevelDBAggregationRepository();
repo.setLevelDBFile(levelDBFile);
repo.setRepositoryName("repo1");
for (int i = 0; i < 100; i++) {
Exchange exchange1 = new DefaultExchange(context);
exchange1.getIn().setBody("counter:" + i);
String key = i % 2 == 0 ? "foo" : "bar";
repo.add(context, key, exchange1);
}
// Get it back..
Exchange actual = repo.get(context, "foo");
assertEquals("counter:98", actual.getIn().getBody());
actual = repo.get(context, "bar");
assertEquals("counter:99", actual.getIn().getBody());
}
use of org.apache.camel.Exchange in project camel by apache.
the class LuceneIndexAndQueryProducerTest method testReturnLuceneDocsQueryProducer.
@Test
public void testReturnLuceneDocsQueryProducer() throws Exception {
MockEndpoint mockSearchEndpoint = getMockEndpoint("mock:searchResult");
context.stop();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start").setHeader("QUERY", constant("Grouc?? Marx")).setHeader("RETURN_LUCENE_DOCS", constant("true")).to("lucene:searchIndex:query?analyzer=#stdAnalyzer&indexDir=#std&maxHits=20").to("direct:next");
from("direct:next").process(new Processor() {
public void process(Exchange exchange) throws Exception {
Hits hits = exchange.getIn().getBody(Hits.class);
try {
printResults(hits);
} catch (Exception e) {
LOG.error(e.getMessage());
exchange.getOut().setBody(null);
}
}
private void printResults(Hits hits) throws Exception {
LOG.debug("Number of hits: " + hits.getNumberOfHits());
for (int i = 0; i < hits.getNumberOfHits(); i++) {
LOG.debug("Hit " + i + " Index Location:" + hits.getHit().get(i).getHitLocation());
LOG.debug("Hit " + i + " Score:" + hits.getHit().get(i).getScore());
LOG.debug("Hit " + i + " Data:" + hits.getHit().get(i).getData());
if (hits.getHit().get(i).getDocument() == null) {
throw new Exception("Failed to return lucene documents");
}
}
}
}).to("mock:searchResult").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Hits hits = exchange.getIn().getBody(Hits.class);
if (hits == null) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("NO_LUCENE_DOCS_ERROR", "NO LUCENE DOCS FOUND");
exchange.getContext().setProperties(map);
}
LOG.debug("Number of hits: " + hits.getNumberOfHits());
}
});
}
});
context.start();
LOG.debug("------------Beginning LuceneQueryProducer Wildcard with Return Lucene Docs Test---------------");
sendQuery();
mockSearchEndpoint.assertIsSatisfied();
Map<String, String> errorMap = mockSearchEndpoint.getCamelContext().getProperties();
LOG.debug("------------Completed LuceneQueryProducer Wildcard with Return Lucene Docs Test---------------");
context.stop();
assertTrue(errorMap.get("NO_LUCENE_DOCS_ERROR") == null);
}
use of org.apache.camel.Exchange in project camel by apache.
the class LumberjackConsumer method onMessageReceived.
private void onMessageReceived(Object payload, LumberjackMessageProcessor.Callback callback) {
// Create the exchange
Exchange exchange = getEndpoint().createExchange();
exchange.getIn().setBody(payload);
// Process the exchange
getAsyncProcessor().process(exchange, doneSync -> callback.onComplete(!exchange.isFailed()));
}
use of org.apache.camel.Exchange in project camel by apache.
the class MailConsumer method createExchanges.
protected Queue<Exchange> createExchanges(List<KeyValueHolder<String, Message>> messages) throws MessagingException {
Queue<Exchange> answer = new LinkedList<Exchange>();
int fetchSize = getEndpoint().getConfiguration().getFetchSize();
int count = fetchSize == -1 ? messages.size() : Math.min(fetchSize, messages.size());
if (LOG.isDebugEnabled()) {
LOG.debug("Fetching {} messages. Total {} messages.", count, messages.size());
}
for (int i = 0; i < count; i++) {
try {
KeyValueHolder<String, Message> holder = messages.get(i);
String key = holder.getKey();
Message message = holder.getValue();
if (LOG.isTraceEnabled()) {
LOG.trace("Mail #{} is of type: {} - {}", new Object[] { i, ObjectHelper.classCanonicalName(message), message });
}
if (!message.getFlags().contains(Flags.Flag.DELETED)) {
Exchange exchange = getEndpoint().createExchange(message);
if (getEndpoint().getConfiguration().isMapMailMessage()) {
// ensure the mail message is mapped, which can be ensured by touching the body/header/attachment
LOG.trace("Mapping #{} from javax.mail.Message to Camel MailMessage", i);
exchange.getIn().getBody();
exchange.getIn().getHeaders();
exchange.getIn().getAttachments();
}
// If the protocol is POP3 we need to remember the uid on the exchange
// so we can find the mail message again later to be able to delete it
// we also need to remember the UUID for idempotent repository
exchange.setProperty(MAIL_MESSAGE_UID, key);
answer.add(exchange);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Skipping message as it was flagged as deleted: {}", MailUtils.dumpMessage(message));
}
}
} catch (Exception e) {
if (skipFailedMessage) {
LOG.debug("Skipping failed message at index " + i + " due " + e.getMessage(), e);
} else if (handleFailedMessage) {
handleException(e);
} else {
throw e;
}
}
}
return answer;
}
use of org.apache.camel.Exchange in project camel by apache.
the class MailEndpoint method createExchange.
public Exchange createExchange(Message message) {
Exchange exchange = super.createExchange();
exchange.setProperty(Exchange.BINDING, getBinding());
exchange.setIn(new MailMessage(message, getConfiguration().isMapMailMessage()));
return exchange;
}
Aggregations