Author: lukaszlenart Date: Thu May 23 11:14:20 2013 New Revision: 1485645 URL: http://svn.apache.org/r1485645 Log: WW-4052 Extends interceptor to propagate params during exception handling
Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java?rev=1485645&r1=1485644&r2=1485645&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java (original) +++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java Thu May 23 11:14:20 2013 @@ -20,7 +20,9 @@ import com.opensymphony.xwork2.config.en import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * <!-- START SNIPPET: description --> @@ -190,9 +192,12 @@ public class ExceptionMappingInterceptor handleLogging(e); } List<ExceptionMappingConfig> exceptionMappings = invocation.getProxy().getConfig().getExceptionMappings(); - String mappedResult = this.findResultFromExceptions(exceptionMappings, e); - if (mappedResult != null) { - result = mappedResult; + ExceptionMappingConfig mappingConfig = this.findMappingFromExceptions(exceptionMappings, e); + if (mappingConfig != null && mappingConfig.getResult()!=null) { + Map parameterMap = mappingConfig.getParams(); + // create a mutable HashMap since some interceptors will remove parameters, and parameterMap is immutable + invocation.getInvocationContext().setParameters(new HashMap<String, Object>(parameterMap)); + result = mappingConfig.getResult(); publishException(invocation, new ExceptionHolder(e)); } else { throw e; @@ -248,9 +253,23 @@ public class ExceptionMappingInterceptor } } + /** + * @deprecated since 2.3.15 please use #findMappingFromExceptions directly instead + */ protected String findResultFromExceptions(List<ExceptionMappingConfig> exceptionMappings, Throwable t) { - String result = null; + ExceptionMappingConfig result = findMappingFromExceptions(exceptionMappings, t); + return result==null?null:result.getResult(); + } + /** + * Try to find appropriate {@link ExceptionMappingConfig} based on provided Throwable + * + * @param exceptionMappings list of defined exception mappings + * @param t caught exception + * @return appropriate mapping or null + */ + protected ExceptionMappingConfig findMappingFromExceptions(List<ExceptionMappingConfig> exceptionMappings, Throwable t) { + ExceptionMappingConfig config = null; // Check for specific exception mappings. if (exceptionMappings != null) { int deepest = Integer.MAX_VALUE; @@ -259,12 +278,11 @@ public class ExceptionMappingInterceptor int depth = getDepth(exceptionMappingConfig.getExceptionClassName(), t); if (depth >= 0 && depth < deepest) { deepest = depth; - result = exceptionMappingConfig.getResult(); + config = exceptionMappingConfig; } } } - - return result; + return config; } /** @@ -301,4 +319,5 @@ public class ExceptionMappingInterceptor protected void publishException(ActionInvocation invocation, ExceptionHolder exceptionHolder) { invocation.getStack().push(exceptionHolder); } + }