View | Details | Raw Unified | Return to bug 59219
Collapse All | Expand All

(-)test/org/apache/catalina/core/TestAsyncContextImpl.java (-1 / +63 lines)
Lines 1820-1826 Link Here
1820
            // NO-OP
1820
            // NO-OP
1821
        }
1821
        }
1822
    }
1822
    }
1823
    
1824
    @Test
1825
    public void testBug59219() throws Exception{
1826
        resetTracker();
1827
        Tomcat tomcat = getTomcatInstance();
1828
        
1829
        Context ctx = tomcat.addContext("", null);
1830
        tomcat.addServlet("", "async", new Bug59219Servlet())
1831
                .setAsyncSupported(true);
1832
        ctx.addServletMapping("/async", "async");
1833
        
1834
        tomcat.start();
1835
        
1836
        getUrl("http://localhost:" + getPort() + "/async");
1837
        String expected = "container has processed me, he is honest :')";
1838
        
1839
        //Just let's give it 5 seconds :)
1840
        int count = 0;
1841
        while(!expected.equals(getTrack()) || count < 100)
1842
            Thread.sleep(50);
1843
        
1844
        Assert.assertEquals(expected, getTrack());
1845
    }
1846
    
1847
    private static class Bug59219Servlet extends HttpServlet {
1823
1848
1849
        @Override
1850
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
1851
                throws ServletException, IOException {
1852
            
1853
           resp.setContentType("text/plain");
1854
           AsyncContext ctx = req.startAsync();
1855
           ctx.addListener(new Bug59219Listener());
1856
           
1857
           throw new ServletException("container be nice and process onError.");
1858
        }
1859
        
1860
    }
1861
    
1862
    private static class Bug59219Listener implements AsyncListener {
1863
1864
        @Override
1865
        public void onComplete(AsyncEvent ae) throws IOException {
1866
            // Nothing.
1867
        }
1868
1869
        @Override
1870
        public void onTimeout(AsyncEvent ae) throws IOException {
1871
            // Nothing.
1872
        }
1873
1874
        @Override
1875
        public void onError(AsyncEvent ae) throws IOException {
1876
            ae.getAsyncContext().getResponse().getWriter()
1877
                    .write("container has processed me, he is honest :')");
1878
        }
1879
1880
        @Override
1881
        public void onStartAsync(AsyncEvent ae) throws IOException {
1882
            // Nothing.
1883
        }
1884
    }
1885
1824
    @Test
1886
    @Test
1825
    public void testForbiddenDispatching() throws Exception {
1887
    public void testForbiddenDispatching() throws Exception {
1826
        resetTracker();
1888
        resetTracker();
1827
native
1889
LF

Return to bug 59219