Example usage for javax.servlet ServletRequest getDispatcherType

List of usage examples for javax.servlet ServletRequest getDispatcherType

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getDispatcherType.

Prototype

public DispatcherType getDispatcherType();

Source Link

Document

Gets the dispatcher type of this request.

Usage

From source file:org.debux.webmotion.server.WebMotionServer.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpServletRequest = ((HttpServletRequest) request);
    HttpServletResponse httpServletResponse = ((HttpServletResponse) response);
    ServerContext serverContext = getServerContext(httpServletRequest);

    String uri = null;/*from w ww .  ja va 2s. c  o m*/
    DispatcherType dispatcherType = request.getDispatcherType();
    if (dispatcherType == DispatcherType.INCLUDE) {
        uri = (String) httpServletRequest.getAttribute(HttpContext.ATTRIBUTE_INCLUDE_REQUEST_URI);
    }
    if (uri == null) {
        uri = httpServletRequest.getRequestURI();
    }

    String contextPath = httpServletRequest.getContextPath();
    String url = StringUtils.substringAfter(uri, contextPath);
    log.debug("Pass in filter = " + url);

    // Search if url is exclude path
    for (String path : serverContext.getExcludePaths()) {
        if (url.startsWith(path)) {
            url = PATH_SERVLET + url;
            break;
        }
    }

    if (url.startsWith(PATH_DEPLOY) || url.startsWith(PATH_ERROR) || url.equals("/")) {
        log.debug("Is deploy");
        doAction(httpServletRequest, httpServletResponse);

    } else if (url.startsWith(PATH_STATIC)) {
        log.debug("Is static");
        doResource(httpServletRequest, httpServletResponse);

    } else if (url.startsWith(PATH_SERVLET)) {
        log.debug("Is servlet");
        chain.doFilter(request, response);

    } else {
        String webappPath = serverContext.getWebappPath();
        File file = new File(webappPath, url);
        if (file.exists()) {
            // css js html png jpg jpeg xml ...
            log.debug("Is file");
            chain.doFilter(request, response);
        } else {
            log.debug("Is default");
            doAction(httpServletRequest, httpServletResponse);
        }
    }
}

From source file:org.springframework.http.server.reactive.ServletHttpHandlerAdapter.java

@Override
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    if (DispatcherType.ASYNC.equals(request.getDispatcherType())) {
        Throwable ex = (Throwable) request.getAttribute(WRITE_ERROR_ATTRIBUTE_NAME);
        throw new ServletException("Write publisher error", ex);
    }/*from  ww w  .j  ava2  s  .  c  o m*/

    // Start async before Read/WriteListener registration
    AsyncContext asyncContext = request.startAsync();
    asyncContext.setTimeout(-1);

    ServerHttpRequest httpRequest = createRequest(((HttpServletRequest) request), asyncContext);
    ServerHttpResponse httpResponse = createResponse(((HttpServletResponse) response), asyncContext);

    if (HttpMethod.HEAD.equals(httpRequest.getMethod())) {
        httpResponse = new HttpHeadResponseDecorator(httpResponse);
    }

    AtomicBoolean isCompleted = new AtomicBoolean();
    HandlerResultAsyncListener listener = new HandlerResultAsyncListener(isCompleted);
    asyncContext.addListener(listener);

    HandlerResultSubscriber subscriber = new HandlerResultSubscriber(asyncContext, isCompleted);
    this.httpHandler.handle(httpRequest, httpResponse).subscribe(subscriber);
}