http://git-wip-us.apache.org/repos/asf/struts-site/blob/124e36c4/content/docs/exception-configuration.html ---------------------------------------------------------------------- diff --git a/content/docs/exception-configuration.html b/content/docs/exception-configuration.html new file mode 100644 index 0000000..3d913e8 --- /dev/null +++ b/content/docs/exception-configuration.html @@ -0,0 +1,256 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> + <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> + <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushCss.js' type='text/javascript'></script> + <script type="text/javascript"> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); + </script> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>Exception Configuration</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="core-developers-guide.html">Core Developers Guide</a> > <a href="configuration-elements.html">Configuration Elements</a> > <a href="exception-configuration.html">Exception Configuration</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">Exception Configuration</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=13987"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=13987">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=13987"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=13987">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=13987"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=13987">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><p>Exception mappings is a powerful feature for dealing with an Action class that throws an Exception. The core idea is that an Exception thrown during the Action method can be automatically caught and mapped to a predefined Result. This declarative strategy is especially useful for frameworks, like Hibernate and Acegi, that throw RuntimeExceptions.</p> + +<p>As with many other parts of the framework, an Interceptor is needed to activate the exception mapping functionality. Below is a snippet from <code>struts-default.xml</code> which has the exception mapping already activated.</p> +<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>snippet of struts-default.xml</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> +... +<interceptors> + ... + <interceptor name="exception" class="com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor"/> + ... +</interceptors> + +<interceptor-stack name="defaultStack"> + <interceptor-ref name="exception"/> + <interceptor-ref name="alias"/> + <interceptor-ref name="servlet-config"/> + <interceptor-ref name="prepare"/> + <interceptor-ref name="i18n"/> + <interceptor-ref name="chain"/> + <interceptor-ref name="debugging"/> + <interceptor-ref name="profiling"/> + <interceptor-ref name="scoped-model-driven"/> + <interceptor-ref name="model-driven"/> + <interceptor-ref name="fileUpload"/> + <interceptor-ref name="checkbox"/> + <interceptor-ref name="static-params"/> + <interceptor-ref name="params"/> + <interceptor-ref name="conversionError"/> + <interceptor-ref name="validation"> + <param name="excludeMethods">input,back,cancel,browse</param> + </interceptor-ref> + <interceptor-ref name="workflow"> + <param name="excludeMethods">input,back,cancel,browse</param> + </interceptor-ref> +</interceptor-stack> +... +</pre> +</div></div> +<p>To use exception mapping, we simply need to map Exceptions to specific Results. The framework provides two ways to declare an exception mapping <code><exception-mapping/></code> - globally or for a specific action mapping. The exception mapping element takes two attributes, <code>exception</code> and <code>result</code>.</p> + +<p>When declaring an exception mapping, the Interceptor will find the closest class inheritance match between the Exception thrown and the Exception declared. The Interceptor will examine all declared mappings applicable to the action mapping, first local and then global mappings. If a match is found, the Result is processed, just as if it had been returned by the Action.</p> + +<p><img class="emoticon emoticon-information" src="https://cwiki.apache.org/confluence/s/en_GB/5982/f2b47fb3d636c8bc9fd0b11c0ec6d0ae18646be7.1/_/images/icons/emoticons/information.png" data-emoticon-name="information" alt="(info)"> This process follows the same rules as a Result returned from an Action. It first looks for the Result in the local action mapping, and if not found, it looks for a global Result.</p> + +<p>Below is an example of global and local exception mappings.</p> +<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>snippet from struts.xml</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> +<struts> + <package name="default"> + ... + <global-results> + <result name="login" type="redirect">/Login.action</result> + <result name="Exception">/Exception.jsp</result> + </global-results> + + <global-exception-mappings> + <exception-mapping exception="java.sql.SQLException" result="SQLException"/> + <exception-mapping exception="java.lang.Exception" result="Exception"/> + </global-exception-mappings> + ... + <action name="DataAccess" class="com.company.DataAccess"> + <exception-mapping exception="com.company.SecurityException" result="login"/> + <result name="SQLException" type="chain">SQLExceptionAction</result> + <result>/DataAccess.jsp</result> + </action> + ... + </package> +</xwork> +</pre> +</div></div> +<p>In the example above, here is what happens based upon each Exception:</p> +<ul><li>A <code>java.sql.SQLException</code> will chain to the <code>SQLExceptionAction</code> (action mapping not shown)</li><li>A <code>com.company.SecurityException</code> will redirect to <code>Login.action</code></li><li>Any other exception that extends <code>java.lang.Exception</code> will return the <code>/Exception.jsp</code> page</li></ul> + + +<h2 id="ExceptionConfiguration-ExceptionValuesontheValueStack">Exception Values on the ValueStack</h2> + +<p>By default, the <code>ExceptionMappingInterceptor</code> adds the following values to the Value Stack:</p> +<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> exception </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> The exception object itself </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> exceptionStack </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> The value from the stack trace </p></td></tr></tbody></table></div> + + + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Sample JSP using Error and Exception Values</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: html; gutter: false; theme: Default" style="font-size:12px;"> +<h2>An unexpected error has occurred</h2> +<p> + Please report this error to your system administrator + or appropriate technical support personnel. + Thank you for your cooperation. +</p> +<hr/> +<h3>Error Message</h3> +<s:actionerror/> +<p> + <s:property value="%{exception.message}"/> +</p> +<hr/> +<h3>Technical Details</h3> +<p> + <s:property value="%{exceptionStack}"/> +</p> +</pre> +</div></div> + +<h2 id="ExceptionConfiguration-Exceptioninconstructors">Exception in constructors</h2> +<p>Global exception mappings are designed to be used with exceptions thrown by action methods (like <code>execute</code>). exceptions thrown from constructors will <strong>not</strong> be handled by global exception mappings.</p></div> + </div> + + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html>
http://git-wip-us.apache.org/repos/asf/struts-site/blob/124e36c4/content/docs/exception-handling.html ---------------------------------------------------------------------- diff --git a/content/docs/exception-handling.html b/content/docs/exception-handling.html new file mode 100644 index 0000000..9c294c6 --- /dev/null +++ b/content/docs/exception-handling.html @@ -0,0 +1,209 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> + <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> + <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushCss.js' type='text/javascript'></script> + <script type="text/javascript"> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); + </script> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>Exception Handling</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="tutorials.html">Tutorials</a> > <a href="getting-started.html">Getting Started</a> > <a href="exception-handling.html">Exception Handling</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">Exception Handling</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14813967"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14813967">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14813967"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14813967">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14813967"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14813967">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The code for this tutorial, exception_handling, is available for checkout at <a shape="rect" class="external-link" href="https://github.com/apache/struts-examples" rel="nofollow">https://github.com/apache/struts-examples</a>.</p></div></div><h3 id="ExceptionHandling-Introduction">Introduction</h3><p>In this tutorial we'll explore how to enable the Struts 2 framework to handle any uncaught exceptions generated by a web application. Struts 2 provides robust exception handling, including the ability to automatically log any uncaught exceptions and redirect the user to a error web page.</p><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve c onfluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The <a shape="rect" class="external-link" href="http://struts.apache.org/mail.html">Struts 2 user mailing list</a> is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.</p></div></div><h3 id="ExceptionHandling-GlobalExceptionHandling">Global Exception Handling</h3><p>Using the Struts 2 framework you can specify in the struts.xml how the framework should handle uncaught exceptions. The handling logic can apply to all actions (global exception handling) or to a specific action. Let's first discuss how to enable global exception handling.</p><p>To enable global exception handling you need to add two nodes to struts.xml: global-exception-mapping and global-results. For example examine struts.xml from the exception_handling pr oject.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> + <global-results> + <result name="securityerror">/securityerror.jsp</result> + <result name="error">/error.jsp</result> + </global-results> + + <global-exception-mappings> + <exception-mapping exception="org.apache.struts.register.exceptions.SecurityBreachException" result="securityerror" /> + <exception-mapping exception="java.lang.Exception" result="error" /> + </global-exception-mappings> + +</pre> +</div></div><p>The global exception mapping node tells the Struts 2 framework what to do if an uncaught exception of the type specified (or a child of that type) is thrown by the the application. For example if a SecurityBreachException is thrown but not caught, the Struts 2 Action class will return a result of "securityerror". All other uncaught exceptions will cause the Struts 2 Action class to return a result of "error".</p><p>The global results mapping node relates the result value to a specific view page. For example the result "securityerror" will cause the framework to redirect the user's browser to the securityerror.jsp view page.</p><h3 id="ExceptionHandling-ExceptionHandlingPerAction">Exception Handling Per Action</h3><p>If you need to handle an exception in a specific way for a certain action you can use the exception-mapping node within the action node.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> <action name="actionspecificexception" class="org.apache.struts.register.action.Register" method="throwSecurityException"> + <exception-mapping exception="org.apache.struts.register.exceptions.SecurityBreachException" + result="login" /> + <result>/register.jsp</result> + <result name="login">/login.jsp</result> + </action> + +</pre> +</div></div><p>The above action node from the example application's struts.xml file specifies that if method throwSecurityException throws an uncaught exception of type SecurityBreachException the Struts 2 framework should return a result of login. The login result will cause the user's browser to be redirected to login.jsp.</p><p>You can see that an action-specific exception mapping will take precedence if the same exception is also mapped globally.</p><h3 id="ExceptionHandling-LoggingExceptions">Logging Exceptions</h3><p>You can configure the Struts 2 framework to log any uncaught exceptions. To enable logging of the exceptions being handled by the Struts 2 framework you must specify some parameter values in struts.xml. If you examine the <a shape="rect" class="external-link" href="http://struts.apache.org/release/2.3.x/xwork-core/apidocs/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.html">ExceptionMappingInterceptor class API</a> there are three parameter values you can set to enable logging (logEnabled), the log level to use (logLevel), and the log category (logCategory) to specify in the log message.</p><p>To set these parameter values for all actions that use a specific stack of interceptors in a package include the following in struts.xml just after the opening package node.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><interceptors> + <interceptor-stack name="appDefaultStack"> + <interceptor-ref name="defaultStack"> + <param name="exception.logEnabled">true</param> + <param name="exception.logLevel">ERROR</param> + </interceptor-ref> + </interceptor-stack> +</interceptors> + +<default-interceptor-ref name="appDefaultStack" /> + +</pre> +</div></div><p>The above interceptors node configures a new stack of Struts 2 interceptors named appDefaultStack. This stack of interceptors is based upon the defaultStack of interceptors (which are the Struts 2 interceptors that execute by default whenever an Action class method is called by the Struts 2 framework).</p><p>The ExceptionMappingInterceptor is one of the Struts 2 interceptors that is part of the default stack. In the definition of the struts defaultStack, the ExceptionMappingInterceptor is given the name of exception. By specifying a param node with the name of exception.logEnabled and a value of true, I'm setting the logEnabled parameter of the ExceptionMappingInterceptor class to true.</p><p>Now when the application throws an uncaught exception, the Struts 2 framework will handle it and will also write an entry to the log that includes the stack trace. In the example above, I've set the level to log these exceptions to be ERROR.</p><p>In the example applications, the logging is just to the Servlet container's console (see the log4j.xml file for the log settings).</p><h3 id="ExceptionHandling-DisplayExceptionInformationInBrowser">Display Exception Information In Browser</h3><p>You can display information about the exception in the browser if you want by using s:property tags with a value of exception and exceptionStack. For example in error.jsp is this markup.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> <h4>The application has malfunctioned.</h4> + + <p> Please contact technical support with the following information:</p> + + <h4>Exception Name: <s:property value="exception" /> </h4> + + <h4>Exception Details: <s:property value="exceptionStack" /></h4> + +</pre> +</div></div><p>When the exception interceptor is triggered it adds to the fields available for display the exception message and the exception's stack trace.</p><h3 id="ExceptionHandling-Summary">Summary</h3><p>Struts 2 provides a easy to use configuration for handling uncaught exceptions and redirecting users to appropriate view pages. You can configure exception handling to be global for all actions or to just for a specific action. You can also enable the Struts 2 framework to log the uncaught exceptions.</p><h3 id="ExceptionHandling-UpNext">Up Next</h3><p>In our next tutorial we'll cover how to configure Struts 2 to make debugging a Struts 2 application simpler.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Next</p></th><td colspan="1" rowspan="1" class="confluenceTd"><p>Onward to <a shape="rect" href="debugging-struts.html">Debugging Struts</a></p></td></tr><tr><th colspan="1" rowspan="1" class="confluen ceTh"><p>Prev</p></th><td colspan="1" rowspan="1" class="confluenceTd"><p>Return to <a shape="rect" href="message-resource-files.html">Message Resource Files</a></p></td></tr></tbody></table></div></div> + </div> + + <div class="tabletitle"> + Children + <span class="smalltext" id="show" style="display: inline;"> + <a href="javascript:showChildren()">Show Children</a></span> + <span class="smalltext" id="hide" style="display: none;"> + <a href="javascript:hideChildren()">Hide Children</a></span> + </div> + <div class="greybox" id="children" style="display: none;"> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + </div> + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/struts-site/blob/124e36c4/content/docs/exception-interceptor.html ---------------------------------------------------------------------- diff --git a/content/docs/exception-interceptor.html b/content/docs/exception-interceptor.html new file mode 100644 index 0000000..5419f2f --- /dev/null +++ b/content/docs/exception-interceptor.html @@ -0,0 +1,211 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> + <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> + <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushCss.js' type='text/javascript'></script> + <script type="text/javascript"> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); + </script> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>Exception Interceptor</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="core-developers-guide.html">Core Developers Guide</a> > <a href="interceptors.html">Interceptors</a> > <a href="exception-interceptor.html">Exception Interceptor</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">Exception Interceptor</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14015"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14015">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14015"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14015">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14015"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14015">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><p> +This interceptor forms the core functionality of the exception handling feature. Exception handling allows you to map +an exception to a result code, just as if the action returned a result code instead of throwing an unexpected +exception. When an exception is encountered, it is wrapped with an ExceptionHolder and pushed on the stack, +providing easy access to the exception from within your result. +</p> + +<p></p><p> +<b>Note:</b> While you can configure exception mapping in your configuration file at any point, the configuration +will not have any effect if this interceptor is not in the interceptor stack for your actions. It is recommended that +you make this interceptor the first interceptor on the stack, ensuring that it has full access to catch any +exception, even those caused by other interceptors. +</p> + + +<h2 id="ExceptionInterceptor-Parameters">Parameters</h2> + + +<p></p><ul></ul><p></p><ul><li>logEnabled (optional) - Should exceptions also be logged? (boolean true|false)</li></ul><p></p><ul><li>logLevel (optional) - what log level should we use (<code>trace, debug, info, warn, error, fatal</code>)? - defaut is <code>debug</code></li></ul><p></p><ul><li>logCategory (optional) - If provided we would use this category (eg. <code>com.mycompany.app</code>). +Default is to use <code>com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor</code>.</li></ul><p></p> + +<p></p><p> +The parameters above enables us to log all thrown exceptions with stacktace in our own logfile, +and present a friendly webpage (with no stacktrace) to the end user. +</p> + + +<h2 id="ExceptionInterceptor-ExtendingtheInterceptor">Extending the Interceptor</h2> + +<p></p><p> +If you want to add custom handling for publishing the Exception, you may override +{@link #publishException(com.opensymphony.xwork2.ActionInvocation, ExceptionHolder)}. The default implementation +pushes the given ExceptionHolder on value stack. A custom implementation could add additional logging etc. +</p> + +<h2 id="ExceptionInterceptor-Examples">Examples</h2> + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +<xwork> + <package name="default" extends="xwork-default"> + <global-results> + <result name="error" type="freemarker">error.ftl</result> + </global-results> + + <global-exception-mappings> + <exception-mapping exception="java.lang.Exception" result="error"/> + </global-exception-mappings> + + <action name="test"> + <interceptor-ref name="exception"/> + <interceptor-ref name="basicStack"/> + <exception-mapping exception="com.acme.CustomException" result="custom_error"/> + <result name="custom_error">custom_error.ftl</result> + <result name="success" type="freemarker">test.ftl</result> + </action> + </package> +</xwork> +]]></script> +</div></div></div> + </div> + + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/struts-site/blob/124e36c4/content/docs/exclude-parameters.html ---------------------------------------------------------------------- diff --git a/content/docs/exclude-parameters.html b/content/docs/exclude-parameters.html new file mode 100644 index 0000000..c1d119e --- /dev/null +++ b/content/docs/exclude-parameters.html @@ -0,0 +1,191 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> + <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> + <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushCss.js' type='text/javascript'></script> + <script type="text/javascript"> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); + </script> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>Exclude Parameters</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="tutorials.html">Tutorials</a> > <a href="getting-started.html">Getting Started</a> > <a href="exclude-parameters.html">Exclude Parameters</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">Exclude Parameters</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=30746942"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=30746942">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=30746942"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=30746942">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=30746942"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=30746942">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The example code for this tutorial, exclude_parameters, is available at <a shape="rect" class="external-link" href="https://github.com/apache/struts-examples" rel="nofollow">https://github.com/apache/struts-examples</a>.</p></div></div><h3 id="ExcludeParameters-Introduction">Introduction</h3><p>When <a shape="rect" class="external-link" href="http://struts.apache.org/2.3.8/docs/strutsproperties.html">Struts development mode is set to true</a> (also see <a shape="rect" href="debugging-struts.html">Debugging Struts</a>) the framework writes many informative messages to the log file. These messages include ones that indicate whether or not a specific parameter will be handled by the parameter interceptor and made availab le to the Action class. These log messages can be helpful in clearly identifying parameters that you do not want the parameter interceptor to process for security or other reasons. This article discusses how to exclude parameters from being handled by the parameter interceptor.</p><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The <a shape="rect" class="external-link" href="http://struts.apache.org/mail.html">Struts 2 user mailing list</a> is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.</p></div></div><h3 id="ExcludeParameters-ProcessingRequestParameters">Processing Request Parameters</h3><p>Most request parameters are by default processed by the parameter interceptor and Struts 2 will attempt to modify the state of those Action class fields that match up to a parameter name by calling a corresponding public set method. For example if the request includes a parameter of lastName with a value of Phillips, Struts 2 will try to call a public method with a signature of setLastName(String lastName). However, there may be request parameters that you do not want Struts 2 to try to set the value of in the Action class.</p><p>Consider this code which creates a form:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Struts 2 Form Tags</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: html; gutter: false; theme: Default" style="font-size:12px;"><s:form action="save" method="post"> +<s:textfield key="personBean.firstName" /> +<s:textfield key="personBean.lastName" /> +<s:textfield key="personBean.email" /> +<s:textfield key="personBean.phoneNumber" /> +<s:select key="personBean.sport" list="sports" /> +<s:radio key="personBean.gender" list="genders" /> +<s:select key="personBean.residency" list="states" listKey="stateAbbr" listValue="stateName" /> +<s:checkbox key="personBean.over21" /> +<s:checkboxlist key="personBean.carModels" list="carModelsAvailable" /> +<s:submit key="submit" /> +</s:form> + +</pre> +</div></div><p>The s:submit tag will create a submit button with a name of submit. Since the Action class probably doesn't have a setSubmit(String name) method you will see the following log messages (only if Struts development mode is set to true):</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Log Messages</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: plain; gutter: false; theme: Default" style="font-size:12px;">Dec 31, 2012 3:43:53 PM +com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn +WARNING: Parameter [submit] is not on the excludeParams list of patterns and will be appended to action! + +Dec 31, 2012 3:43:53 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger error +SEVERE: Developer Notification (set struts.devMode to false to disable this message): +Unexpected Exception caught setting 'submit' on 'class org.apache.struts.edit.action.EditAction: Error setting expression 'submit' with value ['Save Changes', ] + +</pre> +</div></div><h3 id="ExcludeParameters-ExcludingRequestParametersFromStruts2Processing">Excluding Request Parameters From Struts 2 Processing</h3><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>If you're not familiar with setting up a custom interceptor stack for your Struts 2 application review <a shape="rect" href="introducing-interceptors.html">Introducing Interceptors</a>.</p></div></div><p>To exclude specific parameters from being processed by the Struts 2 framework you need to add those parameter names to the list of excluded parameters. One way to do this is by adding those parameter names to the collection of excludedParams for the Parameters interceptor. You can do this by modifying the Parameters interceptor in setting up the stack of interceptors used by your Struts 2 application. For example:</p><d iv class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Setup Interceptor Stack To Exclude submit Parameter</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><interceptors> + <interceptor-stack name="appDefault"> + <interceptor-ref name="defaultStack"> + <param name="exception.logEnabled">true</param> + <param name="exception.logLevel">ERROR</param> + <param name="params.excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*,submit</param> + </interceptor-ref> + </interceptor-stack> +</interceptors> + +<default-interceptor-ref name="appDefault" /> + +</pre> +</div></div><p>The value of node <param name="params.excludeParams"> is a comma-delimited list of regular expressions or simple Strings that identify request parameters that should NOT be processed by the Parameters interceptor. To exclude the submit parameter (which is the name of the submit button in the form code above), I just added submit to the list.</p><p>See the <a shape="rect" class="external-link" href="http://struts.apache.org/2.3.8/docs/struts-defaultxml.html">Basic Stack of Interceptors described here</a> to view the initial set of parameter names/regular expressions to exclude. Be sure to copy over the list of parameters already being excluded and then add your own parameters to the end separated by commas.</p><h3 id="ExcludeParameters-ExampleApplication">Example Application</h3><p>Download the example application, <a shape="rect" class="external-link" href="http://code.google.com/p/struts2-examples/downloads/list" rel="nofollow">Exclude_Params_Struts2_Mvn</a> th at demonstrates excluding a request parameter. The download is a zipped Maven project. You should be able to unzip it and import the project into any Maven-aware Java IDE. See the project's README.txt file for how to build and run the application.</p><p>To see the log messages written when not excluding the submit parameter remove the ",submit" from the list of excluded parameter values in the struts.xml file. Then rebuild and redeploy the application and view the console when running the application.</p><h3 id="ExcludeParameters-Summary">Summary</h3><p>It's a nice feature of the Struts 2 framework that it logs during development which request parameters will and will not be processed. During development of a Struts 2 web application it's a good practice to review these log messages to determine if there are any parameters that the framework should not process. For those parameters the Struts 2 framework should not process add the parameter name (or a regular expression that can be used to identify multiple parameter names) to the comma-delimited list that is the value for the <param name="params.excludeParams"> node.</p></div> + </div> + + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/struts-site/blob/124e36c4/content/docs/execute-action.html ---------------------------------------------------------------------- diff --git a/content/docs/execute-action.html b/content/docs/execute-action.html new file mode 100644 index 0000000..d5aeeab --- /dev/null +++ b/content/docs/execute-action.html @@ -0,0 +1,173 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>Execute Action</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="contributors-guide.html">Contributors Guide</a> > <a href="requirements.html">Requirements</a> > <a href="use-cases.html">Use Cases</a> > <a href="execute-action.html">Execute Action</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">Execute Action</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=29366"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=29366">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=29366"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=29366">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=29366"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=29366">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><h2 id="ExecuteAction-Narrative">Narrative</h2> + +<blockquote> +<p>A client submits a request to the Registration action for a new User account for the username "trillian". The Action object queries the database to see if the user exists, and then obtains a new User object for "trillian". The Action stores the User object in the client's session, and returns "success". The system matches "success" with a result object that presents the "Menu" page. </p></blockquote> + +<h2 id="ExecuteAction-Goal">Goal</h2> + +<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Goal </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Execute Action</p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Level </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Subfunction </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> (User Goal, Summary, Subfunction) </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Trigger </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Dispatcher selects Mapping </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Primary Actor </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Framework </p></td></tr></tbody></table></div> + + +<h2 id="ExecuteAction-MainSuccessScenario(MSS)">Main Success Scenario (MSS)</h2> + +<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Step </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Action </p></th></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> 1 </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Client submits a request for a resource handled by the framework. </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> 2 </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Framework matches location to an action mapping. </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> 3 </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Framework invokes Action class associated with action mapping. </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> 4 </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Action handles transaction and returns result ID. </p></td></tr><tr><th colspan="1" r owspan="1" class="confluenceTh"><p> 5 </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Framework matches result ID to result object. </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> 6 </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Framework invokes result object. </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> 7 </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Framework (via Container) transfers (or redirects) control to result resource. </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> 8 </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Resource renders response. </p></td></tr></tbody></table></div> + + +<h2 id="ExecuteAction-Extensions">Extensions</h2> + +<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Step </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Branching Action </p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> 1a </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> </p></th></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> .1 </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> 2a </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> </p></th></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> .1 </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> <img class="emoticon emoticon-information" src="https://cwiki.apache.org/confluence/s/en_GB/5982/f2b47fb3d636c8bc9fd0b11c0ec6d0ae18646be7.1/_/images/icons/emoticons/information.png" data-emoticon-name="information" alt="(info)"> </p></td></tr></tbody></table></div> + + +<hr> + +<h2 id="ExecuteAction-PreconditionsandGuarantees">Preconditions and Guarantees</h2> + +<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Preconditions </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Minimal Guarantees </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Success Guarantees </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td></tr></tbody></table></div> + + +<h2 id="ExecuteAction-StakeholdersandInterests">Stakeholders and Interests</h2> + +<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Stakeholder </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Interest </p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td></tr></tbody></table></div> + + +<h2 id="ExecuteAction-Variations">Variations </h2> + +<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Step </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Variation </p></th></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td></tr></tbody></table></div> +</div> + </div> + + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/struts-site/blob/124e36c4/content/docs/execute-and-wait-interceptor.html ---------------------------------------------------------------------- diff --git a/content/docs/execute-and-wait-interceptor.html b/content/docs/execute-and-wait-interceptor.html new file mode 100644 index 0000000..7a80995 --- /dev/null +++ b/content/docs/execute-and-wait-interceptor.html @@ -0,0 +1,274 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> + <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> + <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushCss.js' type='text/javascript'></script> + <script type="text/javascript"> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); + </script> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>Execute and Wait Interceptor</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="core-developers-guide.html">Core Developers Guide</a> > <a href="interceptors.html">Interceptors</a> > <a href="execute-and-wait-interceptor.html">Execute and Wait Interceptor</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">Execute and Wait Interceptor</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14318"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14318">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14318"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14318">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14318"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14318">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><p> +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. +</p> + +<p></p><p> Using this interceptor is pretty straight forward. Assuming that you are including struts-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 <b>last</b> interceptor in the stack. +</p> + +<p></p><p> 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 <b>wait</b> result will be returned. <b>The wait result is +responsible for issuing a subsequent request back to the action, giving the effect of a self-updating progress +meter</b>. +</p> + +<p></p><p> If no "wait" result is found, Struts will automatically generate a wait result on the fly. This result is +written in FreeMarker and cannot run unless FreeMarker is installed. If you don't wish to deploy with FreeMarker, you +must provide your own wait result. This is generally a good thing to do anyway, as the default wait page is very +plain. +</p> + +<p></p><p>Whenever the wait result is returned, the <b>action that is currently running in the background will be placed on +top of the stack</b>. 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. +</p> + +<p></p><p>This interceptor also supports using an initial wait delay. An initial delay is a time in milliseconds we let the +server wait before the wait page is shown to the user. During the wait this interceptor will wake every 100 millis +to check if the background process is done premature, thus if the job for some reason doesn't take to long the wait +page is not shown to the user. +<br clear="none"> This is useful for e.g. search actions that have a wide span of execution time. Using a delay time of 2000 +millis we ensure the user is presented fast search results immediately and for the slow results a wait page is used. +</p> + +<p></p><p><b>Important</b>: Because the action will be running in a separate 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.getSession(). +</p> + +<p></p><p>The thread kicked off by this interceptor will be named in the form <b><u>actionName</u>BackgroundProcess</b>. +For example, the <i>search</i> action would run as a thread named <i>searchBackgroundProcess</i>. +</p> + +<h2 id="ExecuteandWaitInterceptor-Parameters">Parameters</h2> + + +<p></p><ul></ul><p></p><ul><li>threadPriority (optional) - the priority to assign the thread. Default is <code>Thread.NORM_PRIORITY</code>.</li><li>delay (optional) - an initial delay in millis to wait before the wait page is shown (returning <code>wait</code> as result code). Default is no initial delay.</li><li>delaySleepInterval (optional) - only used with delay. Used for waking up at certain intervals to check if the background process is already done. Default is 100 millis.</li></ul><p></p> + + +<h2 id="ExecuteandWaitInterceptor-ExtendingtheInterceptor">Extending the Interceptor</h2> + +<p></p><p> +If you wish to make special preparations before and/or after the invocation of the background thread, you can extend +the BackgroundProcess class and implement the beforeInvocation() and afterInvocation() methods. This may be useful +for obtaining and releasing resources that the background process will need to execute successfully. To use your +background process extension, extend ExecuteAndWaitInterceptor and implement the getNewBackgroundProcess() method. +</p> + +<h2 id="ExecuteandWaitInterceptor-Examples">Examples</h2> + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +<action name="someAction" class="com.examples.SomeAction"> + <interceptor-ref name="completeStack"/> + <interceptor-ref name="execAndWait"/> + <result name="wait">longRunningAction-wait.jsp</result> + <result name="success">longRunningAction-success.jsp</result> +</action> + +<%@ taglib prefix="s" uri="/struts" %> +<html> + <head> + <title>Please wait</title> + <meta http-equiv="refresh" content="5;url=<s:url includeParams="all" />"/> + </head> + <body> + Please wait while we process your request. + Click <a href="<s:url includeParams="all" />"></a> if this page does not reload automatically. + </body> +</html> +</pre> + +<p><u>Example code2:</u></p> +<p> +This example will wait 2 second (2000 millis) before the wait page is shown to the user. Therefore +if the long process didn't last long anyway the user isn't shown a wait page. +</p> + +<pre> +<action name="someAction" class="com.examples.SomeAction"> + <interceptor-ref name="completeStack"/> + <interceptor-ref name="execAndWait"> + <param name="delay">2000<param> + <interceptor-ref> + <result name="wait">longRunningAction-wait.jsp</result> + <result name="success">longRunningAction-success.jsp</result> +</action> +</pre> + +<p><u>Example code3:</u></p> +<p> +This example will wait 1 second (1000 millis) before the wait page is shown to the user. +And at every 50 millis this interceptor will check if the background process is done, if so +it will return before the 1 second has elapsed, and the user isn't shown a wait page. +</p> + +<pre> +<action name="someAction" class="com.examples.SomeAction"> + <interceptor-ref name="completeStack"/> + <interceptor-ref name="execAndWait"> + <param name="delay">1000<param> + <param name="delaySleepInterval">50<param> + <interceptor-ref> + <result name="wait">longRunningAction-wait.jsp</result> + <result name="success">longRunningAction-success.jsp</result> +</action> +</pre> + +]]></script> +</div></div></div> + </div> + + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html>