Here is a quartz Job that can be used to invoke an XWork action. You may want to play with the context maps for replicating web calls, and you must be careful with actions that try to write to the ServletResponse outputStream. Note that your scheduler must contain a reference to you web application ServletContext

 HTH

Geoff

package com.widgetmaker.xwork.action;

import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionProxy;
import com.opensymphony.xwork.ActionProxyFactory;
import com.opensymphony.xwork.config.ConfigurationException;
import com.opensymphony.xwork.util.OgnlValueStack;
import org.apache.log4j.Logger;
import org.quartz.*;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;

/**
 * Quartz Job that will invoke an action from the XWork action
 */
public class ActionQuartzJob implements Job {

    private String namespace = null;
    private String actionName = null;

    public void execute(JobExecutionContext context) throws JobExecutionException {
        Scheduler scheduler = context.getScheduler();
        JobDataMap jdm = context.getJobDetail().getJobDataMap();
        namespace = (String) jdm.get("namespace");
        actionName = (String) jdm.get("actionName");
        log.info( "Processing "+getClass().getName()+" JOB: "+context.getJobDetail().getFullName()+"  action: " +namespace+"/"+actionName );

        Map extraContext = new HashMap();
        extraContext.put("request", new HashMap());
        extraContext.put("session", new HashMap());
        extraContext.put("application", new HashMap());
        extraContext.put("parameters", jdm );
        extraContext.put(ActionContext.PARAMETERS, jdm );

        try {
            final ServletContext sc = (ServletContext) scheduler.getContext().get("servletContext");
            ServletConfig sconf = (ServletConfig) Proxy.newProxyInstance(
                    ServletConfig.class.getClassLoader(),
                    new Class[]{ServletConfig.class},
                    new InvocationHandler(){
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    Object o = null;
                    if("getServletContext".equals(method.getName()) ) {
                        o = sc;
                    }
                    return o;
                }
            });
            extraContext.put(ServletActionContext.SERVLET_CONFIG, sconf );
        } catch (Exception e) {
            log.error("",e);
        }



        extraContext.put(ActionContext.VALUE_STACK,new OgnlValueStack());
        try {
            ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext);
            proxy.execute();
        } catch (SchedulerException e) {
            log.error("Could not access scheduler", e);
        } catch (ConfigurationException e) {
            log.error("Could not find action", e);
        } catch (Exception e) {
            log.error("Could not execute action", e);
        }
    }

    public String getNamespace() {
        return namespace;
    }

    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

    public String getActionName() {
        return actionName;
    }

    public void setActionName(String actionName) {
        this.actionName = actionName;
    }

    protected Logger log = Logger.getLogger(getClass());
}

 

 

Then your job configuration's datamap just needs to contain the XWork Action reference

From My jobs.xml file: 

<job-data-map allows-transient-data="true">
 <entry>
   <key>namespace</key>
   <value>/my/job/space</value>
  </entry>
  <entry>
   <key>actionName</key>
   <value>MyQuartzJobAction</value>
  </entry>
</job-data-map>