use of org.apache.camel.Message in project camel by apache.
the class TimerProducer method doProcess.
@Override
protected void doProcess(Exchange exchange, MetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
Message in = exchange.getIn();
MetricsTimerAction action = endpoint.getAction();
MetricsTimerAction finalAction = in.getHeader(HEADER_TIMER_ACTION, action, MetricsTimerAction.class);
if (finalAction == MetricsTimerAction.start) {
handleStart(exchange, registry, metricsName);
} else if (finalAction == MetricsTimerAction.stop) {
handleStop(exchange, registry, metricsName);
} else {
LOG.warn("No action provided for timer \"{}\"", metricsName);
}
}
use of org.apache.camel.Message in project camel by apache.
the class Mina2TcpWithInOutTest method testMinaRouteWithInOut.
@Test
public void testMinaRouteWithInOut() throws Exception {
latch = new CountDownLatch(1);
uri = String.format("mina2:tcp://localhost:%1$s?textline=true", getPort());
Mina2ReverserServer server = new Mina2ReverserServer(getPort());
server.start();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:x").to(uri).process(new Processor() {
public void process(Exchange e) {
receivedExchange = e;
latch.countDown();
}
});
}
});
context.start();
// now lets fire in a message
Endpoint endpoint = context.getEndpoint("direct:x");
Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
Message message = exchange.getIn();
message.setBody("Hello!");
message.setHeader("cheese", 123);
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
// now lets sleep for a while
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertNotNull(receivedExchange.getIn());
assertEquals("!olleH", receivedExchange.getIn().getBody());
producer.stop();
context.stop();
server.stop();
}
use of org.apache.camel.Message in project camel by apache.
the class Mina2TransferExchangeOptionTest method sendExchange.
private Exchange sendExchange(boolean setException) throws Exception {
Endpoint endpoint = context.getEndpoint(String.format("mina2:tcp://localhost:%1$s?sync=true&encoding=UTF-8&transferExchange=true", getPort()));
Producer producer = endpoint.createProducer();
Exchange exchange = endpoint.createExchange();
//Exchange exchange = endpoint.createExchange();
Message message = exchange.getIn();
message.setBody("Hello!");
message.setHeader("cheese", "feta");
exchange.setProperty("ham", "old");
exchange.setProperty("setException", setException);
producer.start();
producer.process(exchange);
return exchange;
}
use of org.apache.camel.Message in project camel by apache.
the class Mina2TransferExchangeOptionTest method assertExchange.
private void assertExchange(Exchange exchange, boolean hasFault) {
if (!hasFault) {
Message out = exchange.getOut();
assertNotNull(out);
assertFalse(out.isFault());
assertEquals("Goodbye!", out.getBody());
assertEquals("cheddar", out.getHeader("cheese"));
} else {
Message fault = exchange.getOut();
assertNotNull(fault);
assertTrue(fault.isFault());
assertNotNull(fault.getBody());
assertTrue("Should get the InterrupteException exception", fault.getBody() instanceof InterruptedException);
assertEquals("nihao", fault.getHeader("hello"));
}
// in should stay the same
Message in = exchange.getIn();
assertNotNull(in);
assertEquals("Hello!", in.getBody());
assertEquals("feta", in.getHeader("cheese"));
// however the shared properties have changed
assertEquals("fresh", exchange.getProperty("salami"));
assertNull(exchange.getProperty("Charset"));
}
use of org.apache.camel.Message in project camel by apache.
the class MinaTransferExchangeOptionTest method assertExchange.
private void assertExchange(Exchange exchange, boolean hasFault) {
if (!hasFault) {
Message out = exchange.getOut();
assertNotNull(out);
assertFalse(out.isFault());
assertEquals("Goodbye!", out.getBody());
assertEquals("cheddar", out.getHeader("cheese"));
} else {
Message fault = exchange.getOut();
assertNotNull(fault);
assertTrue(fault.isFault());
assertNotNull(fault.getBody());
assertTrue("Should get the InterrupteException exception", fault.getBody() instanceof InterruptedException);
assertEquals("nihao", fault.getHeader("hello"));
}
// in should stay the same
Message in = exchange.getIn();
assertNotNull(in);
assertEquals("Hello!", in.getBody());
assertEquals("feta", in.getHeader("cheese"));
// however the shared properties have changed
assertEquals("fresh", exchange.getProperty("salami"));
assertNull(exchange.getProperty("Charset"));
}
Aggregations