osworkflow
  1. osworkflow
  2. OSWORKFLOW-2

Scheduled workflow doesn't get the right config

    Details

    • Type: Task Task
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      2

      Description

      When a scheduled job recreates a workflow (i.e.: new BasicWorkflow()), it
      doesn't specify its configuration, so the workflow is stuck with the static
      configuration (described in "osworkflow.xml"). With the new, non-singletonish,
      way of doing things, it should be possible to specify the configuration to the
      WorkflowJob.

      I guess the best way to handle this would be to add an optional parameter in the
      ScheduleJob XML description. Something like <arg
      name="configLocation">prot://some/url/myConfigLocation.xml</arg>.

      I have a patch for an issue I just entered, if needed. Two files are to be
      modified 1) com.opensymphony.workflow.timer.LocalWorkflowJob and 2)
      com.opensymphony.workflow.util.ScheduleJob.

      Index: LocalWorkflowJob.java
      ===================================================================
      RCS file:
      /cvs/osworkflow/src/java/com/opensymphony/workflow/timer/LocalWorkflowJob.java,v
      retrieving revision 1.4
      diff -u -r1.4 LocalWorkflowJob.java
      — LocalWorkflowJob.java 3 Oct 2003 20:17:27 -0000 1.4
      +++ LocalWorkflowJob.java 3 Nov 2004 15:45:09 -0000
      @@ -7,12 +7,19 @@
      import com.opensymphony.workflow.Workflow;
      import com.opensymphony.workflow.WorkflowException;
      import com.opensymphony.workflow.basic.BasicWorkflow;
      +import com.opensymphony.workflow.config.Configuration;
      +import com.opensymphony.workflow.config.DefaultConfiguration;
      +
      +import org.apache.log4j.Logger;

      import org.quartz.Job;
      import org.quartz.JobDataMap;
      import org.quartz.JobExecutionContext;
      import org.quartz.JobExecutionException;

      +import java.net.MalformedURLException;
      +import java.net.URL;
      +

      /**

      • DOCUMENT ME!
        @@ -21,21 +28,75 @@
      • @version $Revision: 1.4 $
        */
        public class LocalWorkflowJob implements Job {
        + //~ Static fields/initializers /////////////////////////////////////////////
        +
        + private static final Logger log = Logger.getLogger(LocalWorkflowJob.class);
        +
        //~ Methods ////////////////////////////////////////////////////////////////

      + // ////////////////////////////////////////////////////////////////
      public void execute(JobExecutionContext jobExecutionContext) throws
      JobExecutionException {
      JobDataMap data = jobExecutionContext.getJobDetail().getJobDataMap();
      long id = data.getLong("entryId");
      int triggerId = data.getInt("triggerId");
      String username = data.getString("username");
      + String configLocation = data.getString("configLocation");
      +
      + Configuration config = new DefaultConfiguration();
      + URL configURL = getURL(Thread.currentThread().getContextClassLoader(),
      configLocation);
      +
      + if (configURL == null)

      { + configURL = getURL(getClass().getClassLoader(), configLocation); + }

      +
      + if (configURL == null)

      { + configURL = getClass().getResource(configLocation); + }

      +
      Workflow wf = new BasicWorkflow(username);

      try {
      + if (log.isDebugEnabled())

      { + log.debug("Loading configuration from '" + configURL + "'"); + }

      +
      + config.load(configURL);
      + wf.setConfiguration(config);
      wf.executeTriggerFunction(id, triggerId);
      } catch (WorkflowException e)

      { - //this cast is a fairly horrible hack, but it's more due to the fact that quartz is stupid enough to have wrapped exceptions + //this cast is a fairly horrible hack, but it's more due to the + // fact that quartz is stupid enough to have wrapped exceptions //wrap Exception, instead of Throwable. throw new JobExecutionException("Error Executing local job", (e.getRootCause() != null) ? (Exception) e.getRootCause() : e, true); }

      + }
      +
      + private URL getURL(ClassLoader classLoader, String location) {
      + URL url = null;
      +
      + if ((location != null) && (location.indexOf(":/") > -1)) {
      + try

      { + url = new URL(location); + }

      catch (MalformedURLException e)

      { + }

      + }
      +
      + if (url == null)

      { + url = classLoader.getResource(location); + }

      +
      + if (url == null)

      { + url = classLoader.getResource("/" + location); + }

      +
      + if (url == null)

      { + url = classLoader.getResource("META-INF/" + location); + }

      +
      + if (url == null)

      { + url = classLoader.getResource("/META-INF/" + location); + }

      +
      + return url;
      }
      }

      Index: ScheduleJob.java
      ===================================================================
      RCS file: /cvs/osworkflow/src/java/com/opensymphony/workflow/util/ScheduleJob.java,v
      retrieving revision 1.4
      diff -u -r1.4 ScheduleJob.java
      — ScheduleJob.java 5 Dec 2003 01:18:07 -0000 1.4
      +++ ScheduleJob.java 3 Nov 2004 15:43:44 -0000
      @@ -53,6 +53,7 @@

      • defaults to either a WorkflowJob or a LocalWorkflowJob if "local" is set to
        true.
      • <li>schedulerName - the name of an existing scheduler to use</li>
      • <li>schdulerStart - if "true", start the scheduler if it hasn't been
        started already</li>
        + * <li>configLocation - the location of the configuration file to be loaded
        ("osworkflow.xml"), in a resource format (url, ClassLoader.getResource(), etc.)</li>
      • <li>txHack - set this to true if you are getting lockups while running with
        transactions (defaults to false)</li>
      • </ul>
        *
        @@ -91,6 +92,8 @@
        String triggerName = (String) args.get("triggerName");
        String groupName = (String) args.get("groupName");

      + String configLocation = (String) args.get("configLocation");
      +
      String username = (String) args.get("username");
      String password = (String) args.get("password");

      @@ -205,6 +208,7 @@
      dataMap.put("entryId", entry.getId());
      dataMap.put("username", username);
      dataMap.put("password", password);
      + dataMap.put("configLocation", configLocation);
      jobDetail.setJobDataMap(dataMap);
      jobDetail.setDurability(true);

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            hani
            Reporter:
            fxlelouarn
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: