Search in sources :

Example 1 with BytesStreamer

use of org.apache.catalina.startup.BytesStreamer in project tomcat by apache.

the class TestNonBlockingAPI method testBug55438NonBlockingReadWriteEmptyRead.

@Test
public void testBug55438NonBlockingReadWriteEmptyRead() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    NBReadWriteServlet servlet = new NBReadWriteServlet();
    String servletName = NBReadWriteServlet.class.getName();
    Tomcat.addServlet(ctx, servletName, servlet);
    ctx.addServletMappingDecoded("/", servletName);
    tomcat.start();
    Map<String, List<String>> resHeaders = new HashMap<>();
    int rc = postUrl(false, new BytesStreamer() {

        @Override
        public byte[] next() {
            return new byte[] {};
        }

        @Override
        public int getLength() {
            return 0;
        }

        @Override
        public int available() {
            return 0;
        }
    }, "http://localhost:" + getPort() + "/", new ByteChunk(), resHeaders, null);
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
}
Also used : AsyncContext(javax.servlet.AsyncContext) Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) Tomcat(org.apache.catalina.startup.Tomcat) HashMap(java.util.HashMap) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) BytesStreamer(org.apache.catalina.startup.BytesStreamer) ArrayList(java.util.ArrayList) List(java.util.List) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AsyncContext (javax.servlet.AsyncContext)1 Context (org.apache.catalina.Context)1 StandardContext (org.apache.catalina.core.StandardContext)1 BytesStreamer (org.apache.catalina.startup.BytesStreamer)1 Tomcat (org.apache.catalina.startup.Tomcat)1 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)1 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)1 Test (org.junit.Test)1