/** * Factory for creating instances of this class. * * @param request * @return instance of request contains error attributes or {@code null} if it does not. */ public static ErrorAttributes of(HttpServletRequest request, String filterPrefix) { Args.notNull(request, "request"); Integer code = (Integer)request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); String message = (String)request.getAttribute(RequestDispatcher.ERROR_MESSAGE); String uri = DispatchedRequestUtils.getRequestUri(request, RequestDispatcher.ERROR_REQUEST_URI, filterPrefix); String servlet = (String)request.getAttribute(RequestDispatcher.ERROR_SERVLET_NAME); @SuppressWarnings("unchecked") Class<? extends Throwable> type = (Class<? extends Throwable>)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE); Throwable ex = (Throwable)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); if (!Strings.isEmpty(uri) || code != null || ex != null) { return new ErrorAttributes(code, message, uri, servlet, type, ex); } return null; }
@Override public boolean shouldPreserveClientUrl() { return (errorAttributes != null && !Strings.isEmpty(errorAttributes.getRequestUri()) || forwardAttributes != null && !Strings.isEmpty(forwardAttributes.getRequestUri())); } }
/** * Construct. * * @param httpServletRequest * @param filterPrefix * contentPath + filterPath, used to extract the actual {@link Url} * @param url */ public ServletWebRequest(HttpServletRequest httpServletRequest, String filterPrefix, Url url) { Args.notNull(httpServletRequest, "httpServletRequest"); Args.notNull(filterPrefix, "filterPrefix"); this.httpServletRequest = httpServletRequest; errorAttributes = ErrorAttributes.of(httpServletRequest, filterPrefix); forwardAttributes = ForwardAttributes.of(httpServletRequest, filterPrefix); this.filterPrefix = filterPrefix; if (url != null) { this.url = url; } else { this.url = getContextRelativeUrl(httpServletRequest.getRequestURI(), filterPrefix); } }
/** * Construct. * * @param httpServletRequest * @param filterPrefix * contentPath + filterPath, used to extract the actual {@link Url} * @param url */ public ServletWebRequest(HttpServletRequest httpServletRequest, String filterPrefix, Url url) { Args.notNull(httpServletRequest, "httpServletRequest"); Args.notNull(filterPrefix, "filterPrefix"); this.httpServletRequest = httpServletRequest; errorAttributes = ErrorAttributes.of(httpServletRequest, filterPrefix); forwardAttributes = ForwardAttributes.of(httpServletRequest, filterPrefix); this.filterPrefix = filterPrefix; if (url != null) { this.url = url; } else { this.url = getContextRelativeUrl(httpServletRequest.getRequestURI(), filterPrefix); } }
@Override public boolean shouldPreserveClientUrl() { return (errorAttributes != null && !Strings.isEmpty(errorAttributes.getRequestUri()) || forwardAttributes != null && !Strings.isEmpty(forwardAttributes.getRequestUri())); } }
/** * Factory for creating instances of this class. * * @param request * @return instance of request contains error attributes or {@code null} if it does not. */ public static ErrorAttributes of(HttpServletRequest request, String filterPrefix) { Args.notNull(request, "request"); Integer code = (Integer)request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); String message = (String)request.getAttribute(RequestDispatcher.ERROR_MESSAGE); String uri = DispatchedRequestUtils.getRequestUri(request, RequestDispatcher.ERROR_REQUEST_URI, filterPrefix); String servlet = (String)request.getAttribute(RequestDispatcher.ERROR_SERVLET_NAME); @SuppressWarnings("unchecked") Class<? extends Throwable> type = (Class<? extends Throwable>)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE); Throwable ex = (Throwable)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); if (!Strings.isEmpty(uri) || code != null || ex != null) { return new ErrorAttributes(code, message, uri, servlet, type, ex); } return null; }
public Url getClientUrl() if (errorAttributes != null && !Strings.isEmpty(errorAttributes.getRequestUri())) String problematicURI = Url.parse(errorAttributes.getRequestUri(), getCharset(), false) .toString(); return getContextRelativeUrl(problematicURI, filterPrefix);
public Url getClientUrl() if (errorAttributes != null && !Strings.isEmpty(errorAttributes.getRequestUri())) String problematicURI = Url.parse(errorAttributes.getRequestUri(), getCharset(), false) .toString(); return getContextRelativeUrl(problematicURI, filterPrefix);