Package javax.servlet

Examples of javax.servlet.AsyncContext


    private final static Logger LOG = Logger.getLogger(CometEscalator.class.getName());

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        AsyncContext startAsync = request.startAsync();
        String channel = extractChannel(request.getRequestURI());
        events.fire(new BrowserWindow(startAsync, channel));
        LOG.fine("Event sent for channel " + channel);
    }
View Full Code Here


            super(request, trustResolver, rolePrefix);
            this.response = response;
        }

        public AsyncContext getAsyncContext() {
            AsyncContext asyncContext = super.getAsyncContext();
            return new SecurityContextAsyncContext(asyncContext);
        }
View Full Code Here

            AsyncContext asyncContext = super.getAsyncContext();
            return new SecurityContextAsyncContext(asyncContext);
        }

        public AsyncContext startAsync() {
            AsyncContext startAsync = super.startAsync();
            return new SecurityContextAsyncContext(startAsync);
        }
View Full Code Here

            return new SecurityContextAsyncContext(startAsync);
        }

        public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse)
                throws IllegalStateException {
            AsyncContext startAsync = super.startAsync(servletRequest, servletResponse);
            return new SecurityContextAsyncContext(startAsync);
        }
View Full Code Here

     * @param request
     * @param response
     */
    @RequestMapping("/async")
    public void asynch(HttpServletRequest request, HttpServletResponse response) {
        final AsyncContext async = request.startAsync();
        async.start(new Runnable() {
            public void run() {
                Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
                try {
                    final HttpServletResponse asyncResponse = (HttpServletResponse) async.getResponse();
                    asyncResponse.setStatus(HttpServletResponse.SC_OK);
                    asyncResponse.getWriter().write(String.valueOf(authentication));
                    async.complete();
                } catch(Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });
View Full Code Here

        ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        context.setAuthentication(expectedAuth);
        SecurityContextHolder.setContext(context);
        AsyncContext asyncContext = mock(AsyncContext.class);
        when(request.getAsyncContext()).thenReturn(asyncContext);
        Runnable runnable = new Runnable() {
            public void run() {}
        };
View Full Code Here

        ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        context.setAuthentication(expectedAuth);
        SecurityContextHolder.setContext(context);
        AsyncContext asyncContext = mock(AsyncContext.class);
        when(request.startAsync()).thenReturn(asyncContext);
        Runnable runnable = new Runnable() {
            public void run() {}
        };
View Full Code Here

        ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        context.setAuthentication(expectedAuth);
        SecurityContextHolder.setContext(context);
        AsyncContext asyncContext = mock(AsyncContext.class);
        when(request.startAsync(request,response)).thenReturn(asyncContext);
        Runnable runnable = new Runnable() {
            public void run() {}
        };
View Full Code Here

        out.println("</p>");
        out.println("<br><br>");

        out.flush();

        AsyncContext ctx =req.startAsync();
        new Thread(new TaskExecutor(ctx)).start();

        out.println("<p id='b'>");
        out.println("Task assigned to executor.Servlet finishes at: " + "<font color='red'>" + new Date() + " -> <b id='sft'>" + System.currentTimeMillis() + "</b></font>" + ".");
        out.println("</p>");
View Full Code Here

        PrintWriter out = resp.getWriter();
        out.write("hello async");
        out.write("<br/>");
        out.flush();
        //1、开启异步
        final AsyncContext asyncContext = req.startAsync();
        //2、设置超时时间,如果不设置如jetty是30000L
        asyncContext.setTimeout(10L * 1000); //设置为0表示永不超时

        //把任务提交给自己的任务队列
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3L * 1000);
                    PrintWriter out = asyncContext.getResponse().getWriter();
                    out.write("over");
                    asyncContext.complete();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
View Full Code Here

TOP

Related Classes of javax.servlet.AsyncContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.