Lines 1822-1827
Link Here
|
1822 |
} |
1822 |
} |
1823 |
|
1823 |
|
1824 |
@Test |
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 |
tomcat.addServlet("", "async", new Bug59219Servlet()) |
1832 |
.setAsyncSupported(true); |
1833 |
ctx.addServletMapping("/async", "async"); |
1834 |
|
1835 |
tomcat.start(); |
1836 |
|
1837 |
//Point 2. |
1838 |
ByteChunk body = getUrl("http://localhost:" + getPort() + "/async"); |
1839 |
String expected = "doGet-onError"; |
1840 |
|
1841 |
//Just let's give it 5 seconds :) |
1842 |
int count = 0; |
1843 |
while(!expected.equals(body.toString()) || count < 100) { |
1844 |
Thread.sleep(50); |
1845 |
count++; |
1846 |
} |
1847 |
|
1848 |
Assert.assertEquals(expected, body.toString()); |
1849 |
|
1850 |
//Point 3. |
1851 |
body = getUrl("http://localhost:" + getPort() + "/async?loops=3"); |
1852 |
expected = "doGet-doGet-doGet-onError"; |
1853 |
|
1854 |
count = 0; |
1855 |
while(!expected.equals(body.toString()) || count < 100) { |
1856 |
Thread.sleep(50); |
1857 |
count++; |
1858 |
} |
1859 |
|
1860 |
Assert.assertEquals(expected, body.toString()); |
1861 |
} |
1862 |
|
1863 |
private static class Bug59219Servlet extends HttpServlet { |
1864 |
|
1865 |
@Override |
1866 |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) |
1867 |
throws ServletException, IOException { |
1868 |
|
1869 |
resp.setContentType("text/html"); |
1870 |
AsyncContext ctx = req.startAsync(); |
1871 |
ctx.addListener(new Bug59219Listener()); |
1872 |
resp.getWriter().write("doGet-"); |
1873 |
|
1874 |
String loop = req.getParameter("loop"); |
1875 |
Integer iloop = (Integer) req.getAttribute("iloop"); |
1876 |
|
1877 |
if (iloop == null) { |
1878 |
iloop = 0; |
1879 |
if (loop != null) |
1880 |
iloop = Integer.parseInt(loop); |
1881 |
} |
1882 |
|
1883 |
if (iloop > 0) { |
1884 |
iloop--; |
1885 |
req.setAttribute("iloop", iloop); |
1886 |
ctx.dispatch(); |
1887 |
} else |
1888 |
throw new ServletException("container be nice and process onError."); |
1889 |
} |
1890 |
|
1891 |
} |
1892 |
|
1893 |
private static class Bug59219Listener implements AsyncListener { |
1894 |
|
1895 |
@Override |
1896 |
public void onComplete(AsyncEvent ae) throws IOException { |
1897 |
// Nothing. |
1898 |
} |
1899 |
|
1900 |
@Override |
1901 |
public void onTimeout(AsyncEvent ae) throws IOException { |
1902 |
// Nothing. |
1903 |
} |
1904 |
|
1905 |
@Override |
1906 |
public void onError(AsyncEvent ae) throws IOException { |
1907 |
ae.getAsyncContext().getResponse().getWriter() |
1908 |
.write("onError"); |
1909 |
} |
1910 |
|
1911 |
@Override |
1912 |
public void onStartAsync(AsyncEvent ae) throws IOException { |
1913 |
// Nothing. |
1914 |
} |
1915 |
} |
1916 |
|
1917 |
@Test |
1825 |
public void testForbiddenDispatching() throws Exception { |
1918 |
public void testForbiddenDispatching() throws Exception { |
1826 |
resetTracker(); |
1919 |
resetTracker(); |
1827 |
// Setup Tomcat instance |
1920 |
// Setup Tomcat instance |