AnsweredAssumed Answered

shell service tasks not showing in runtime tables

Question asked by aoliver on Jun 19, 2012
Latest reply on Jun 29, 2012 by aoliver
I am an activiti noob and am having issues with a Shell Task implementation.  Since Shell Tasks are not available in the Activiti Designer yet, i created a Service Task (Java Delegate) that mimics the Shell Task Behavior.  These Shell Tasks are running BI processes and take several minutes.  I'm using the Activiti REST API to invoke the workflows.  Activiti-Explorer and Activiti-REST are both configured to connect to an Oracle database.

3 Questions:
1) While the Shell tasks are running, i see no information in the ACT_RU_EXECUTION table.  I would expect to see my process instance row there while these tasks are running.
2) How can i get the  REST call to return once the workflow is invoked instead of returning after the workflow has completed?
3) In Activiti Explorer, when i run the attached workflow, no other activity is allowed in the activiti-explorer app.  I am even unable to log into another session.  Why is Activiti Explorer locking up like this?

Here is a snippet of the service task xml:
    <serviceTask id="NetGStageServiceTask" name="NetGStageService Task" activiti:class="com.scrippsnetworks.ibi.revenueWorkflows.serviceTasks.ShellServiceTask">
        <activiti:field name="command">
        <activiti:field name="wait">
        <activiti:field name="outputVariable">
        <activiti:field name="errorCodeVariable">
        <activiti:field name="arg1">

Here is the java delegate code:
public class ShellServiceTask implements JavaDelegate {

   final static Logger logger = Logger.getLogger(ShellServiceTask.class.getName());

   protected Expression command;
   protected Expression wait;
   protected Expression arg1;
   protected Expression arg2;
   protected Expression arg3;
   protected Expression arg4;
   protected Expression arg5;
   protected Expression outputVariable;
   protected Expression errorCodeVariable;
   protected Expression redirectError;
   protected Expression cleanEnv;
   protected Expression directory;

   String commandStr;
   String arg1Str;
   String arg2Str;
   String arg3Str;
   String arg4Str;
   String arg5Str;
   String waitStr;
   String resultVariableStr;
   String errorCodeVariableStr;
   Boolean waitFlag;
   Boolean redirectErrorFlag;
   Boolean cleanEnvBoolan;
   String directoryStr;

   public void execute(DelegateExecution execution) throws Exception {"In " + command.getValue(execution) + " ShellTask script with variables = " + execution.getVariables());
      // create a new value for execution
   "Leaving " + command.getValue(execution) + " ShellTask script with variables = " + execution.getVariables());


   private void readFields(DelegateExecution execution) {
       commandStr = getStringFromField(command, execution);
       arg1Str = getStringFromField(arg1, execution);
       arg2Str = getStringFromField(arg2, execution);
       arg3Str = getStringFromField(arg3, execution);
       arg4Str = getStringFromField(arg4, execution);
       arg5Str = getStringFromField(arg5, execution);
       waitStr = getStringFromField(wait, execution);
       resultVariableStr = getStringFromField(outputVariable, execution);
       errorCodeVariableStr = getStringFromField(errorCodeVariable, execution);

       String redirectErrorStr = getStringFromField(redirectError, execution);
       String cleanEnvStr = getStringFromField(cleanEnv, execution);

       waitFlag = waitStr == null || waitStr.equals("true");
       redirectErrorFlag = redirectErrorStr != null && redirectErrorStr.equals("true");
       cleanEnvBoolan = cleanEnvStr != null && cleanEnvStr.equals("true");
       directoryStr = getStringFromField(directory, execution);

   public String toString() {
      return "command="+command+", arg1="+arg1+", arg2="+arg2+", arg3="+arg3+", arg4="+arg4+", arg5="+arg5+
            ", wait="+wait+", outputVariable="+outputVariable+", errorCodeVariable="+errorCodeVariable;
   public void executeScript(DelegateExecution execution) {"starting execute");
      List<String> argList = new ArrayList<String>();
         if (arg1Str != null)
         if (arg2Str != null)
         if (arg3Str != null)
         if (arg4Str != null)
         if (arg5Str != null)
         ProcessBuilder processBuilder = new ProcessBuilder(argList);
         try {
            if (cleanEnvBoolan) {
               Map<String, String> env = processBuilder.environment();
            if (directoryStr != null && directoryStr.length() > 0)
               Process process = processBuilder.start();
               if (waitFlag) {
                  int errorCode = process.waitFor();
                  if (resultVariableStr != null) {
                     String result = convertStreamToStr(process.getInputStream());
                     execution.setVariable(resultVariableStr, result);
                  if (errorCodeVariableStr != null) {
                     execution.setVariable(errorCodeVariableStr, Integer.toString(errorCode));

         } catch (Exception e) {
  "Could not execute shell command with error = " + e);
            throw new ActivitiException("Could not execute shell command" , e);

   public static String convertStreamToStr(InputStream is) throws IOException {
      if (is != null) {
         Writer writer = new StringWriter();
         char[] buffer = new char[1024];
         try {
            Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            int n;
            while ((n = != -1) {
               writer.write(buffer, 0, n);
         } finally {
         return writer.toString();
      } else {
         return "";

   protected String getStringFromField(Expression expression, DelegateExecution execution) {
      if (expression != null) {
         Object value = expression.getValue(execution);
         if (value != null) {
            return value.toString();
      return null;

What can i change to solve these 3 issues?