Search in sources :

Example 66 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class RoutingUsingCamelContextFactoryTest method testXMLRouteLoading.

public void testXMLRouteLoading() throws Exception {
    applicationContext = createApplicationContext();
    SpringCamelContext context = applicationContext.getBean("camel-A", SpringCamelContext.class);
    assertValidContext(context);
    MockEndpoint resultEndpoint = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:result");
    resultEndpoint.expectedBodiesReceived(body);
    // now lets send a message
    ProducerTemplate template = context.createProducerTemplate();
    template.start();
    template.send("seda:start", new Processor() {

        public void process(Exchange exchange) {
            Message in = exchange.getIn();
            in.setHeader("name", "James");
            in.setBody(body);
        }
    });
    template.stop();
    resultEndpoint.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 67 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class SpringSetFaultBodyTest method testSetFaultBody.

public void testSetFaultBody() throws Exception {
    Exchange out = template.request("direct:start", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("Hello World");
        }
    });
    assertNotNull(out);
    assertEquals("Bye World", out.getIn().getBody());
    assertTrue("Should be a fault body", out.getIn().isFault());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor)

Example 68 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class MinaManyUDPMessagesTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() throws Exception {
            //context.setTracing(true);
            DataFormat syslogDataFormat = new SyslogDataFormat();
            // we setup a Syslog  listener on a random port.
            from("mina2:udp://127.0.0.1:" + serverPort).unmarshal(syslogDataFormat).process(new Processor() {

                public void process(Exchange ex) {
                    assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
                }
            }).to("mock:stop1").marshal(syslogDataFormat).to("mock:stop2");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat)

Example 69 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class NettyDataFormatTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() throws Exception {
            context.setTracing(true);
            DataFormat syslogDataFormat = new SyslogDataFormat();
            // we setup a Syslog  listener on a random port.
            from("netty4:udp://127.0.0.1:" + serverPort + "?sync=false&allowDefaultCodec=false").unmarshal(syslogDataFormat).process(new Processor() {

                public void process(Exchange ex) {
                    assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
                    SyslogMessage message = ex.getIn().getBody(SyslogMessage.class);
                }
            }).to("mock:syslogReceiver").marshal(syslogDataFormat).to("mock:syslogReceiver2");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat)

Example 70 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class NettyRfc5425LongMessageTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    context().getRegistry(JndiRegistry.class).bind("rfc5426FrameDecoder", new Rfc5425FrameDecoder());
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            context.setTracing(true);
            DataFormat syslogDataFormat = new SyslogDataFormat();
            // we setup a Syslog listener on a random port.
            from(uri).unmarshal(syslogDataFormat).process(new Processor() {

                @Override
                public void process(Exchange ex) {
                    assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
                }
            }).to("mock:syslogReceiver").marshal(syslogDataFormat).to("mock:syslogReceiver2");
            // Here we need to turn the request body into ByteBuf
            from("direct:start").convertBodyTo(ByteBuf.class).to(uri);
        }
    };
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) Exchange(org.apache.camel.Exchange) Rfc5425FrameDecoder(org.apache.camel.component.syslog.netty.Rfc5425FrameDecoder) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

Processor (org.apache.camel.Processor)1469 Exchange (org.apache.camel.Exchange)1369 Test (org.junit.Test)634 RouteBuilder (org.apache.camel.builder.RouteBuilder)544 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)164 Message (org.apache.camel.Message)119 ArrayList (java.util.ArrayList)66 HashMap (java.util.HashMap)64 IOException (java.io.IOException)55 CamelExecutionException (org.apache.camel.CamelExecutionException)52 Endpoint (org.apache.camel.Endpoint)46 Map (java.util.Map)45 File (java.io.File)38 List (java.util.List)35 Producer (org.apache.camel.Producer)33 DefaultExchange (org.apache.camel.impl.DefaultExchange)29 SendProcessor (org.apache.camel.processor.SendProcessor)26 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)26 CountDownLatch (java.util.concurrent.CountDownLatch)24 Expression (org.apache.camel.Expression)24