Class SystemCommandExecutorService
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.services.system.SystemCommandExecutorService
-
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,MessageEventGenerator
,Service
,StateManagedComponent
@ComponentProfile(summary="Execute an arbitrary system command (DANGER!)", tag="service") public class SystemCommandExecutorService extends ServiceImp
Service that runs the specified system executable with the provided arguments, optionally capturing the output.Note that no checking is peformed on the command to be executed; it will be executed as-is. If used in combination with
DynamicServiceExecutor
then you might have a large security hole if it is improperly configured or validated.The following behaviour is non-configurable:
- The exitcode is stored against the metadata key "SystemCommandExecutorService.ReturnValue" if the service does not throw an exception.
- If a timeout occurs then a ServiceException is thrown, output that was captured before the timeout should still be available
In the adapter configuration file this class is aliased as system-command-executor which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
COMMAND_RETURN_VALUE_METADATA_KEY
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description SystemCommandExecutorService()
SystemCommandExecutorService(CommandBuilder builder, CommandOutputCapture capture)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeService()
void
doService(AdaptrisMessage msg)
Invokes the command line executableCommandBuilder
getCommandBuilder()
CommandOutputCapture
getOutputCapture()
TimeInterval
getTimeout()
protected void
initService()
void
prepare()
Prepare for initialisation.void
setCommandBuilder(CommandBuilder builder)
Set the command builder.void
setOutputCapture(CommandOutputCapture outputCapture)
void
setTimeout(TimeInterval t)
Specifies a maximum time for the executable to run, after which it will be terminated.-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
-
-
-
-
Field Detail
-
COMMAND_RETURN_VALUE_METADATA_KEY
public static final java.lang.String COMMAND_RETURN_VALUE_METADATA_KEY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SystemCommandExecutorService
public SystemCommandExecutorService()
-
SystemCommandExecutorService
public SystemCommandExecutorService(CommandBuilder builder, CommandOutputCapture capture)
-
-
Method Detail
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Invokes the command line executable- Parameters:
msg
- theAdaptrisMessage
to process- Throws:
ServiceException
- wrapping any underlyingException
s- See Also:
Service.doService(com.adaptris.core.AdaptrisMessage)
-
initService
protected void initService() throws CoreException
- Specified by:
initService
in classServiceImp
- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeService
in classServiceImp
-
getCommandBuilder
public CommandBuilder getCommandBuilder()
-
setCommandBuilder
public void setCommandBuilder(CommandBuilder builder)
Set the command builder.- Parameters:
builder
- theCommandBuilder
implementation- See Also:
DefaultCommandBuilder
-
prepare
public void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Throws:
CoreException
-
setTimeout
public void setTimeout(TimeInterval t)
Specifies a maximum time for the executable to run, after which it will be terminated.- Parameters:
t
- the timeout; default if not configured is 30 seconds.
-
getTimeout
public TimeInterval getTimeout()
-
getOutputCapture
public CommandOutputCapture getOutputCapture()
-
setOutputCapture
public void setOutputCapture(CommandOutputCapture outputCapture)
-
-