use of org.apache.camel.Message in project camel by apache.
the class MessageSupportTest method testGetMessageId.
public void testGetMessageId() {
context.setUuidGenerator(new SimpleUuidGenerator());
Exchange exchange = new DefaultExchange(context);
Message in = exchange.getIn();
assertEquals("1", in.getMessageId());
}
use of org.apache.camel.Message in project camel by apache.
the class MessageSupportTest method testCopyFromSameHeadersInstance.
public void testCopyFromSameHeadersInstance() {
Exchange exchange = new DefaultExchange(context);
Message in = exchange.getIn();
Map<String, Object> headers = in.getHeaders();
headers.put("foo", 123);
Message out = new DefaultMessage();
out.setBody("Bye World");
out.setHeaders(headers);
out.copyFrom(in);
assertEquals(123, headers.get("foo"));
assertEquals(123, in.getHeader("foo"));
assertEquals(123, out.getHeader("foo"));
}
use of org.apache.camel.Message in project camel by apache.
the class PipelineTest method testSendMessageThroughAPipeline.
public void testSendMessageThroughAPipeline() throws Exception {
resultEndpoint.expectedBodiesReceived(4);
Exchange results = template.request("direct:a", new Processor() {
public void process(Exchange exchange) {
// now lets fire in a message
Message in = exchange.getIn();
in.setBody(1);
in.setHeader("foo", "bar");
}
});
resultEndpoint.assertIsSatisfied();
assertEquals("Result body", 4, results.getOut().getBody());
}
use of org.apache.camel.Message in project camel by apache.
the class AggregateGroupMessageTest method testGrouped.
@SuppressWarnings("unchecked")
public void testGrouped() throws Exception {
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedMessageCount(1);
template.sendBody("direct:start", "100");
template.sendBody("direct:start", "150");
template.sendBody("direct:start", "130");
template.sendBody("direct:start", "200");
template.sendBody("direct:start", "190");
assertMockEndpointsSatisfied();
Exchange out = result.getExchanges().get(0);
List<Message> grouped = out.getIn().getBody(List.class);
assertEquals(5, grouped.size());
assertEquals("100", grouped.get(0).getBody(String.class));
assertEquals("150", grouped.get(1).getBody(String.class));
assertEquals("130", grouped.get(2).getBody(String.class));
assertEquals("200", grouped.get(3).getBody(String.class));
assertEquals("190", grouped.get(4).getBody(String.class));
}
use of org.apache.camel.Message in project camel by apache.
the class BeanIOSplitter method evaluate.
public Object evaluate(Exchange exchange) throws Exception {
Message msg = exchange.getIn();
Object body = msg.getBody();
if (factory == null) {
factory = createStreamFactory(exchange.getContext());
}
BeanReader beanReader = null;
if (body instanceof WrappedFile) {
body = ((WrappedFile) body).getFile();
}
if (body instanceof File) {
File file = (File) body;
beanReader = factory.createReader(getStreamName(), file);
}
if (beanReader == null) {
Reader reader = msg.getMandatoryBody(Reader.class);
beanReader = factory.createReader(getStreamName(), reader);
}
BeanIOIterator iterator = new BeanIOIterator(beanReader);
BeanReaderErrorHandler errorHandler = getOrCreateBeanReaderErrorHandler(configuration, exchange, null, iterator);
beanReader.setErrorHandler(errorHandler);
return iterator;
}
Aggregations