Author: lukaszlenart
Date: Wed Sep 12 20:18:45 2012
New Revision: 1384108
URL: http://svn.apache.org/viewvc?rev=1384108&view=rev
Log:
WW-3811 adds a new constant struts.handle.exception to control when Dispatcher
should handle exception and when rethrow it
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java?rev=1384108&r1=1384107&r2=1384108&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
Wed Sep 12 20:18:45 2012
@@ -243,4 +243,7 @@ public final class StrutsConstants {
public static final String STRUTS_CONVERTER_NUMBER =
"struts.converter.number";
public static final String STRUTS_CONVERTER_STRING =
"struts.converter.string";
+ /** Enable handling exceptions by Dispatcher - true by default **/
+ public static final String STRUTS_HANDLE_EXCEPTION =
"struts.handle.exception";
+
}
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java?rev=1384108&r1=1384107&r2=1384108&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
Wed Sep 12 20:18:45 2012
@@ -156,6 +156,12 @@ public class Dispatcher {
private boolean paramsWorkaroundEnabled = false;
/**
+ * Indicates if Dispatcher should handle exception and call sendError()
+ * Introduced to allow integration with other frameworks like Spring
Security
+ */
+ private boolean handleException;
+
+ /**
* Provide the dispatcher instance for the current thread.
*
* @return The dispatcher instance
@@ -254,6 +260,11 @@ public class Dispatcher {
this.valueStackFactory = valueStackFactory;
}
+ @Inject(StrutsConstants.STRUTS_HANDLE_EXCEPTION)
+ public void setHandleException(String handleException) {
+ this.handleException = Boolean.parseBoolean(handleException);
+ }
+
/**
* Releases all instances bound to this dispatcher instance.
*/
@@ -537,21 +548,24 @@ public class Dispatcher {
}
} catch (ConfigurationException e) {
// WW-2874 Only log error if in devMode
- if(devMode) {
+ if (devMode) {
String reqStr = request.getRequestURI();
if (request.getQueryString() != null) {
reqStr = reqStr + "?" + request.getQueryString();
}
LOG.error("Could not find action or result\n" + reqStr, e);
+ } else {
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Could not find action or result", e);
+ }
}
- else {
- if (LOG.isWarnEnabled()) {
- LOG.warn("Could not find action or result", e);
- }
- }
sendError(request, response, context,
HttpServletResponse.SC_NOT_FOUND, e);
} catch (Exception e) {
- sendError(request, response, context,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
+ if (handleException || devMode) {
+ sendError(request, response, context,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
+ } else {
+ throw new ServletException(e);
+ }
} finally {
UtilTimerStack.pop(timerKey);
}
@@ -800,8 +814,7 @@ public class Dispatcher {
* @param e the Exception that is reported.
* @param ctx the ServletContext object.
*/
- public void sendError(HttpServletRequest request, HttpServletResponse
response,
- ServletContext ctx, int code, Exception e) {
+ public void sendError(HttpServletRequest request, HttpServletResponse
response, ServletContext ctx, int code, Exception e) {
Boolean devModeOverride = FilterDispatcher.getDevModeOverride();
if (devModeOverride != null ? devModeOverride : devMode) {
response.setContentType("text/html");
Modified:
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties?rev=1384108&r1=1384107&r2=1384108&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties
(original)
+++
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties
Wed Sep 12 20:18:45 2012
@@ -207,4 +207,8 @@ struts.ognl.logMissingProperties=false
### Caches parsed OGNL expressions, but can lead to memory leaks
### if the application generates a lot of different expressions
struts.ognl.enableExpressionCache=true
+
+### Indicates if Dispatcher should handle unexpected exceptions by calling
sendError()
+### or simply rethrow it as a ServletException to allow future processing by
other frameworks like Spring Security
+struts.handle.exception=true
### END SNIPPET: complete_file