Java Code Examples for javax.servlet.DispatcherType#ERROR

The following examples show how to use javax.servlet.DispatcherType#ERROR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractServerHandleInterceptor.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }

    try {
        final HttpServletRequest request = toHttpServletRequest(args);
        if (request.getDispatcherType() == DispatcherType.ASYNC || request.getDispatcherType() == DispatcherType.ERROR) {
            if (isDebug) {
                logger.debug("Skip async servlet request event. isAsyncStarted={}, dispatcherType={}", request.isAsyncStarted(), request.getDispatcherType());
            }
            return;
        }
        this.servletRequestListenerInterceptorHelper.initialized(request, JettyConstants.JETTY_METHOD, this.methodDescriptor);
    } catch (Throwable t) {
        logger.info("Failed to servlet request event handle.", t);
    }
}
 
Example 2
Source File: AbstractServerHandleInterceptor.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }

    try {
        final HttpServletRequest request = toHttpServletRequest(args);
        final HttpServletResponse response = toHttpServletResponse(args);
        if (request.getDispatcherType() == DispatcherType.ASYNC || request.getDispatcherType() == DispatcherType.ERROR) {
            if (isDebug) {
                logger.debug("Skip async servlet request event. isAsyncStarted={}, dispatcherType={}", request.isAsyncStarted(), request.getDispatcherType());
            }
            return;
        }
        final int statusCode = getStatusCode(response);
        this.servletRequestListenerInterceptorHelper.destroyed(request, throwable, statusCode);
    } catch (Throwable t) {
        if (isInfo) {
            logger.info("Failed to servlet request event handle.", t);
        }
    }
}
 
Example 3
Source File: DefaultServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    if (req.getDispatcherType() == DispatcherType.ERROR) {
        doGet(req, resp);
    } else {
        super.service(req, resp);
    }
}
 
Example 4
Source File: ApplicationDispatcher.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Prepare the request based on the filter configuration.
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param state The RD state
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */
private void processRequest(ServletRequest request,
                            ServletResponse response,
                            State state)
    throws IOException, ServletException {

    DispatcherType disInt = (DispatcherType) request.getAttribute(Globals.DISPATCHER_TYPE_ATTR);
    if (disInt != null) {
        boolean doInvoke = true;

        if (context.getFireRequestListenersOnForwards() &&
                !context.fireRequestInitEvent(request)) {
            doInvoke = false;
        }

        if (doInvoke) {
            if (disInt != DispatcherType.ERROR) {
                state.outerRequest.setAttribute(
                        Globals.DISPATCHER_REQUEST_PATH_ATTR,
                        getCombinedPath());
                state.outerRequest.setAttribute(
                        Globals.DISPATCHER_TYPE_ATTR,
                        DispatcherType.FORWARD);
                invoke(state.outerRequest, response, state);
            } else {
                invoke(state.outerRequest, response, state);
            }

            if (context.getFireRequestListenersOnForwards()) {
                context.fireRequestDestroyEvent(request);
            }
        }
    }
}
 
Example 5
Source File: AssetServlet.java    From onedev with MIT License 5 votes vote down vote up
public AssetServlet() {
	super(new ResourceService() {
		
		@Override
		protected void putHeaders(HttpServletResponse response, HttpContent content, long contentLength) {
			super.putHeaders(response, content, contentLength);
			
			HttpFields fields;
			if (response instanceof Response)
				fields = ((Response) response).getHttpFields();
			else
				fields = ((Response)((HttpServletResponseWrapper) response).getResponse()).getHttpFields();
			
			if (requestHolder.get().getDispatcherType() == DispatcherType.ERROR) {
				/*
				 * Do not cache error page and also makes sure that error page is not eligible for 
				 * modification check. That is, error page will be always retrieved.
				 */
	            fields.put(HttpHeader.CACHE_CONTROL, "must-revalidate,no-cache,no-store");
			} else if (requestHolder.get().getRequestURI().equals("/favicon.ico")) {
				/*
				 * Make sure favicon request is cached. Otherwise, it will be requested for every 
				 * page request.
				 */
				fields.put(HttpHeader.CACHE_CONTROL, "max-age=86400,public");
			}
		}
		
	});
}
 
Example 6
Source File: ApplicationDispatcher.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Prepare the request based on the filter configuration.
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param state The RD state
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */
private void processRequest(ServletRequest request, 
                            ServletResponse response,
                            State state)
    throws IOException, ServletException {
            
    DispatcherType disInt = (DispatcherType) request.getAttribute(Globals.DISPATCHER_TYPE_ATTR);
    if (disInt != null) {
        boolean doInvoke = true;
        
        if (context.getFireRequestListenersOnForwards() &&
                !context.fireRequestInitEvent(request)) {
            doInvoke = false;
        }

        if (doInvoke) {
            if (disInt != DispatcherType.ERROR) {
                state.outerRequest.setAttribute(
                        Globals.DISPATCHER_REQUEST_PATH_ATTR,
                        getCombinedPath());
                state.outerRequest.setAttribute(
                        Globals.DISPATCHER_TYPE_ATTR,
                        DispatcherType.FORWARD);
                invoke(state.outerRequest, response, state);
            } else {
                invoke(state.outerRequest, response, state);
            }
            
            if (context.getFireRequestListenersOnForwards()) {
                context.fireRequestDestroyEvent(request);
            }
        }
    }
}
 
