List of usage examples for javax.servlet DispatcherType ERROR
DispatcherType ERROR
To view the source code for javax.servlet DispatcherType ERROR.
Click Source Link
From source file:org.dd4t.mvc.controllers.AbstractPageController.java
private String adjustLocalErrorUrl(HttpServletRequest request, String url) { if (request.getDispatcherType() == DispatcherType.ERROR) { url = publicationResolver.getLocalPageUrl(url); }/*w w w . j ava2 s . c o m*/ return url; }
From source file:org.eclipse.gyrex.http.jetty.internal.app.ApplicationHandler.java
@Override public void doScope(String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { /*/* w w w . j a va 2s .c o m*/ * IMPLEMENTATION NOTE * * This method is overridden to customize the path handling. * * Normally, a ContextHandler has a context path. However, the ApplicationHandler * must inherit the context path from the calling ApplicationHandlerCollection because * it changes depending on the incoming url. * * Additionally, class loader handling has been disabled in order to rely on the Equinox default. */ // note, we do not support requests going through different contexts final ContextHandler.Context origContext = baseRequest.getContext(); if ((origContext != null) && (origContext != _scontext)) throw new IllegalStateException( "origContext != this context, nesting/cross-application routing not supported!"); // backup paths final String origContextPath = baseRequest.getContextPath(); final String origServletPath = baseRequest.getServletPath(); final String origPathInfo = baseRequest.getPathInfo(); // if the current context is not set, we need to set and restore final boolean newContext = (origContext == null) || (currentContextPath.get() == null); // set 'current' context path if not already set if (newContext) { // note, we rely on ApplicationHandlerCollection to pre-set the // correct context path on the request currentContextPath.set(baseRequest.getContextPath()); } try { final String contextPath = currentContextPath.get(); String pathInfo = null; final DispatcherType dispatch = baseRequest.getDispatcherType(); // Are we already in this context? if (newContext) { // check the target if (DispatcherType.REQUEST.equals(dispatch) || DispatcherType.ASYNC.equals(dispatch)) { // perform checkContext to support unavailable status if (!checkContext(target, baseRequest, response)) return; // only accept requests coming through ApplicationHandlerCollection if (contextPath == null) return; // calculate paths if (target.length() > contextPath.length()) { if (contextPath.length() > 1) { target = target.substring(contextPath.length()); } pathInfo = target; } else if (contextPath.length() == 1) { target = URIUtil.SLASH; pathInfo = URIUtil.SLASH; } else { // redirect null path infos in order to have context request end with / baseRequest.setHandled(true); if (baseRequest.getQueryString() != null) { response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(), URIUtil.SLASH) + "?" + baseRequest.getQueryString()); } else { response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(), URIUtil.SLASH)); } return; } } } else { // calculate paths for forwarded requests // (note, handle error dispatches like forwards for custom error handler support) if ((DispatcherType.FORWARD.equals(dispatch) || DispatcherType.ERROR.equals(dispatch)) && target.startsWith(URIUtil.SLASH)) { pathInfo = target; } } // update the paths baseRequest.setContext(_scontext); if (!DispatcherType.INCLUDE.equals(dispatch) && target.startsWith(URIUtil.SLASH)) { if (contextPath.length() == 1) { baseRequest.setContextPath(EMPTY_STRING); } else { baseRequest.setContextPath(contextPath); } baseRequest.setServletPath(null); baseRequest.setPathInfo(pathInfo); } // set application handler debug info reference if (showDebugInfo) { final StringBuilder dump = new StringBuilder(); dump(dump); baseRequest.setAttribute(ATTRIBUTE_DEBUG_INFO, dump.toString()); } // next scope // start manual inline of nextScope(target,baseRequest,request,response); if (never()) { nextScope(target, baseRequest, request, response); } else if (_nextScope != null) { _nextScope.doScope(target, baseRequest, request, response); } else if (_outerScope != null) { _outerScope.doHandle(target, baseRequest, request, response); } else { doHandle(target, baseRequest, request, response); } // end manual inline (pathetic attempt to reduce stack depth) } finally { if (newContext) { // reset the context and servlet path baseRequest.setContext(origContext); baseRequest.setContextPath(origContextPath); baseRequest.setServletPath(origServletPath); baseRequest.setPathInfo(origPathInfo); currentContextPath.set(null); } } }