Example usage for javax.servlet.http HttpServletRequest getAsyncContext

List of usage examples for javax.servlet.http HttpServletRequest getAsyncContext

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getAsyncContext.

Prototype

public AsyncContext getAsyncContext();

Source Link

Document

Gets the AsyncContext that was created or reinitialized by the most recent invocation of #startAsync or #startAsync(ServletRequest,ServletResponse) on this request.

Usage

From source file:org.ireland.jnetty.webapp.RequestDispatcherImpl.java

private void doInclude(HttpServletRequest request, HttpServletResponse response, HttpInvocation invocation)
        throws ServletException, IOException {

    //Wrap the request
    IncludeRequest wrequest = new IncludeRequest(request, response, invocation);

    // If we have already been include previously, then keep using the established
    // original value. Otherwise, this is the first include and we need to establish the values.
    // Note: the established value on the original request for pathInfo and
    // for queryString is allowed to be null, but cannot be null for the other values.
    if (request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) == null) {
        // ?Include,
        wrequest.setAttribute(RequestDispatcher.INCLUDE_REQUEST_URI, request.getRequestURI());

        wrequest.setAttribute(RequestDispatcher.INCLUDE_CONTEXT_PATH, request.getContextPath());
        wrequest.setAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH, request.getServletPath());
        wrequest.setAttribute(RequestDispatcher.INCLUDE_PATH_INFO, request.getPathInfo());
        wrequest.setAttribute(RequestDispatcher.INCLUDE_QUERY_STRING, request.getQueryString());
    }//from   ww w  . j a  v a2 s . c o m

    boolean isValid = false;

    try {

        invocation.getFilterChainInvocation().service(wrequest, response);

        isValid = true;
    } finally {
        if (request.getAsyncContext() != null) {
            // An async request was started during the forward, don't close the
            // response as it may be written to during the async handling
            return;
        }

        // server/106r, ioc/0310
        if (isValid) {
            finishResponse(response);
        }
    }
}

From source file:org.ireland.jnetty.webapp.RequestDispatcherImpl.java

private void doError(HttpServletRequest request, HttpServletResponse response, HttpInvocation invocation)
        throws ServletException, IOException {

    // Reset any output that has been buffered, but keep headers/cookies
    response.resetBuffer(); // Servlet-3_1-PFD 9.4

    //Wrap the request
    ErrorRequest wrequest = new ErrorRequest(request, response, invocation);

    boolean isValid = false;

    try {/*  w w  w .  ja  va2s.  c  o  m*/

        invocation.getFilterChainInvocation().service(wrequest, response);

        isValid = true;
    } finally {
        if (request.getAsyncContext() != null) {
            // An async request was started during the forward, don't close the
            // response as it may be written to during the async handling
            return;
        }

        // server/106r, ioc/0310
        if (isValid) {
            finishResponse(response);
        }
    }
}