Example 7
Source File: ApplicationDispatcher.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Prepare the request based on the filter configuration.
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param state The RD state
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */
private void processRequest(ServletRequest request, 
                            ServletResponse response,
                            State state)
    throws IOException, ServletException {
            
    DispatcherType disInt = (DispatcherType) request.getAttribute(Globals.DISPATCHER_TYPE_ATTR);
    if (disInt != null) {
        boolean doInvoke = true;
        
        if (context.getFireRequestListenersOnForwards() &&
                !context.fireRequestInitEvent(request)) {
            doInvoke = false;
        }

        if (doInvoke) {
            if (disInt != DispatcherType.ERROR) {
                state.outerRequest.setAttribute(
                        Globals.DISPATCHER_REQUEST_PATH_ATTR,
                        getCombinedPath());
                state.outerRequest.setAttribute(
                        Globals.DISPATCHER_TYPE_ATTR,
                        DispatcherType.FORWARD);
                invoke(state.outerRequest, response, state);
            } else {
                invoke(state.outerRequest, response, state);
            }
            
            if (context.getFireRequestListenersOnForwards()) {
                context.fireRequestDestroyEvent(request);
            }
        }
    }
}
 
Example 8
Source File: WebdavServlet.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Handles the special WebDAV methods.
 */
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

    final String path = getRelativePath(req);

    // Error page check needs to come before special path check since
    // custom error pages are often located below WEB-INF so they are
    // not directly accessible.
    if (req.getDispatcherType() == DispatcherType.ERROR) {
        doGet(req, resp);
        return;
    }

    // Block access to special subdirectories.
    // DefaultServlet assumes it services resources from the root of the web app
    // and doesn't add any special path protection
    // WebdavServlet remounts the webapp under a new path, so this check is
    // necessary on all methods (including GET).
    if (isSpecialPath(path)) {
        resp.sendError(WebdavStatus.SC_NOT_FOUND);
        return;
    }

    final String method = req.getMethod();

    if (debug > 0) {
        log("[" + method + "] " + path);
    }

    if (method.equals(METHOD_PROPFIND)) {
        doPropfind(req, resp);
    } else if (method.equals(METHOD_PROPPATCH)) {
        doProppatch(req, resp);
    } else if (method.equals(METHOD_MKCOL)) {
        doMkcol(req, resp);
    } else if (method.equals(METHOD_COPY)) {
        doCopy(req, resp);
    } else if (method.equals(METHOD_MOVE)) {
        doMove(req, resp);
    } else if (method.equals(METHOD_LOCK)) {
        doLock(req, resp);
    } else if (method.equals(METHOD_UNLOCK)) {
        doUnlock(req, resp);
    } else {
        // DefaultServlet processing
        super.service(req, resp);
    }

}
 
Example 9
Source File: TestApplicationContextGetRequestDispatcherB.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    Assert.assertEquals(expectedRequestURI, req.getRequestURI());
    Assert.assertEquals(expectedContextPath, req.getContextPath());
    Assert.assertEquals(expectedServletPath, req.getServletPath());
    Assert.assertEquals(expectedPathInfo, req.getPathInfo());
    Assert.assertEquals(expectedQueryString, req.getQueryString());
    HttpServletMapping mapping =
            ((org.apache.catalina.servlet4preview.http.HttpServletRequest) req).getHttpServletMapping();
    Assert.assertEquals(expectedMappingMatch, mapping.getMappingMatch());
    Assert.assertEquals(expectedMappingPattern, mapping.getPattern());
    Assert.assertEquals(expectedMappingMatchValue, mapping.getMatchValue());
    Assert.assertEquals(expectedMappingServletName, mapping.getServletName());

    for (DispatcherType type : DispatcherType.values()) {
        if (type == dispatcherType) {
            String name = dispatcherType.name().toLowerCase(Locale.ENGLISH);
            Assert.assertEquals(expectedDispatcherRequestURI,
                    req.getAttribute("javax.servlet." + name + ".request_uri"));
            Assert.assertEquals(expectedDispatcherContextPath,
                    req.getAttribute("javax.servlet." + name + ".context_path"));
            Assert.assertEquals(expectedDispatcherServletPath,
                    req.getAttribute("javax.servlet." + name + ".servlet_path"));
            Assert.assertEquals(expectedDispatcherPathInfo,
                    req.getAttribute("javax.servlet." + name + ".path_info"));
            Assert.assertEquals(expectedDispatcherQueryString,
                    req.getAttribute("javax.servlet." + name + ".query_string"));
            HttpServletMapping dispatcherMapping =
                    (HttpServletMapping) ((org.apache.catalina.servlet4preview.http.HttpServletRequest) req).getAttribute(
                            "javax.servlet." + name + ".mapping");
            Assert.assertNotNull(dispatcherMapping);
            Assert.assertEquals(expectedDispatcherMappingMatch,
                    dispatcherMapping.getMappingMatch());
            Assert.assertEquals(expectedDispatcherMappingPattern,
                    dispatcherMapping.getPattern());
            Assert.assertEquals(expectedDispatcherMappingMatchValue,
                    dispatcherMapping.getMatchValue());
            Assert.assertEquals(expectedDispatcherMappingServletName,
                    dispatcherMapping.getServletName());
        } else if (type == DispatcherType.ERROR || type == DispatcherType.REQUEST) {
            // Skip - not tested
        } else {
            assertAllNull(req, type.name().toLowerCase(Locale.ENGLISH));
        }
    }

    resp.setContentType("text/plain");
    resp.setCharacterEncoding("UTF-8");
    PrintWriter pw = resp.getWriter();
    pw.print("OK");
}