/** * Gets the holded exception stacktrace using {@link Exception#printStackTrace()}. * * @return stacktrace */ public String getExceptionStack() { String exceptionStack = null; if (getException() != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); try { getException().printStackTrace(pw); exceptionStack = sw.toString(); } finally { try { sw.close(); pw.close(); } catch (IOException e) { // ignore } } } return exceptionStack; }
@Override public String intercept(ActionInvocation invocation) throws Exception { String result; try { result = invocation.invoke(); } catch (Exception e) { if (isLogEnabled()) { handleLogging(e); } List<ExceptionMappingConfig> exceptionMappings = invocation.getProxy().getConfig().getExceptionMappings(); 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; } } return result; }