Search in sources :

Example 41 with Processor

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

the class DisruptorInOutChainedWithOnCompletionTest method createRouteBuilder.

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

        @Override
        public void configure() throws Exception {
            from("disruptor:a").process(new Processor() {

                @Override
                public void process(final Exchange exchange) throws Exception {
                    // should come in last
                    exchange.addOnCompletion(new SynchronizationAdapter() {

                        @Override
                        public void onDone(final Exchange exchange) {
                            template.sendBody("mock:c", "onCustomCompletion");
                        }
                    });
                }
            }).to("mock:a").transform(simple("${body}-a")).to("disruptor:b");
            from("disruptor:b").to("mock:b").transform(simple("${body}-b")).to("disruptor:c");
            from("disruptor:c").to("mock:c").transform(simple("${body}-c"));
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Example 42 with Processor

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

the class DisruptorVmWaitForTaskCompleteTest method testInOnly.

public void testInOnly() throws Exception {
    getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
    // we send an in only but we use Always to wait for it to complete
    // and since the route changes the payload we can get the response anyway
    Exchange out = template2.send("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("Hello World");
            exchange.setPattern(ExchangePattern.InOnly);
        }
    });
    assertEquals("Bye World", out.getIn().getBody());
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor)

Example 43 with Processor

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

the class DockerCustomCmdExecFactoryTestIT method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    FakeDockerCmdExecFactory.class.getDeclaredConstructors();
    return new RouteBuilder() {

        public void configure() {
            from("direct:in").to("docker://version?cmdExecFactory=" + FakeDockerCmdExecFactory.class.getName()).log("${body}").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    Version version = exchange.getIn().getBody(Version.class);
                    exchange.getOut().setBody(version.getVersion());
                }
            }).to("mock:result");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Version(com.github.dockerjava.api.model.Version)

Example 44 with Processor

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

the class DropboxProducerGetSingleTest method testCamelDropbox.

@Test
public void testCamelDropbox() throws Exception {
    template.send("direct:start", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader("test", "test");
        }
    });
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    assertMockEndpointsSatisfied();
    List<Exchange> exchanges = mock.getReceivedExchanges();
    Exchange exchange = exchanges.get(0);
    Object header = exchange.getIn().getHeader(DropboxResultHeader.DOWNLOADED_FILE.name());
    Object body = exchange.getIn().getBody();
    assertNotNull(header);
    assertNotNull(body);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 45 with Processor

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

the class DropboxProducerPutSingleFileTest method testCamelDropbox.

@Test
public void testCamelDropbox() throws Exception {
    template.send("direct:start", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader("test", "test");
        }
    });
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    assertMockEndpointsSatisfied();
    List<Exchange> exchanges = mock.getReceivedExchanges();
    Exchange exchange = exchanges.get(0);
    Object header = exchange.getIn().getHeader(DropboxResultHeader.UPLOADED_FILE.name());
    Object body = exchange.getIn().getBody();
    assertNotNull(header);
    assertNotNull(body);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

Processor (org.apache.camel.Processor)1467 Exchange (org.apache.camel.Exchange)1368 Test (org.junit.Test)634 RouteBuilder (org.apache.camel.builder.RouteBuilder)543 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)164 Message (org.apache.camel.Message)119 ArrayList (java.util.ArrayList)65 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)34 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