javax.servlet.http.HttpServletRequest#isAsyncSupported()源码实例Demo

下面列出了javax.servlet.http.HttpServletRequest#isAsyncSupported() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Tomcat8-Source-Read   文件: AsyncStockServlet.java
@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.");
    }
}
 
源代码2 项目: Tomcat8-Source-Read   文件: AsyncStockServlet.java
@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.");
    }
}
 
源代码3 项目: Tomcat7.0.67   文件: TestAsyncContextImpl.java
@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");
    }
}
 
源代码4 项目: tomcatsrc   文件: AsyncStockServlet.java
@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.");
    }
}
 
源代码5 项目: tomcatsrc   文件: AsyncStockServlet.java
@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.");
    }
}
 
源代码6 项目: tomcatsrc   文件: TestAsyncContextImpl.java
@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");
    }
}
 
源代码7 项目: tomcatsrc   文件: AsyncStockServlet.java
@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.");
    }
}
 
源代码8 项目: cxf   文件: AbstractHTTPDestination.java
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
    }
}
 
@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");
    }
}
 
源代码10 项目: engine.io-server-java   文件: Polling.java
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));
    }
}
 
源代码11 项目: portals-pluto   文件: PathDisplay.java
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)));
      }
}
 
源代码12 项目: portals-pluto   文件: PortletContainerImpl.java
/**
 * 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());
}