Example usage for org.springframework.web.util WebUtils ERROR_SERVLET_NAME_ATTRIBUTE

List of usage examples for org.springframework.web.util WebUtils ERROR_SERVLET_NAME_ATTRIBUTE

Introduction

In this page you can find the example usage for org.springframework.web.util WebUtils ERROR_SERVLET_NAME_ATTRIBUTE.

Prototype

String ERROR_SERVLET_NAME_ATTRIBUTE

To view the source code for org.springframework.web.util WebUtils ERROR_SERVLET_NAME_ATTRIBUTE.

Click Source Link

Document

Standard Servlet 2.3+ spec request attribute for error page servlet name.

Usage

From source file:org.carewebframework.ui.ExceptionController.java

/**
 * Populate the display with information from the current execution.
 * /*from w w  w .j a v a  2 s.  c  om*/
 * @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);
    }
}