Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8058603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:24:39+00:00 2026-06-05T09:24:39+00:00

I am trying to execute a Struts2 Action from inside a Quartz job —

  • 0

I am trying to execute a Struts2 Action from inside a Quartz job — generalizing, from any context which is not the processing of an HTTP request.

I started here http://struts.apache.org/2.0.6/docs/how-can-we-schedule-quartz-jobs.html but the document seems to be pretty obsolete.

I believe (but I may be wrong) I’ve boiled it down to the need to obtain a Container object:

import java.util.HashMap;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.DefaultActionProxyFactory;

...

HashMap ctx = new HashMap();
DefaultActionProxyFactory factory= new DefaultActionProxyFactory();
factory.setContainer(HOW DO I GET THE CONTAINER??);
ActionProxy proxy = factory.createActionProxy("", "scheduled/myjob", ctx);

One solution would be to issue an http request (via TCP) against localhost. I would prefer to avoid that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:24:43+00:00Added an answer on June 5, 2026 at 9:24 am

    I somewhat fear what providing this answer may encourage some people to do, but as a proof of concept and to actually provide a solution to anyone who may, for whatever reason (maybe they are inheriting some whacked out application for which this is needed?), need to execute Struts2 actions outside of a normal request context.

    But, here is a raw (it is provided as a starting point, not an optimal implementation), but working, solution:

    First, add these three classes to a package called com.stackoverflow.struts2.quartz:

    A simple job that just asks for a proxy for the given job context and executes it:

    package com.stackoverflow.struts2.quartz;
    
    import org.quartz.Job;
    import org.quartz.JobExecutionContext;
    import org.quartz.JobExecutionException;
    
    public class ActionJob implements Job {
    
        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException {
    
            try {
                QuartzActionProxyFactory.getActionProxy(context).execute();
            } catch (Exception e) {
                e.printStackTrace();
                throw new JobExecutionException(e);
            }
    
        }
    
    }
    

    Some constants for passing around the action details:

    package com.stackoverflow.struts2.quartz;
    
    public class QuartzActionConstants {
    
        public static final String NAMESPACE = "struts.action.namespace";
        public static final String NAME = "struts.action.name";
        public static final String METHOD = "struts.action.method";
    
    }
    

    A custom ActionProxyFactory that can be accessed statically from the ActionJob:

    package com.stackoverflow.struts2.quartz;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import org.apache.struts2.impl.StrutsActionProxyFactory;
    import org.quartz.JobExecutionContext;
    import org.quartz.JobExecutionException;
    
    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionProxy;
    import com.opensymphony.xwork2.ActionProxyFactory;
    
    public class QuartzActionProxyFactory extends StrutsActionProxyFactory {
    
        private static ActionProxyFactory actionProxyFactory;
    
        public QuartzActionProxyFactory() {
            actionProxyFactory = this;
        }
    
        public static ActionProxy getActionProxy(JobExecutionContext context) throws JobExecutionException {
    
            ActionProxy actionProxy = null;
    
            try {
                @SuppressWarnings("unchecked")
                Map<String, Object> actionParams = context.getJobDetail().getJobDataMap();
                Map<String, Object> actionContext = new HashMap<String, Object>();
                actionContext.put(ActionContext.PARAMETERS, actionParams);
    
                actionProxy = actionProxyFactory.createActionProxy(
                        (String) actionParams.get(QuartzActionConstants.NAMESPACE),
                        (String) actionParams.get(QuartzActionConstants.NAME), 
                        (String) actionParams.get(QuartzActionConstants.METHOD), 
                        actionContext, 
                        false, //set to false to prevent execution of result, set to true if this is desired 
                        false);
    
            } catch (Exception e) {
                throw new JobExecutionException(e);
            }
    
            return actionProxy;
        }
    
    }
    

    Then, in your struts.xml, add:

    <bean name="quartz" type="com.opensymphony.xwork2.ActionProxyFactory" class="com.stackoverflow.struts2.quartz.QuartzActionProxyFactory"/>
    <constant name="struts.actionProxyFactory" value="quartz"/>
    

    Then you can schedule action executions with some simple code:

    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler scheduler = sf.getScheduler();
    scheduler.start();
    JobDetail jobDetail = new JobDetail("someActionJob", Scheduler.DEFAULT_GROUP, ActionJob.class);
    
    @SuppressWarnings("unchecked")
    Map<String, Object> jobContext = jobDetail.getJobDataMap();
    jobContext.put(QuartzActionConstants.NAMESPACE, "/the/action/namespace");
    jobContext.put(QuartzActionConstants.NAME, "theActionName");
    jobContext.put(QuartzActionConstants.METHOD, "theActionMethod");
    
    Trigger trigger = new SimpleTrigger("actionJobTrigger", Scheduler.DEFAULT_GROUP, new Date(), null, SimpleTrigger.REPEAT_INDEFINITELY, 1000L);
    scheduler.deleteJob("someActionJob", Scheduler.DEFAULT_GROUP);
    scheduler.scheduleJob(jobDetail, trigger);
    

    And that’s it. This code will cause the action to be executed every second indefinitely, and the interceptors will all fire and the dependencies will be injected. Of course, any logic or interceptors that depend on Servlet object like an HttpServletRequest are not going to operate properly, but then it wouldn’t make sense to schedule those actions outside of the servlet context, anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m trying to execute linux commant 'cat' from java code, but it does not
I'm trying to execute an external program from inside my Linux C++ program. I'm
I am trying to execute a packageprocedure from ODP.NET C# which insert data into
Here's a little snippet that I'm trying execute: >>> from datetime import * >>>
I trying execute next FQL query SELECT uid FROM user WHERE name='Vovka' and getting
I am trying execute a java class which accesses a method in a jar
Trying to execute a Powershell cmdlet from a MVC 3 Controller using impersonation but
Am trying to execute ssis package using dtexec utility from c# app(Creating New Process,
I'm trying to execute a MYSQL command which grabs all the rows with the
I am new to struts2 tiles. Here i am trying to execute 1 simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.