(Amended commit based on feedback)

Proposed fix for WW-5028 for the 2.5.x branch:
- Disable printing stacktrace on exceptions by the Dispatcher by default.
- Printing stacktrace on exception is only enabled with devMode set to true, as suggested by L. Lenart.
- Now prints stacktrace on exception using LOG, as suggested by A. Mashchenko and the the JIRA reporter.
  Log level set to debug as recommended by Y. Zamani.
- Added two additional unit tests for Dispatcher devMode and handleException states.

(cherry picked from commit 4815744)
This commit is contained in:
JCgH4164838Gh792C124B5
2019-04-13 21:50:00 +04:30
committed by Yasser Zamani
parent d71ff77f82
commit f0776aeac6
2 changed files with 35 additions and 1 deletions
@@ -614,8 +614,10 @@ public class Dispatcher {
logConfigurationException(request, e);
sendError(request, response, HttpServletResponse.SC_NOT_FOUND, e);
} catch (Exception e) {
e.printStackTrace();
if (handleException || devMode) {
if (devMode) {
LOG.debug("Dispatcher serviceAction failed", e);
}
sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
} else {
throw new ServletException(e);
@@ -367,6 +367,38 @@ public class DispatcherTest extends StrutsInternalTestCase {
assertTrue("should execute previous proxy", actionProxy.isExecutedCalled());
}
/**
* Verify proper default (true) handleExceptionState for Dispatcher and that
* it properly reflects a manually configured change to false.
*
* @throws Exception
*/
public void testHandleException() throws Exception {
Dispatcher du = initDispatcher(new HashMap<String, String>());
assertTrue("Default Dispatcher handleException state not true ?", du.isHandleException());
Dispatcher du2 = initDispatcher(new HashMap<String, String>() {{
put(StrutsConstants.STRUTS_HANDLE_EXCEPTION, "false");
}});
assertFalse("Modified Dispatcher handleException state not false ?", du2.isHandleException());
}
/**
* Verify proper default (false) devMode for Dispatcher and that
* it properly reflects a manually configured change to true.
*
* @throws Exception
*/
public void testDevMode() throws Exception {
Dispatcher du = initDispatcher(new HashMap<String, String>());
assertFalse("Default Dispatcher devMode state not false ?", du.isDevMode());
Dispatcher du2 = initDispatcher(new HashMap<String, String>() {{
put(StrutsConstants.STRUTS_DEVMODE, "true");
}});
assertTrue("Modified Dispatcher devMode state not true ?", du2.isDevMode());
}
class InternalConfigurationManager extends ConfigurationManager {
public boolean destroyConfiguration = false;