use of org.apache.tomcat.util.collections.CaseInsensitiveKeyMap in project tomcat by apache.
the class TestAsyncContextImpl method testBug50753.
@Test
public void testBug50753() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Bug50753Servlet servlet = new Bug50753Servlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "servlet", servlet);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/", "servlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
// Call the servlet once
Map<String, List<String>> headers = new CaseInsensitiveKeyMap<>();
ByteChunk bc = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/", bc, headers);
Assert.assertEquals(200, rc);
Assert.assertEquals("OK", bc.toString());
String testHeader = getSingleHeader("A", headers);
Assert.assertEquals("xyz", testHeader);
// Check the access log
alv.validateAccessLog(1, 200, Bug50753Servlet.THREAD_SLEEP_TIME, Bug50753Servlet.THREAD_SLEEP_TIME + REQUEST_TIME);
}
use of org.apache.tomcat.util.collections.CaseInsensitiveKeyMap in project tomcat by apache.
the class TestAsyncContextImpl method testAsyncStartWithComplete.
@Test
public void testAsyncStartWithComplete() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncStartWithCompleteServlet servlet = new AsyncStartWithCompleteServlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "servlet", servlet);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/", "servlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
// Call the servlet once
ByteChunk bc = new ByteChunk();
Map<String, List<String>> headers = new CaseInsensitiveKeyMap<>();
getUrl("http://localhost:" + getPort() + "/", bc, headers);
Assert.assertEquals("OK", bc.toString());
String contentLength = getSingleHeader("Content-Length", headers);
Assert.assertEquals("2", contentLength);
// Check the access log
alv.validateAccessLog(1, 200, 0, REQUEST_TIME);
}
use of org.apache.tomcat.util.collections.CaseInsensitiveKeyMap in project tomcat by apache.
the class TestExpiresFilter method testBug63909.
/*
* Tests Expires filter with:
* - per content type expires
* - no default
* - Default servlet returning 304s (without content-type)
*/
@Test
public void testBug63909() throws Exception {
Tomcat tomcat = getTomcatInstanceTestWebapp(false, false);
Context ctxt = (Context) tomcat.getHost().findChild("/test");
FilterDef filterDef = new FilterDef();
filterDef.addInitParameter("ExpiresByType text/xml;charset=utf-8", "access plus 3 minutes");
filterDef.addInitParameter("ExpiresByType text/xml", "access plus 5 minutes");
filterDef.addInitParameter("ExpiresByType text", "access plus 7 minutes");
filterDef.addInitParameter("ExpiresExcludedResponseStatusCodes", "");
filterDef.setFilterClass(ExpiresFilter.class.getName());
filterDef.setFilterName(ExpiresFilter.class.getName());
ctxt.addFilterDef(filterDef);
FilterMap filterMap = new FilterMap();
filterMap.setFilterName(ExpiresFilter.class.getName());
filterMap.addURLPatternDecoded("*");
ctxt.addFilterMap(filterMap);
tomcat.start();
ByteChunk bc = new ByteChunk();
Map<String, List<String>> requestHeaders = new CaseInsensitiveKeyMap<>();
List<String> ifModifiedSinceValues = new ArrayList<>();
ifModifiedSinceValues.add(FastHttpDateFormat.getCurrentDate());
requestHeaders.put("If-Modified-Since", ifModifiedSinceValues);
Map<String, List<String>> responseHeaders = new CaseInsensitiveKeyMap<>();
int rc = getUrl("http://localhost:" + getPort() + "/test/bug6nnnn/bug69303.txt", bc, requestHeaders, responseHeaders);
Assert.assertEquals(HttpServletResponse.SC_NOT_MODIFIED, rc);
StringBuilder msg = new StringBuilder();
for (Entry<String, List<String>> field : responseHeaders.entrySet()) {
for (String value : field.getValue()) {
msg.append((field.getKey() == null ? "" : field.getKey() + ": ") + value + "\n");
}
}
System.out.println(msg);
Integer actualMaxAgeInSeconds;
String cacheControlHeader = getSingleHeader("Cache-Control", responseHeaders);
if (cacheControlHeader == null) {
actualMaxAgeInSeconds = null;
} else {
actualMaxAgeInSeconds = null;
StringTokenizer cacheControlTokenizer = new StringTokenizer(cacheControlHeader, ",");
while (cacheControlTokenizer.hasMoreTokens() && actualMaxAgeInSeconds == null) {
String cacheDirective = cacheControlTokenizer.nextToken();
StringTokenizer cacheDirectiveTokenizer = new StringTokenizer(cacheDirective, "=");
if (cacheDirectiveTokenizer.countTokens() == 2) {
String key = cacheDirectiveTokenizer.nextToken().trim();
String value = cacheDirectiveTokenizer.nextToken().trim();
if (key.equalsIgnoreCase("max-age")) {
actualMaxAgeInSeconds = Integer.valueOf(value);
}
}
}
}
Assert.assertNotNull(actualMaxAgeInSeconds);
Assert.assertTrue(Math.abs(actualMaxAgeInSeconds.intValue() - 420) < 3);
}
Aggregations