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

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

Introduction

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

Prototype

String ERROR_REQUEST_URI_ATTRIBUTE

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

Click Source Link

Document

Standard Servlet 2.3+ spec request attribute for error page request URI.

Usage

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

/**
 * Populate the display with information from the current execution.
 * //from w  ww  . j  a va  2  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:org.springframework.security.web.authentication.www.BasicAuthenticationFilterTests.java

@Test
public void skippedOnErrorDispatch() throws Exception {

    String token = "bad:credentials";
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("Authorization", "Basic " + new String(Base64.encodeBase64(token.getBytes())));
    request.setServletPath("/some_file.html");
    request.setAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE, "/error");
    MockHttpServletResponse response = new MockHttpServletResponse();

    FilterChain chain = mock(FilterChain.class);

    filter.doFilter(request, response, chain);

    assertThat(response.getStatus()).isEqualTo(200);
}

From source file:org.springframework.web.util.UrlPathHelper.java

/**
 * Return the query string part of the given request's URL. If this is a forwarded request,
 * correctly resolves to the query string of the original request.
 * @param request current HTTP request// w  ww  .ja  v  a  2  s  . co m
 * @return the query string
 */
public String getOriginatingQueryString(HttpServletRequest request) {
    if ((request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE) != null)
            || (request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE) != null)) {
        return (String) request.getAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE);
    } else {
        return request.getQueryString();
    }
}