Search in sources :

Example 16 with Message

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);
    }
}
Also used : Message(org.apache.camel.Message)

Example 17 with Message

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();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) Message(org.apache.camel.Message) Producer(org.apache.camel.Producer) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 18 with Message

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;
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) Message(org.apache.camel.Message)

Example 19 with Message

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"));
}
Also used : Message(org.apache.camel.Message)

Example 20 with Message

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"));
}
Also used : Message(org.apache.camel.Message)

Aggregations

Message (org.apache.camel.Message)810 Exchange (org.apache.camel.Exchange)379 Test (org.junit.Test)262 Processor (org.apache.camel.Processor)120 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)109 DefaultMessage (org.apache.camel.impl.DefaultMessage)67 DefaultExchange (org.apache.camel.impl.DefaultExchange)50 Endpoint (org.apache.camel.Endpoint)46 HashMap (java.util.HashMap)41 InputStream (java.io.InputStream)39 Response (javax.ws.rs.core.Response)38 ArrayList (java.util.ArrayList)33 RouteBuilder (org.apache.camel.builder.RouteBuilder)33 Map (java.util.Map)27 Producer (org.apache.camel.Producer)27 Customer (org.apache.camel.component.cxf.jaxrs.testbean.Customer)25 ActionResponse (org.openstack4j.model.common.ActionResponse)25 IOException (java.io.IOException)24 List (java.util.List)23 CamelContext (org.apache.camel.CamelContext)23