use of org.apache.camel.Message in project camel by apache.
the class CharsetTest method testCamel.
@Test
public void testCamel() throws Exception {
results.expectedMessageCount(4);
results.assertIsSatisfied();
int counter = 0;
List<Exchange> list = results.getReceivedExchanges();
for (Exchange exchange : list) {
Message in = exchange.getIn();
Map<?, ?> body = in.getBody(Map.class);
assertNotNull("Should have found body as a Map but was: " + ObjectHelper.className(in.getBody()), body);
assertEquals("ITEM_DESC", expectedItemDesc[counter], body.get("ITEM_DESC"));
LOG.info("Result: " + counter + " = " + body);
counter++;
}
}
use of org.apache.camel.Message in project camel by apache.
the class DelimitedWithNoDescriptorTest method testCamel.
@Test
public void testCamel() throws Exception {
results.expectedMessageCount(4);
results.assertIsSatisfied();
int counter = 0;
List<Exchange> list = results.getReceivedExchanges();
for (Exchange exchange : list) {
Message in = exchange.getIn();
Map<?, ?> body = in.getBody(Map.class);
assertNotNull("Should have found body as a Map but was: " + ObjectHelper.className(in.getBody()), body);
assertEquals("NAME", expectedItemDesc[counter], body.get("NAME"));
LOG.info("Result: " + counter + " = " + body);
counter++;
}
}
use of org.apache.camel.Message in project camel by apache.
the class AggregationStrategyClause method body.
/**
* TODO: document
*
* Note: this is experimental and subject to changes in future releases.
*/
public <O, N> T body(final Class<O> oldType, final Class<N> newType, final BiFunction<O, N, Object> function) {
return exchange((Exchange oldExchange, Exchange newExchange) -> {
Message oldMessage = oldExchange != null ? oldExchange.getIn() : null;
Message newMessage = ObjectHelper.notNull(newExchange, "NewExchange").getIn();
Object result = function.apply(oldMessage != null ? oldMessage.getBody(oldType) : null, newMessage != null ? newMessage.getBody(newType) : null);
if (oldExchange != null) {
oldExchange.getIn().setBody(result);
return oldExchange;
} else {
newExchange.getIn().setBody(result);
return newExchange;
}
});
}
use of org.apache.camel.Message in project camel by apache.
the class AggregationStrategyClause method message.
// *******************************
// Message
// *******************************
/**
* TODO: document
*
* Note: this is experimental and subject to changes in future releases.
*/
public T message(final BiFunction<Message, Message, Message> function) {
return exchange((Exchange oldExchange, Exchange newExchange) -> {
Message oldMessage = oldExchange != null ? oldExchange.getIn() : null;
Message newMessage = ObjectHelper.notNull(newExchange, "NewExchange").getIn();
Message result = function.apply(oldMessage, newMessage);
if (oldExchange != null) {
oldExchange.setIn(result);
return oldExchange;
} else {
newExchange.setIn(result);
return newExchange;
}
});
}
use of org.apache.camel.Message in project camel by apache.
the class MockEndpoint method performAssertions.
/**
* Performs the assertions on the incoming exchange.
*
* @param exchange the actual exchange
* @param copy a copy of the exchange (only store this)
* @throws Exception can be thrown if something went wrong
*/
protected void performAssertions(Exchange exchange, Exchange copy) throws Exception {
Message in = copy.getIn();
Object actualBody = in.getBody();
if (expectedHeaderValues != null) {
if (actualHeaderValues == null) {
actualHeaderValues = new CaseInsensitiveMap();
}
if (in.hasHeaders()) {
actualHeaderValues.putAll(in.getHeaders());
}
}
if (expectedPropertyValues != null) {
if (actualPropertyValues == null) {
actualPropertyValues = new ConcurrentHashMap<String, Object>();
}
actualPropertyValues.putAll(copy.getProperties());
}
if (expectedBodyValues != null) {
int index = actualBodyValues.size();
if (expectedBodyValues.size() > index) {
Object expectedBody = expectedBodyValues.get(index);
if (expectedBody != null) {
// prefer to convert body early, for example when using files
// we need to read the content at this time
Object body = in.getBody(expectedBody.getClass());
if (body != null) {
actualBody = body;
}
}
actualBodyValues.add(actualBody);
}
}
// let counter be 0 index-based in the logs
if (LOG.isDebugEnabled()) {
String msg = getEndpointUri() + " >>>> " + counter + " : " + copy + " with body: " + actualBody;
if (copy.getIn().hasHeaders()) {
msg += " and headers:" + copy.getIn().getHeaders();
}
LOG.debug(msg);
}
// record timestamp when exchange was received
copy.setProperty(Exchange.RECEIVED_TIMESTAMP, new Date());
// add a copy of the received exchange
addReceivedExchange(copy);
// and then increment counter after adding received exchange
++counter;
Processor processor = processors.get(getReceivedCounter()) != null ? processors.get(getReceivedCounter()) : defaultProcessor;
if (processor != null) {
try {
// must process the incoming exchange and NOT the copy as the idea
// is the end user can manipulate the exchange
processor.process(exchange);
} catch (Exception e) {
// set exceptions on exchange so we can throw exceptions to simulate errors
exchange.setException(e);
}
}
}
Aggregations