use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestNonLoginAndBasicAuthenticator method doTestNonLogin.
private void doTestNonLogin(String uri, boolean useCookie, int expectedRC) throws Exception {
Map<String, List<String>> reqHeaders = new HashMap<>();
Map<String, List<String>> respHeaders = new HashMap<>();
if (useCookie) {
addCookies(reqHeaders);
}
ByteChunk bc = new ByteChunk();
int rc = getUrl(HTTP_PREFIX + getPort() + uri, bc, reqHeaders, respHeaders);
if (expectedRC != HttpServletResponse.SC_OK) {
assertEquals(expectedRC, rc);
assertTrue(bc.getLength() > 0);
} else {
assertEquals("OK", bc.toString());
}
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestAsyncContextImpl method testCommitOnComplete.
@Test
public void testCommitOnComplete() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncStatusServlet asyncStatusServlet = new AsyncStatusServlet(HttpServletResponse.SC_BAD_REQUEST);
Wrapper wrapper = Tomcat.addServlet(ctx, "asyncStatusServlet", asyncStatusServlet);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/asyncStatusServlet", "asyncStatusServlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/asyncStatusServlet");
int rc = getUrl(url.toString(), new ByteChunk(), null);
assertEquals(HttpServletResponse.SC_BAD_REQUEST, rc);
// Without this test may complete before access log has a chance to log
// the request
Thread.sleep(REQUEST_TIME);
// Check the access log
alv.validateAccessLog(1, HttpServletResponse.SC_BAD_REQUEST, 0, REQUEST_TIME);
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestAsyncContextImpl method doTestTimeoutErrorDispatch.
private void doTestTimeoutErrorDispatch(Boolean asyncError, ErrorPageAsyncMode mode) throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
TimeoutServlet timeout = new TimeoutServlet(null, null);
Wrapper w1 = Tomcat.addServlet(ctx, "time", timeout);
w1.setAsyncSupported(true);
ctx.addServletMappingDecoded("/async", "time");
NonAsyncServlet nonAsync = new NonAsyncServlet();
Wrapper w2 = Tomcat.addServlet(ctx, "nonAsync", nonAsync);
w2.setAsyncSupported(true);
ctx.addServletMappingDecoded("/error/nonasync", "nonAsync");
AsyncErrorPage asyncErrorPage = new AsyncErrorPage(mode);
Wrapper w3 = Tomcat.addServlet(ctx, "asyncErrorPage", asyncErrorPage);
w3.setAsyncSupported(true);
ctx.addServletMappingDecoded("/error/async", "asyncErrorPage");
if (asyncError != null) {
ErrorPage ep = new ErrorPage();
ep.setErrorCode(500);
if (asyncError.booleanValue()) {
ep.setLocation("/error/async");
} else {
ep.setLocation("/error/nonasync");
}
ctx.addErrorPage(ep);
}
ctx.addApplicationListener(TrackingRequestListener.class.getName());
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
TesterAccessLogValve alvGlobal = new TesterAccessLogValve();
tomcat.getHost().getPipeline().addValve(alvGlobal);
tomcat.start();
ByteChunk res = new ByteChunk();
try {
getUrl("http://localhost:" + getPort() + "/async", res, null);
} catch (IOException ioe) {
// Ignore - expected for some error conditions
}
StringBuilder expected = new StringBuilder();
expected.append("requestInitialized-TimeoutServletGet-");
if (asyncError != null) {
if (asyncError.booleanValue()) {
expected.append("AsyncErrorPageGet-");
if (mode == ErrorPageAsyncMode.NO_COMPLETE) {
expected.append("NoOp-");
} else if (mode == ErrorPageAsyncMode.COMPLETE) {
expected.append("Complete-");
} else if (mode == ErrorPageAsyncMode.DISPATCH) {
expected.append("Dispatch-NonAsyncServletGet-");
}
} else {
expected.append("NonAsyncServletGet-");
}
}
expected.append("requestDestroyed");
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
String expectedTrack = expected.toString();
int count = 0;
while (!expectedTrack.equals(getTrack()) && count < 100) {
Thread.sleep(50);
count++;
}
Assert.assertEquals(expectedTrack, getTrack());
// Check the access log
alvGlobal.validateAccessLog(1, 500, TimeoutServlet.ASYNC_TIMEOUT, TimeoutServlet.ASYNC_TIMEOUT + TIMEOUT_MARGIN + REQUEST_TIME);
alv.validateAccessLog(1, 500, TimeoutServlet.ASYNC_TIMEOUT, TimeoutServlet.ASYNC_TIMEOUT + TIMEOUT_MARGIN + REQUEST_TIME);
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestAsyncContextImpl method doTestAsyncRequestURI.
private void doTestAsyncRequestURI(String uri) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Servlet servlet = new AsyncRequestUriServlet();
Wrapper wrapper1 = Tomcat.addServlet(ctx, "bug57559", servlet);
wrapper1.setAsyncSupported(true);
ctx.addServletMappingDecoded("/", "bug57559");
tomcat.start();
ByteChunk body = getUrl("http://localhost:" + getPort() + uri);
Assert.assertEquals(uri, body.toString());
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestAsyncContextImpl method testBug53843.
@Test
public void testBug53843() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Bug53843ServletA servletA = new Bug53843ServletA();
Wrapper a = Tomcat.addServlet(ctx, "ServletA", servletA);
a.setAsyncSupported(true);
Tomcat.addServlet(ctx, "ServletB", new Bug53843ServletB());
ctx.addServletMappingDecoded("/ServletA", "ServletA");
ctx.addServletMappingDecoded("/ServletB", "ServletB");
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/ServletA");
ByteChunk body = new ByteChunk();
int rc = getUrl(url.toString(), body, null);
assertEquals(HttpServletResponse.SC_OK, rc);
assertEquals("OK", body.toString());
assertTrue(servletA.isAsyncWhenExpected());
}
Aggregations