Dashboard > WebWork > ... > WebWork > Quartz
  WebWork Log In View a printable version of the current page.  
  Quartz
Added by Cuong Tran, last edited by Patrick Lightbody on Jun 14, 2005  (view change)
Labels: 
(None)

The following class performs the glue between Quartz and WebWork:

package com.trantek.sit.action;

import com.opensymphony.xwork.ActionProxy;
import com.opensymphony.xwork.ActionProxyFactory;
import com.opensymphony.xwork.interceptor.component.ComponentInterceptor;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import java.util.HashMap;

public class WebWorkJob implements Job
{
    public void execute(JobExecutionContext context) throws JobExecutionException
    {
        try
        {
            HashMap ctx = new HashMap();
            ctx.put(ActionContext.PARAMETERS, context.getJobDetail().getJobDataMap());
            ctx.put(ComponentInterceptor.COMPONENT_MANAGER, ???);
            ctx.put(???, ???)
            ServletDispatcher.createContextMap()
            ActionProxy proxy = ActionProxyFactory.getFactory().
                    createActionProxy("", context.getJobDetail().getName(), ctx);

            proxy.execute();
        }
        catch (Exception e)
        {
            throw new JobExecutionException(e);
        }
    }
}

To schedule webwork actions you simply create a job where

  • the name of your job is the name of the WW action to execute (no ".action" suffix).
  • all the parameters you want to send to the WW action is contained in the JobDataMap of the JobDetail

(the Quartz scheduler is setup as a servlet according to the javadocs of org.quartz.ee.servlet.QuartzInitializerServlet.)

The following code schedules an e-mail action:

Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

JobDetail jobDetail = new JobDetail("email.send", 
                                     scheduler.DEFAULT_GROUP, WebWorkJob.class);

Map m = jobDetail.getJobDataMap();
m.put("to", "me@bogusdomain.com");
m.put("subject", "quartz test");
m.put("body", "This is a quartz test, Hey ho");
m.put("smtpServer", "smtp.bogusdomain.com");
m.put("from", "quartz@bogusdomain.com");

SimpleTrigger trigger = new SimpleTrigger("myTrigger", 
                                          scheduler.DEFAULT_GROUP, 
                                          new Date(), null, 0, 0L);

scheduler.deleteJob("email.send", scheduler.DEFAULT_GROUP);
scheduler.scheduleJob(jobDetail, trigger);

This example is based on WW1:Integrating Webwork and Quartz

It's not quite clear how in fact you would add the ComponentManager as configured by WebWork so that dependency injection would occur when triggered by Quartz...

Posted by Justin Mecham at Jun 14, 2005 20:28 | Permalink

The previous WebWorkJob class that was posted breaks out of the entire loop of the application and not even the ActionContext is available,
what are the parameters that need to be passed to the Component Manager so that the webwork job stays in the appropriate context?

Posted by Fady Matar at Sep 12, 2005 10:10 | Permalink

To append to the issue, the ServletActionContext is null within the WebWorkJob Class. Any clue?

Posted by Fady Matar at Sep 18, 2005 03:41 | Permalink
Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators