use of org.apache.catalina.Context in project tomcat by apache.
the class TestCoyoteInputStream method testReadWithByteBuffer.
@Test
public void testReadWithByteBuffer() throws Exception {
Tomcat tomcat = getTomcatInstance();
Context root = tomcat.addContext("", TEMP_DIR);
Tomcat.addServlet(root, "testServlet", new TestServlet());
root.addServletMappingDecoded("/", "testServlet");
tomcat.start();
ByteChunk bc = new ByteChunk();
String requestBody = "HelloWorld";
int rc = postUrl(requestBody.getBytes(StandardCharsets.UTF_8), "http://localhost:" + getPort() + "/", bc, null);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
Assert.assertTrue(requestBody.equals(bc.toString()));
}
use of org.apache.catalina.Context in project tomcat by apache.
the class TestCoyoteOutputStream method testWriteWithByteBuffer.
@Test
public void testWriteWithByteBuffer() throws Exception {
Tomcat tomcat = getTomcatInstance();
Context root = tomcat.addContext("", TEMP_DIR);
Tomcat.addServlet(root, "testServlet", new TestServlet());
root.addServletMappingDecoded("/", "testServlet");
tomcat.start();
ByteChunk bc = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/", bc, null, null);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
File file = new File("test/org/apache/catalina/connector/test_content.txt");
try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
ByteChunk expected = new ByteChunk();
expected.append(raf.getChannel().map(MapMode.READ_ONLY, 0, file.length()));
Assert.assertTrue(expected.equals(bc));
}
}
use of org.apache.catalina.Context in project tomcat by apache.
the class TestCoyoteOutputStream method doNonBlockingTest.
private void doNonBlockingTest(int asyncWriteTarget, int syncWriteTarget, boolean useContainerThreadToSetListener) throws Exception {
Tomcat tomcat = getTomcatInstance();
Context root = tomcat.addContext("", TEMP_DIR);
Wrapper w = Tomcat.addServlet(root, "nbWrite", new NonBlockingWriteServlet(asyncWriteTarget, useContainerThreadToSetListener));
w.setAsyncSupported(true);
root.addServletMappingDecoded("/nbWrite", "nbWrite");
Tomcat.addServlet(root, "write", new BlockingWriteServlet(asyncWriteTarget, syncWriteTarget));
w.setAsyncSupported(true);
root.addServletMappingDecoded("/write", "write");
tomcat.start();
ByteChunk bc = new ByteChunk();
// Extend timeout to 5 mins for debugging
int rc = getUrl("http://localhost:" + getPort() + "/nbWrite", bc, 300000, null, null);
int totalCount = asyncWriteTarget + syncWriteTarget;
StringBuilder sb = new StringBuilder(totalCount * 16);
for (int i = 0; i < totalCount; i++) {
sb.append("OK - " + i + System.lineSeparator());
}
String expected = null;
if (sb.length() > 0) {
expected = sb.toString();
}
Assert.assertEquals(200, rc);
Assert.assertEquals(expected, bc.toString());
}
use of org.apache.catalina.Context in project tomcat by apache.
the class TestOutputBuffer method testBug52577.
@Test
public void testBug52577() throws Exception {
Tomcat tomcat = getTomcatInstance();
Context root = tomcat.addContext("", TEMP_DIR);
Bug52577Servlet bug52577 = new Bug52577Servlet();
Tomcat.addServlet(root, "bug52577", bug52577);
root.addServletMappingDecoded("/", "bug52577");
tomcat.start();
ByteChunk bc = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/", bc, null, null);
assertEquals(HttpServletResponse.SC_OK, rc);
assertEquals("OK", bc.toString());
}
use of org.apache.catalina.Context in project tomcat by apache.
the class TestRequest method testBug49424WithChunking.
@Test
public void testBug49424WithChunking() throws Exception {
Tomcat tomcat = getTomcatInstance();
Context root = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
Tomcat.addServlet(root, "Bug37794", new Bug37794Servlet());
root.addServletMappingDecoded("/", "Bug37794");
tomcat.start();
HttpURLConnection conn = getConnection("http://localhost:" + getPort() + "/");
conn.setChunkedStreamingMode(8 * 1024);
InputStream is = conn.getInputStream();
assertNotNull(is);
}
Aggregations