List of usage examples for org.springframework.web.util WebUtils ERROR_EXCEPTION_ATTRIBUTE
String ERROR_EXCEPTION_ATTRIBUTE
To view the source code for org.springframework.web.util WebUtils ERROR_EXCEPTION_ATTRIBUTE.
Click Source Link
From source file:org.carewebframework.ui.ExceptionController.java
/** * Populate the display with information from the current execution. * /*from w w w. j a v a2 s. co m*/ * @see org.zkoss.zk.ui.util.GenericAutowireComposer#doAfterCompose(org.zkoss.zk.ui.Component) */ @Override public void doAfterCompose(final Component comp) throws Exception { super.doAfterCompose(comp); Clients.clearBusy(); this.root = ZKUtil.findAncestor(comp, Window.class); final HttpServletRequest req = (HttpServletRequest) this.execution.getNativeRequest(); Class<?> errClass = (Class<?>) req.getAttribute(WebUtils.ERROR_EXCEPTION_TYPE_ATTRIBUTE); String errMsg = (String) req.getAttribute(WebUtils.ERROR_MESSAGE_ATTRIBUTE); Throwable err = (Throwable) req.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE); final String errReqURI = (String) req.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE); final String errServletName = (String) req.getAttribute(WebUtils.ERROR_SERVLET_NAME_ATTRIBUTE); final Integer errStatusCode = (Integer) req.getAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE); String throwableContext = null; if (err != null) { if (err instanceof IThrowableContext) { throwableContext = ((IThrowableContext) err).getThrowableContext(); } //stack trace info if (err instanceof NestedCheckedException) { err = ((NestedCheckedException) err).getMostSpecificCause(); } else if (err instanceof NestedRuntimeException) { err = ((NestedRuntimeException) err).getMostSpecificCause(); } } if (err != null) { errClass = errClass == null ? err.getClass() : errClass; errMsg = StringUtils.trimToNull(errMsg) == null ? err.getMessage() : errMsg; } final StringBuffer buffer = new StringBuffer(); //generic exception info buffer.append("\nException class: ").append(errClass); buffer.append("\nMessage: ").append(errMsg); if (err instanceof ErrorCoded) { final String errorCode = ((ErrorCoded) err).getErrorCode(); buffer.append("\nErrorCode: ").append(errorCode); this.lblCode.setValue(errorCode); } buffer.append("\nStatusCode: ").append(errStatusCode); buffer.append("\nServletName: ").append(errServletName); buffer.append("\nReqURI: ").append(errReqURI); final SessionInfo sessionInfo = Application.getInstance().getSessionInfo(this.desktop); buffer.append(sessionInfo); buffer.append("\nThrowableContext: " + throwableContext); buffer.append("\nStackTrace: "); appendStackTrace(err); log.error(buffer, err); this.lblExceptionClass.setValue(String.valueOf(errClass)); this.lblMessage.setValue(errMsg); this.lblStatusCode.setValue(String.valueOf(errStatusCode)); if (SecurityUtil.isGrantedAny(Labels.getLabel("cwf.error.dialog.expanded"))) { Events.echoEvent(Events.ON_CLICK, this.btnDetail, null); } }
From source file:com.wiiyaya.consumer.web.main.controller.ExceptionController.java
@RequestMapping(MainURIResource.PATH_ERROR_ALL) public String error(HttpServletRequest request) throws Throwable { Integer code = (Integer) request.getAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE); Throwable exception = (Throwable) request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE); String simpleMsg = (String) request.getAttribute(WebUtils.ERROR_MESSAGE_ATTRIBUTE); if (exception != null) { throw getRootCause(exception); } else {//from ww w .jav a2s . c om switch (code) { case 404: throw new PageNotFoundException(); case 403: throw new AccessDeniedException(simpleMsg); default: throw new Exception(simpleMsg); } } }
From source file:com.devnexus.ting.web.controller.SiteController.java
@RequestMapping("/s/handleGlobaleErrors") public String onUploadError(HttpServletRequest request, final Model model, RedirectAttributes redirectAttributes) { final Object errorExceptionObject = request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE); if (errorExceptionObject instanceof MultipartException) { final MultipartException multipartException = (MultipartException) errorExceptionObject; final Throwable rootCause = multipartException.getRootCause(); String errorMessage = ""; if (rootCause instanceof SizeLimitExceededException || rootCause instanceof FileSizeLimitExceededException) { errorMessage = String.format( "The file that you are trying to upload is unfortunately too big. Uploaded files cannot be bigger than <strong>%s</strong>." + " Please go back and upload a smaller image file.", multipartProperties.getMaxFileSize()); } else {/*from w w w. j av a 2 s . c o m*/ errorMessage = (String) request.getAttribute(WebUtils.ERROR_MESSAGE_ATTRIBUTE); } redirectAttributes.addFlashAttribute("error", errorMessage); return "redirect:/s/uploadError"; } else { return "error/error"; } }
From source file:org.springframework.web.servlet.DispatcherServlet.java
/** * Convert the request into a multipart request, and make multipart resolver available. * <p>If no multipart resolver is set, simply use the existing request. * @param request current HTTP request//from www.j a v a 2 s. c o m * @return the processed request (multipart wrapper if necessary) * @see MultipartResolver#resolveMultipart */ protected HttpServletRequest checkMultipart(HttpServletRequest request) throws MultipartException { if (this.multipartResolver != null && this.multipartResolver.isMultipart(request)) { if (WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class) != null) { logger.debug("Request is already a MultipartHttpServletRequest - if not in a forward, " + "this typically results from an additional MultipartFilter in web.xml"); } else if (hasMultipartException(request)) { logger.debug("Multipart resolution failed for current request before - " + "skipping re-resolution for undisturbed error rendering"); } else { try { return this.multipartResolver.resolveMultipart(request); } catch (MultipartException ex) { if (request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) != null) { logger.debug("Multipart resolution failed for error dispatch", ex); // Keep processing error dispatch with regular request handle below } else { throw ex; } } } } // If not returned before: return original request. return request; }
From source file:org.springframework.web.servlet.DispatcherServlet.java
/** * Check "javax.servlet.error.exception" attribute for a multipart exception. *///from w w w .jav a 2 s .c o m private boolean hasMultipartException(HttpServletRequest request) { Throwable error = (Throwable) request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE); while (error != null) { if (error instanceof MultipartException) { return true; } error = error.getCause(); } return false; }
From source file:org.springframework.web.servlet.LogDispatcherServlet.java
/** * Convert the request into a multipart request, and make multipart resolver available. * <p>If no multipart resolver is set, simply use the existing request. * @param request current HTTP request/*from www. j av a 2 s .c o m*/ * @return the processed request (multipart wrapper if necessary) * @see MultipartResolver#resolveMultipart */ protected HttpServletRequest checkMultipart(HttpServletRequest request) throws MultipartException { if (this.multipartResolver != null && this.multipartResolver.isMultipart(request)) { if (WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class) != null) { logger.debug("Request is already a MultipartHttpServletRequest - if not in a forward, " + "this typically results from an additional MultipartFilter in web.xml"); } else if (request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) instanceof MultipartException) { logger.debug("Multipart resolution failed for current request before - " + "skipping re-resolution for undisturbed error rendering"); } else { return this.multipartResolver.resolveMultipart(request); } } // If not returned before: return original request. return request; }
From source file:org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler.java
/** * A single place to customize the response body of all Exception types. * <p>The default implementation sets the {@link WebUtils#ERROR_EXCEPTION_ATTRIBUTE} * request attribute and creates a {@link ResponseEntity} from the given * body, headers, and status./* w w w . ja v a 2s .c om*/ * @param ex the exception * @param body the body for the response * @param headers the headers for the response * @param status the response status * @param request the current request */ protected ResponseEntity<Object> handleExceptionInternal(Exception ex, @Nullable Object body, HttpHeaders headers, HttpStatus status, WebRequest request) { if (HttpStatus.INTERNAL_SERVER_ERROR.equals(status)) { request.setAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE, ex, WebRequest.SCOPE_REQUEST); } return new ResponseEntity<>(body, headers, status); }