Java Code Examples for javax.servlet.http.HttpServletRequest#isAsyncSupported()

The following examples show how to use javax.servlet.http.HttpServletRequest#isAsyncSupported() . 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: AsyncStockServlet.java    From Tomcat8-Source-Read with MIT License 7 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    if (req.isAsyncStarted()) {
        req.getAsyncContext().complete();
    } else if (req.isAsyncSupported()) {
        AsyncContext actx = req.startAsync();
        actx.addListener(this);
        resp.setContentType("text/plain");
        clients.add(actx);
        if (clientcount.incrementAndGet()==1) {
            Stockticker ticker = (Stockticker) req.getServletContext().getAttribute(
                    AsyncStockContextListener.STOCK_TICKER_KEY);
            ticker.addTickListener(this);
        }
    } else {
        new Exception("Async Not Supported").printStackTrace();
        resp.sendError(400,"Async is not supported.");
    }
}
 
Example 2
Source File: AsyncStockServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    if (req.isAsyncStarted()) {
        req.getAsyncContext().complete();
    } else if (req.isAsyncSupported()) {
        AsyncContext actx = req.startAsync();
        actx.addListener(this);
        resp.setContentType("text/plain");
        clients.add(actx);
        if (clientcount.incrementAndGet()==1) {
            Stockticker ticker = (Stockticker) req.getServletContext().getAttribute(
                    AsyncStockContextListener.STOCK_TICKER_KEY);
            ticker.addTickListener(this);
        }
    } else {
        new Exception("Async Not Supported").printStackTrace();
        resp.sendError(400,"Async is not supported.");
    }
}
 
Example 3
Source File: TestAsyncContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    if (req.isAsyncSupported()) {
        TestAsyncContextImpl.track("TimeoutServletGet-");
        final AsyncContext ac = req.startAsync();
        ac.setTimeout(ASYNC_TIMEOUT);

        if (completeOnTimeout != null) {
            ac.addListener(new TrackingListener(false,
                    completeOnTimeout.booleanValue(), dispatchUrl));
        }
    } else {
        resp.getWriter().print("FAIL: Async unsupported");
    }
}
 
Example 4
Source File: AsyncStockServlet.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    if (req.isAsyncStarted()) {
        req.getAsyncContext().complete();
    } else if (req.isAsyncSupported()) {
        AsyncContext actx = req.startAsync();
        actx.addListener(this);
        resp.setContentType("text/plain");
        clients.add(actx);
        if (clientcount.incrementAndGet()==1) {
            ticker.addTickListener(this);
        }
    } else {
        new Exception("Async Not Supported").printStackTrace();
        resp.sendError(400,"Async is not supported.");
    }
}
 
Example 5
Source File: TestAsyncContextImpl.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    if (req.isAsyncSupported()) {
        TestAsyncContextImpl.track("TimeoutServletGet-");
        final AsyncContext ac = req.startAsync();
        ac.setTimeout(ASYNC_TIMEOUT);

        if (completeOnTimeout != null) {
            ac.addListener(new TrackingListener(false,
                    completeOnTimeout.booleanValue(), dispatchUrl));
        }
    } else {
        resp.getWriter().print("FAIL: Async unsupported");
    }
}
 
Example 6
Source File: AsyncStockServlet.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    if (req.isAsyncStarted()) {
        req.getAsyncContext().complete();
    } else if (req.isAsyncSupported()) {
        AsyncContext actx = req.startAsync();
        actx.addListener(this);
        resp.setContentType("text/plain");
        clients.add(actx);
        if (clientcount.incrementAndGet()==1) {
            ticker.addTickListener(this);
        }
    } else {
        new Exception("Async Not Supported").printStackTrace();
        resp.sendError(400,"Async is not supported.");
    }
}
 
Example 7
Source File: AbstractHTTPDestination.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void setupContinuation(Message inMessage,
                                 final HttpServletRequest req,
                                 final HttpServletResponse resp) {
    try {
        if (isServlet3 && req.isAsyncSupported()) {
            inMessage.put(ContinuationProvider.class.getName(),
                          new Servlet3ContinuationProvider(req, resp, inMessage));
        } else if (cproviderFactory != null) {
            ContinuationProvider p = cproviderFactory.createContinuationProvider(inMessage, req, resp);
            if (p != null) {
                inMessage.put(ContinuationProvider.class.getName(), p);
            }
        }
    } catch (Throwable ex) {
        // the request may not implement the Servlet3 API
    }
}
 
Example 8
Source File: TestAsyncContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    if (req.isAsyncSupported()) {
        TestAsyncContextImpl.track("TimeoutServletGet-");
        final AsyncContext ac = req.startAsync();
        ac.setTimeout(ASYNC_TIMEOUT);

        if (completeOnTimeout != null) {
            ac.addListener(trackingListener);
        }
    } else {
        resp.getWriter().print("FAIL: Async unsupported");
    }
}
 
