@Test public void testSetExceptionCode_exception_code_is_notnull() { FlashMap flashMap = new FlashMap(); mockRequest.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, flashMap); SystemException occurException = new SystemException("code001", "message"); testTarget.setExceptionCode(occurException, mockRequest, mockResponse); assertThat(mockRequest.getAttribute("exceptionCode").toString(), is( "code001")); assertThat(mockResponse.getHeader("X-Exception-Code"), is("code001")); assertThat((String) flashMap.get("exceptionCode"), is("code001")); }
protected void setExceptionCode(Exception ex, HttpServletRequest request, HttpServletResponse response) { String exceptionCode = null; if (exceptionCodeResolver != null && (StringUtils.hasText( exceptionCodeAttribute) || StringUtils.hasText( exceptionCodeHeader))) { exceptionCode = exceptionCodeResolver.resolveExceptionCode(ex); } if (exceptionCode == null) { return; } if (StringUtils.hasText(exceptionCodeAttribute)) { request.setAttribute(exceptionCodeAttribute, exceptionCode); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); if (flashMap != null) { flashMap.put(exceptionCodeAttribute, exceptionCode); } } if (StringUtils.hasText(exceptionCodeHeader)) { response.setHeader(exceptionCodeHeader, exceptionCode); } }
SystemExceptionResolver extends SimpleMappingExceptionResolver { protected void setExceptionCode(Exception ex, HttpServletRequest request, HttpServletResponse response) { String exceptionCode = null; if (exceptionCodeResolver != null && (StringUtils.hasText( exceptionCodeAttribute) || StringUtils.hasText( exceptionCodeHeader))) { exceptionCode = exceptionCodeResolver.resolveExceptionCode(ex); } if (exceptionCode == null) { return; } if (StringUtils.hasText(exceptionCodeAttribute)) { request.setAttribute(exceptionCodeAttribute, exceptionCode); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); if (flashMap != null) { flashMap.put(exceptionCodeAttribute, exceptionCode); } } if (StringUtils.hasText(exceptionCodeHeader)) { response.setHeader(exceptionCodeHeader, exceptionCode); } } }
SystemExceptionResolver extends SimpleMappingExceptionResolver { protected void setExceptionCode(Exception ex, HttpServletRequest request, HttpServletResponse response) { String exceptionCode = null; if (exceptionCodeResolver != null && (StringUtils.hasText( exceptionCodeAttribute) || StringUtils.hasText( exceptionCodeHeader))) { exceptionCode = exceptionCodeResolver.resolveExceptionCode(ex); } if (exceptionCode == null) { return; } if (StringUtils.hasText(exceptionCodeAttribute)) { request.setAttribute(exceptionCodeAttribute, exceptionCode); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); if (flashMap != null) { flashMap.put(exceptionCodeAttribute, exceptionCode); } } if (StringUtils.hasText(exceptionCodeHeader)) { response.setHeader(exceptionCodeHeader, exceptionCode); } }  }
SystemExceptionResolver extends SimpleMappingExceptionResolver { protected void setExceptionCode(Exception ex, HttpServletRequest request, HttpServletResponse response) { String exceptionCode = null; if (exceptionCodeResolver != null && (StringUtils.hasText( exceptionCodeAttribute) || StringUtils.hasText( exceptionCodeHeader))) { exceptionCode = exceptionCodeResolver.resolveExceptionCode(ex); } if (exceptionCode == null) { return; } if (StringUtils.hasText(exceptionCodeAttribute)) { request.setAttribute(exceptionCodeAttribute, exceptionCode); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); if (flashMap != null) { flashMap.put(exceptionCodeAttribute, exceptionCode); } } if (StringUtils.hasText(exceptionCodeHeader)) { response.setHeader(exceptionCodeHeader, exceptionCode); } }  void setExceptionCodeAttribute(String exceptionCodeAttribute); void setExceptionCodeHeader(String exceptionCodeHeader); void setResultMessagesAttribute(String resultMessagesAttribute); void setExceptionCodeResolver(
            ExceptionCodeResolver exceptionCodeResolver); }
SystemExceptionResolver extends SimpleMappingExceptionResolver { protected void setExceptionCode(Exception ex, HttpServletRequest request, HttpServletResponse response) { String exceptionCode = null; if (exceptionCodeResolver != null && (StringUtils.hasText( exceptionCodeAttribute) || StringUtils.hasText( exceptionCodeHeader))) { exceptionCode = exceptionCodeResolver.resolveExceptionCode(ex); } if (exceptionCode == null) { return; } if (StringUtils.hasText(exceptionCodeAttribute)) { request.setAttribute(exceptionCodeAttribute, exceptionCode); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); if (flashMap != null) { flashMap.put(exceptionCodeAttribute, exceptionCode); } } if (StringUtils.hasText(exceptionCodeHeader)) { response.setHeader(exceptionCodeHeader, exceptionCode); } }  void setExceptionCodeAttribute(String exceptionCodeAttribute); void setExceptionCodeHeader(String exceptionCodeHeader); void setResultMessagesAttribute(String resultMessagesAttribute); void setExceptionCodeResolver(
            ExceptionCodeResolver exceptionCodeResolver);  }