Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Description

Wiki Markup
{snippet:id=description|javadoc=true|url=com.opensymphony.webwork.interceptor.ExecuteAndWaitInterceptor}

Parameters

Wiki Markup
{snippet:id=parameters|javadoc=true|url=com.opensymphony.webwork.interceptor.ExecuteAndWaitInterceptor}

Extending the Interceptor

Wiki Markup
{snippet:id=extending|javadoc=true|url=

The ExecuteAndWaitInterceptor is great for running long-lived actions in the background while showing the user a nice progress meter. This also prevents the HTTP request from timing out when the action takes more than 5 or 10 minutes.

Using this interceptor is pretty straight forward. Assuming that you are including webwork-default.xml, this interceptor is already configured but is not part of any of the default stacks. Because of the nature of this interceptor, it must be the last interceptor in the stack. A typical configuration looks like:

...


...
<action name="myLongRunningAction" class="...">
    <interceptor-ref name="defaultStack"/>
    <interceptor-ref name="execAndWait"/>
    <result name="wait">longRunningAction-wait.jsp</result>
    <result name="success">longRunningAction-success.jsp</result>
</action>
...

This interceptor works on a per-session basis. That means that the same action name (myLongRunningAction, in the above example) cannot be run more than once at a time in a given session. On the initial request or any subsequent requests (before the action has completed), the wait result will be returned. The wait result is responsible for issuing a subsequent request back to the action, giving the effect of a self-updating progress meter.

An example of a simple wait JSP is:

...


<html>
    <head>
        <title>Please wait</title>
        <meta http-equiv="refresh" content="5;url=<ww:url includeParams="'all'" />"/>
    </head>
    <body>
        Please wait while we process your request. 
        Click <a href="<ww:url includeParams="'all'" />"></a> if this page does not reload automatically.
    </body>

Whenever the wait result is returned, the action that is currently running in the background will be placed on top of the stack. This allows you to display progress data, such as a count, in the wait page. By making the wait page automatically reload the request to the action (which will be short-circuited by the interceptor), you can give the appearance of an automatic progress meter.

To set the Thread priority, add the parameter threadPriority (defaults to Thread.NORM_PRIORITY):

Code Block
xmlxml
titlexwork.xml

<interceptor name="execAndWait" class="com.opensymphony.webwork.interceptor.ExecuteAndWaitInterceptor"/>

<interceptor-stack name="defaultStack">
    ...
    <interceptor-ref name="execAndWait">
        <param name="threadPriority">10</param>
    </interceptor-ref>
</interceptor-stack>

The thread will receive the name of the action with 'BackgroundThread' appended.

Note

Because the action will be running in a seperate thread, you can't use ActionContext because it is a ThreadLocal. This means if you need to access, for example, session data, you need to implement SessionAware rather than calling ActionContext.getSesion().

Extending the Interceptor

...

}

Examples

Wiki Markup
{snippet:id=example|lang=xml|javadoc=true|url=com.opensymphony.webwork.interceptor.ExecuteAndWaitInterceptor}