Message body - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

If the in message body, that the Exec component receives is convertible to java.io.InputStream, it is used to feed the input of the executable via its stdin. After the execution, the message body is the result of the execution, that is org.apache.camel.components.exec.ExecResult instance containing the stdout, stderr, exit value and out file. The component supports the following ExecResult type converters for convenience:

From

To

ExecResult

java.io.InputStream

ExecResult

String

ExecResult

byte []

ExecResult

org.w3c.dom.Document

If out file is used (the endpoint is configured with outFile, or there is ExecBinding.EXEC_COMMAND_OUT_FILE header) the converters return the content of the out file. If no out file is used, then the converters will use the stdout of the process for conversion to the target type.

For an example, the below executes wc (word count, Linux) to count the words in file /usr/share/dict/words . The word count (output) is written in the standard output stream of wc.

from("direct:exec")
.to("exec:wc?args=--words /usr/share/dict/words")
.process(new Processor() {
   public void process(Exchange exchange) throws Exception {
      // By default, the body is ExecResult instance
      assertIsInstanceOf(ExecResult.class, exchange.getIn().getBody());

      // Use the Camel Exec String type 
      // converter to convert the ExecResult 
      // to String. In this case, the stdout is considered as output.
      String wordCountOutput = exchange.getIn().getBody(String.class);

      // do something with the word count
      ...
   }
});