use of java.io.File in project camel by apache.
the class DefaultExecCommandExecutor method prepareDefaultExecutor.
protected DefaultExecutor prepareDefaultExecutor(ExecCommand execCommand) {
DefaultExecutor executor = new ExecDefaultExecutor();
executor.setExitValues(null);
if (execCommand.getWorkingDir() != null) {
executor.setWorkingDirectory(new File(execCommand.getWorkingDir()).getAbsoluteFile());
}
if (execCommand.getTimeout() != ExecEndpoint.NO_TIMEOUT) {
executor.setWatchdog(new ExecuteWatchdog(execCommand.getTimeout()));
}
executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
return executor;
}
use of java.io.File 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 java.io.File in project camel by apache.
the class DefaultExecBinding method readInput.
@SuppressWarnings("unchecked")
public ExecCommand readInput(Exchange exchange, ExecEndpoint endpoint) {
ObjectHelper.notNull(exchange, "exchange");
ObjectHelper.notNull(endpoint, "endpoint");
// do not convert args as we do that manually later
Object args = exchange.getIn().removeHeader(EXEC_COMMAND_ARGS);
String cmd = getAndRemoveHeader(exchange.getIn(), EXEC_COMMAND_EXECUTABLE, endpoint.getExecutable(), String.class);
String dir = getAndRemoveHeader(exchange.getIn(), EXEC_COMMAND_WORKING_DIR, endpoint.getWorkingDir(), String.class);
long timeout = getAndRemoveHeader(exchange.getIn(), EXEC_COMMAND_TIMEOUT, endpoint.getTimeout(), Long.class);
String outFilePath = getAndRemoveHeader(exchange.getIn(), EXEC_COMMAND_OUT_FILE, endpoint.getOutFile(), String.class);
boolean useStderrOnEmptyStdout = getAndRemoveHeader(exchange.getIn(), EXEC_USE_STDERR_ON_EMPTY_STDOUT, endpoint.isUseStderrOnEmptyStdout(), Boolean.class);
InputStream input = exchange.getIn().getBody(InputStream.class);
// If the args is a list of strings already..
List<String> argsList = null;
if (isListOfStrings(args)) {
argsList = (List<String>) args;
}
if (argsList == null) {
// no we could not do that, then parse it as a string to a list
String s = endpoint.getArgs();
if (args != null) {
// use args from header instead from endpoint
s = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, args);
}
LOG.debug("Parsing argument String to a List: {}", s);
argsList = splitToWhiteSpaceSeparatedTokens(s);
}
File outFile = outFilePath == null ? null : new File(outFilePath);
return new ExecCommand(cmd, argsList, dir, timeout, input, outFile, useStderrOnEmptyStdout);
}
use of java.io.File in project camel by apache.
the class ExecDocumentationExamplesTest method testExecWinAnt.
/**
* The test assumes that Apache ant is installed
*/
@Test
@Ignore
public void testExecWinAnt() throws Exception {
File f = new File(ANT_BUILD_FILE_NAME);
f.createNewFile();
FileUtils.writeStringToFile(f, ANT_BUILD_FILE_CONTENT);
assertTrue("You must create a sample build file!", f.exists());
ExecResult body = templateExecAnt.requestBody((Object) "test", ExecResult.class);
String stdout = IOUtils.toString(body.getStdout());
assertNull(body.getStderr());
assertTrue("The ant script should print" + TEST_MSG, stdout.contains(TEST_MSG));
f.delete();
}
use of java.io.File in project camel by apache.
the class FlatpackDelimitedDataFormatTest method testUnmarshal.
@Test
public void testUnmarshal() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:unmarshal");
// by default we get on big message
mock.expectedMessageCount(1);
mock.message(0).body().isInstanceOf(DataSetList.class);
String data = IOConverter.toString(new File("src/test/data/delim/INVENTORY-CommaDelimitedWithQualifier.txt"), null);
template.sendBody("direct:unmarshal", data);
assertMockEndpointsSatisfied();
DataSetList list = mock.getExchanges().get(0).getIn().getBody(DataSetList.class);
assertEquals(4, list.size());
Map<?, ?> row = list.get(0);
assertEquals("SOME VALVE", row.get("ITEM_DESC"));
}
Aggregations