Source

webwork / docs / wikidocs / Quartz.html

<html>
    <head>
        <title>WebWork 2 : Quartz</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">	    
    </head>

    <body>
	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
		    <tr>
			    <td valign="top" class="pagebody">
				    <div class="pageheader">
					    <span class="pagetitle">
                            WebWork 2 : Quartz
                                                    </span>
				    </div>
				    <div class="pagesubheading">
					    This page last changed on Jun 10, 2004 by <font color="#0050B2">ctran</font>.
				    </div>

				    <p class="paragraph">The following class performs the glue between Quartz and Webwork:</p><div class="code"><div class="codeContent">
<pre><span class="java&#45;keyword">package</span> com.trantek.sit.action;&#10;&#10;<span class="java&#45;keyword">import</span> com.opensymphony.xwork.ActionProxy;&#10;<span class="java&#45;keyword">import</span> com.opensymphony.xwork.ActionProxyFactory;&#10;<span class="java&#45;keyword">import</span> org.quartz.Job;&#10;<span class="java&#45;keyword">import</span> org.quartz.JobExecutionContext;&#10;<span class="java&#45;keyword">import</span> org.quartz.JobExecutionException;&#10;&#10;<span class="java&#45;keyword">public</span> class WebWorkJob <span class="java&#45;keyword">implements</span> Job&#10;&#123;&#10;    <span class="java&#45;keyword">public</span> void execute(JobExecutionContext context) <span class="java&#45;keyword">throws</span> JobExecutionException&#10;    &#123;&#10;        <span class="java&#45;keyword">try</span>&#10;        &#123;&#10;            ActionProxy proxy = ActionProxyFactory.getFactory().&#10;                    createActionProxy(&quot;&quot;, context.getJobDetail().getName(), context.getJobDetail().getJobDataMap());&#10;&#10;            proxy.execute();&#10;        &#125;&#10;        <span class="java&#45;keyword">catch</span> (Exception e)&#10;        &#123;&#10;            <span class="java&#45;keyword">throw</span>&#160;<span class="java&#45;keyword">new</span> JobExecutionException(e);&#10;        &#125;&#10;    &#125;&#10;&#125;</pre>
</div></div><p class="paragraph">To schedule webwork actions you simply create a job where</p><ul class="star">
<li> the name of your job is the name of the WW action to execute (no &quot;.action&quot; suffix).</li>
<li> all the parameters you want to send to the WW action is contained in the JobDataMap of the JobDetail</li>
</ul><p class="paragraph">(the Quartz scheduler is setup as a servlet according to the javadocs of org.quartz.ee.servlet.QuartzInitializerServlet.)</p>The following code schedules an e-mail action:<br/>

<div class="code"><div class="codeContent">
<pre>Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();&#10;&#10;JobDetail jobDetail = <span class="java&#45;keyword">new</span> JobDetail(<span class="java&#45;quote">&quot;email.send&quot;</span>, &#10;                                     scheduler.DEFAULT&#95;GROUP, WebworkJob.class);&#10;&#10;Map m = jobDetail.getJobDataMap();&#10;m.put(<span class="java&#45;quote">&quot;to&quot;</span>, <span class="java&#45;quote">&quot;me&#64;bogusdomain.com&quot;</span>);&#10;m.put(<span class="java&#45;quote">&quot;subject&quot;</span>, <span class="java&#45;quote">&quot;quartz test&quot;</span>);&#10;m.put(<span class="java&#45;quote">&quot;body&quot;</span>, <span class="java&#45;quote">&quot;This is a quartz test, Hey ho&quot;</span>);&#10;m.put(<span class="java&#45;quote">&quot;smtpServer&quot;</span>, <span class="java&#45;quote">&quot;smtp.bogusdomain.com&quot;</span>);&#10;m.put(<span class="java&#45;quote">&quot;from&quot;</span>, <span class="java&#45;quote">&quot;quartz&#64;bogusdomain.com&quot;</span>);&#10;&#10;SimpleTrigger trigger = <span class="java&#45;keyword">new</span> SimpleTrigger(<span class="java&#45;quote">&quot;myTrigger&quot;</span>, &#10;                                          scheduler.DEFAULT&#95;GROUP, &#10;                                          <span class="java&#45;keyword">new</span> Date(), <span class="java&#45;keyword">null</span>, 0, 0L);&#10;&#10;scheduler.deleteJob(<span class="java&#45;quote">&quot;email.send&quot;</span>, scheduler.DEFAULT&#95;GROUP);&#10;scheduler.scheduleJob(jobDetail, trigger);</pre>
</div></div><p class="paragraph">This example is based on <a href="http://wiki.opensymphony.com//display/WW1/Integrating+Webwork+and+Quartz" title="Integrating Webwork and Quartz">WW1:Integrating Webwork and Quartz</a></p>

				    
                    			    </td>
		    </tr>
	    </table>
	    <table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td height="12" background="border/border_bottom.gif"><img src="border/spacer.gif" width="1" height="1" border="0"/></td>
			</tr>
		    <tr>
			    <td align="center"><font color="grey">Document generated by Confluence on Oct 18, 2004 00:08</font></td>
		    </tr>
	    </table>
    </body>
</html>