001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.component.exec;
018
019 import java.io.InputStream;
020
021 import org.apache.camel.Exchange;
022
023 /**
024 * Represents the binding of input and output types of a
025 * {@link ExecCommandExecutor} to an {@link Exchange}. The input of the executor
026 * is an {@link ExecCommand} and the output is an {@link ExecResult}.
027 */
028 public interface ExecBinding {
029
030 /**
031 * The header value overrides the executable of the command, configured in
032 * the exec endpoint URI. As executable is considered the remaining of the
033 * {@link ExecEndpoint} URI; <br>
034 * <br>
035 * e.g. in the URI <i> <code>exec:C:/Program Files/jdk/java.exe</code> </i>,
036 * <code>C:/Program Files/jdk/java.exe<code> is the executable.
037 */
038 String EXEC_COMMAND_EXECUTABLE = "CamelExecCommandExecutable";
039
040 /**
041 * The header value overrides the existing command arguments in the
042 * {@link ExecEndpoint} URI. The arguments may be a
043 * <code>List<String></code>. In this case no parsing of the arguments is
044 * necessary.
045 *
046 * @see {@link #EXEC_COMMAND_EXECUTABLE}
047 */
048 String EXEC_COMMAND_ARGS = "CamelExecCommandArgs";
049
050 /**
051 * Specifies the file name of a file, created by the executable, that should
052 * be considered as output of the executable, e.g. a log file.
053 *
054 * @see ExecResultConverter#toInputStream(ExecResult)
055 */
056 String EXEC_COMMAND_OUT_FILE = "CamelExecCommandOutFile";
057
058 /**
059 * Sets the working directory of the {@link #EXEC_COMMAND_EXECUTABLE}. The
060 * header value overrides any existing command in the endpoint URI. If this
061 * is not configured, the working directory of the current process will be
062 * used.
063 */
064 String EXEC_COMMAND_WORKING_DIR = "CamelExecCommandWorkingDir";
065
066 /**
067 * Specifies the amount of time, in milliseconds, after which the process of
068 * the executable should be terminated. The default value is
069 * {@link Long#MAX_VALUE}.
070 */
071 String EXEC_COMMAND_TIMEOUT = "CamelExecCommandTimeout";
072
073 /**
074 * The value of this header is a {@link InputStream} with the standard error
075 * stream of the executable.
076 */
077 String EXEC_STDERR = "CamelExecStderr";
078
079 /**
080 * The value of this header is the exit value that is returned, after the
081 * execution. By convention a non-zero status exit value indicates abnormal
082 * termination. <br>
083 * <b>Note that the exit value is OS dependent.</b>
084 */
085 String EXEC_EXIT_VALUE = "CamelExecExitValue";
086
087 /**
088 * The value of this header is a boolean which indicates whether or not
089 * to fallback and use stderr when stdout is empty.
090 */
091 String EXEC_USE_STDERR_ON_EMPTY_STDOUT = "CamelExecUseStderrOnEmptyStdout";
092
093 /**
094 * Creates a {@link ExecCommand} from the headers in the
095 * <code>exchange</code> and the settings of the <code>endpoint</code>.
096 *
097 * @param exchange a Camel {@link Exchange}
098 * @param endpoint an {@link ExecEndpoint} instance
099 * @return an {@link ExecCommand} object
100 * @see ExecCommandExecutor
101 */
102 ExecCommand readInput(Exchange exchange, ExecEndpoint endpoint);
103
104 /**
105 * Populates the exchange form the {@link ExecResult}.
106 *
107 * @param exchange a Camel {@link Exchange}, in which to write the
108 * <code>result</code>
109 * @param result the result of a command execution
110 * @see ExecCommandExecutor
111 */
112 void writeOutput(Exchange exchange, ExecResult result);
113 }