Example 9
Source File: Polling.java    From engine.io-server-java with MIT License 5 votes vote down vote up
private void onPollRequest(HttpServletRequest request,
                           @SuppressWarnings("unused") HttpServletResponse response) {
    if (mPollRequest != null) {
        onError("overlap from client", "");
        mPollResponse.setStatus(500);
        try (PrintWriter writer = mPollResponse.getWriter()) {
            writer.print("error");
            writer.flush();
        } catch (IOException ignore) {
        }
        return;
    }

    mPollRequest = request;
    mPollResponse = response;

    boolean asyncEnabled = false;
    if (request.isAsyncSupported() || request.isAsyncStarted()) {
        final AsyncContext asyncContext = request.startAsync();
        asyncContext.addListener(this);
        asyncContext.setTimeout(3 * 60 * 1000);

        asyncEnabled = true;
    }

    mWritable = true;
    emit("drain");

    if (mWritable && (!asyncEnabled || mShouldClose)) {
        send(new ArrayList<>(PACKET_NOOP));
    }
}
 
Example 10
Source File: AsyncStockServlet.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    if (req.isAsyncStarted()) {
        req.getAsyncContext().complete();
    } else if (req.isAsyncSupported()) {
        AsyncContext actx = req.startAsync();
        actx.addListener(this);
        resp.setContentType("text/plain");
        clients.add(actx);
        if (clientcount.incrementAndGet()==1) {
            ticker.addTickListener(this);
        }
    } else {
        new Exception("Async Not Supported").printStackTrace();
        resp.sendError(400,"Async is not supported.");
    }
}
 
Example 11
Source File: PathDisplay.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
public PathDisplay(HttpServletRequest req, String caller) {
      this.caller = caller;
      title = (String) req.getAttribute("title");
      async_request_uri = (String) req.getAttribute("javax.servlet.async.request_uri");
      async_context_path = (String) req.getAttribute("javax.servlet.async.context_path");
      async_servlet_path = (String) req.getAttribute("javax.servlet.async.servlet_path");
      async_path_info = (String) req.getAttribute("javax.servlet.async.path_info");
      async_query_string = (String) req.getAttribute("javax.servlet.async.query_string");

      forward_request_uri = (String) req.getAttribute("javax.servlet.forward.request_uri");
      forward_context_path = (String) req.getAttribute("javax.servlet.forward.context_path");
      forward_servlet_path = (String) req.getAttribute("javax.servlet.forward.servlet_path");
      forward_path_info = (String) req.getAttribute("javax.servlet.forward.path_info");
      forward_query_string = (String) req.getAttribute("javax.servlet.forward.query_string");

      include_request_uri = (String) req.getAttribute("javax.servlet.include.request_uri");
      include_context_path = (String) req.getAttribute("javax.servlet.include.context_path");
      include_servlet_path = (String) req.getAttribute("javax.servlet.include.servlet_path");
      include_path_info = (String) req.getAttribute("javax.servlet.include.path_info");
      include_query_string = (String) req.getAttribute("javax.servlet.include.query_string");

      method_request_uri = req.getRequestURI();
      method_context_path = req.getContextPath();
      method_servlet_path = req.getServletPath();
      method_path_info = req.getPathInfo();
      method_path_xlated = req.getPathTranslated();
      method_query_string = req.getQueryString();
      
      type = req.getDispatcherType().name();
      isAsyncSupported = req.isAsyncSupported();
      
      Map<String, String[]> pmap = req.getParameterMap();
      for (String key : pmap.keySet()) {
         params.put(key, Arrays.asList(pmap.get(key)));
      }
}
 
Example 12
Source File: PortletContainerImpl.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
/**
 * Indicates that a portlet resource Serving occured in the current request and calls
 * the processServeResource method of this portlet.
 * @param portletWindow the portlet Window
 * @param request               the servlet request
 * @param response              the servlet response
 * @throws PortletException          if one portlet has trouble fulfilling
 *                                   the request
 * @throws PortletContainerException if the portlet container implementation
 *                                   has trouble fulfilling the request
 */
public void doServeResource(PortletWindow portletWindow,
        HttpServletRequest request,
        HttpServletResponse response)
throws PortletException, IOException, PortletContainerException
{
    ensureInitialized();

    debugWithName("Resource request received for portlet: "
            + portletWindow.getPortletDefinition().getPortletName());

    PortletRequestContextService rcService = getContainerServices().getPortletRequestContextService();
    PortletEnvironmentService envService = getContainerServices().getPortletEnvironmentService();
    PortletInvokerService invoker = getContainerServices().getPortletInvokerService();

    PortletResourceRequestContext requestContext = rcService.getPortletResourceRequestContext(this, request, response, portletWindow);
    PortletResourceResponseContext responseContext = rcService.getPortletResourceResponseContext(this, request, response, portletWindow, requestContext);
    responseContext.setPropsAllowed(true);
    ResourceRequest portletRequest = envService.createResourceRequest(requestContext, responseContext);
    ResourceResponse portletResponse = envService.createResourceResponse(responseContext, requestContext.getCacheability());
    requestContext.setResponse(portletResponse);     // for async support

    FilterManager filterManager = filterInitialisation(portletWindow,PortletRequest.RESOURCE_PHASE);
    
    try
    {
       invoker.serveResource(requestContext, portletRequest, portletResponse, filterManager);
    }
    finally
    {
        if (!request.isAsyncSupported() || !request.isAsyncStarted()) {
            // Mark portlet interaction is completed: backend implementation can flush response state now
            responseContext.close();
            responseContext.release();
        } else {
           LOG.debug("Async started for resource request. responseContext not released.");
        }
    }

    debugWithName("Portlet resource done for: " + portletWindow.getPortletDefinition().getPortletName());
}