Search in sources :

Example 46 with Processor

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

the class DropboxProducerPutSingleFileWithRemotePathTest 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)

Example 47 with Processor

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

the class ExecJava8IssueTest method test.

@Test
public void test() throws Exception {
    if (!OS.isFamilyUnix()) {
        System.err.println("The test 'CamelExecTest' does not support the following OS : " + System.getProperty("os.name"));
        return;
    }
    String tempFilePath = tempDir.getAbsolutePath() + "/" + tempFileName;
    final File script = File.createTempFile("script", ".sh", tempDir);
    writeScript(script);
    final String exec = "bash?args=" + script.getAbsolutePath() + " " + tempFilePath + "&outFile=" + tempFilePath;
    DefaultCamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:source").to("file:" + tempDir.getAbsolutePath() + "?fileName=" + tempFileName).to("exec:" + exec).process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    String output = exchange.getIn().getBody(String.class);
                    assertEquals("hello world\n", output);
                }
            });
        }
    });
    context.start();
    ProducerTemplate pt = context.createProducerTemplate();
    String payload = "hello";
    pt.sendBody("direct:source", payload);
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) File(java.io.File) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) IOException(java.io.IOException) Test(org.junit.Test)

Example 48 with Processor

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

the class ExecJavaProcessRecipientListTest method sendExchange.

protected Exchange sendExchange(final String endpoint, final Object commandArgument, final long timeout, final String body, final boolean useStderrOnEmptyStdout) {
    final List<String> args = buildArgs(commandArgument);
    final String javaAbsolutePath = buildJavaExecutablePath();
    return producerTemplate.send(endpoint, new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody(body);
            exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, javaAbsolutePath);
            exchange.getIn().setHeader(EXEC_COMMAND_TIMEOUT, timeout);
            exchange.getIn().setHeader(EXEC_COMMAND_ARGS, args);
            exchange.getIn().setHeader("whereTo", "exec:java");
            if (useStderrOnEmptyStdout) {
                exchange.getIn().setHeader(EXEC_USE_STDERR_ON_EMPTY_STDOUT, true);
            }
        }
    });
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor)

Example 49 with Processor

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

the class ExecJavaProcessTest method testExecJavaArgsAsStringWithQuote.

/**
     * Test print in stdout using string as args with quotes
     */
@Test
public void testExecJavaArgsAsStringWithQuote() throws Exception {
    context.start();
    output.setExpectedMessageCount(1);
    Exchange exchange = producerTemplate.send("direct:input", new Processor() {

        public void process(Exchange exchange) throws Exception {
            final String javaAbsolutePath = buildJavaExecutablePath();
            // use string for args
            String classpath = System.getProperty("java.class.path");
            String args = "-cp \"" + classpath + "\" " + EXECUTABLE_PROGRAM_ARG + " " + PRINT_ARGS_STDOUT + " \"Hello World\"";
            exchange.getIn().setBody("hello");
            exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, javaAbsolutePath);
            exchange.getIn().setHeader(EXEC_COMMAND_ARGS, args);
            exchange.getIn().setHeader(EXEC_USE_STDERR_ON_EMPTY_STDOUT, true);
        }
    });
    output.assertIsSatisfied();
    ExecResult result = exchange.getIn().getBody(ExecResult.class);
    assertNotNull(result);
    String out = IOConverter.toString(result.getStdout(), exchange);
    assertTrue(out, out.contains("1Hello World"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Test(org.junit.Test)

Example 50 with Processor

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

the class FacebookComponentPageIdProducerTest method createRouteBuilder.

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

        public void configure() {
            from("timer:period=20000").setHeader("CamelFacebook.reading.limit", constant("10")).process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    if (lastTimestamp > 0) {
                        exchange.getIn().setHeader("CamelFacebook.reading.since", lastTimestamp);
                    }
                }
            }).to("facebook://getPosts?" + getOauthParams() + "&userId=" + APACHE_FOUNDATION_PAGE_ID + "&reading.limit=5").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    ResponseList<Post> body = (ResponseList<Post>) exchange.getIn().getBody();
                    log.info("Number of posts received: {}", body.size());
                    for (Post post : body) {
                        log.debug(post.toString());
                    }
                    if (!body.isEmpty()) {
                        lastTimestamp = body.get(0).getUpdatedTime().getTime();
                    }
                }
            }).to("mock:page");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Post(facebook4j.Post) ResponseList(facebook4j.ResponseList)

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