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);
}
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);
}
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);
}
}
});
}
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"));
}
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");
}
};
}
Aggregations