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 ServiceImpService 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
DynamicServiceExecutorthen 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.StringCOMMAND_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 voidcloseService()voiddoService(AdaptrisMessage msg)Invokes the command line executableCommandBuildergetCommandBuilder()CommandOutputCapturegetOutputCapture()TimeIntervalgetTimeout()protected voidinitService()voidprepare()Prepare for initialisation.voidsetCommandBuilder(CommandBuilder builder)Set the command builder.voidsetOutputCapture(CommandOutputCapture outputCapture)voidsetTimeout(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- theAdaptrisMessageto process- Throws:
ServiceException- wrapping any underlyingExceptions- See Also:
Service.doService(com.adaptris.core.AdaptrisMessage)
-
initService
protected void initService() throws CoreException- Specified by:
initServicein classServiceImp- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeServicein classServiceImp
-
getCommandBuilder
public CommandBuilder getCommandBuilder()
-
setCommandBuilder
public void setCommandBuilder(CommandBuilder builder)
Set the command builder.- Parameters:
builder- theCommandBuilderimplementation- See Also:
DefaultCommandBuilder
-
prepare
public void prepare() throws CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare 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)
-
-