use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestTomcatClassLoader method testDefaultClassLoader.
@Test
public void testDefaultClassLoader() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "ClassLoaderReport", new ClassLoaderReport(null));
ctx.addServletMappingDecoded("/", "ClassLoaderReport");
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
assertEquals("WEBAPP,SYSTEM,OTHER,", res.toString());
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TomcatBaseTest method getUrl.
/*
* Wrapper for getting the response.
*/
public static ByteChunk getUrl(String path) throws IOException {
ByteChunk out = new ByteChunk();
getUrl(path, out, null);
return out;
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestDefaultServlet method testGetWithSubpathmount.
/*
* Test https://bz.apache.org/bugzilla/show_bug.cgi?id=50026
* Verify serving of resources from context root with subpath mapping.
*/
@Test
public void testGetWithSubpathmount() throws Exception {
Tomcat tomcat = getTomcatInstance();
String contextPath = "/examples";
File appDir = new File(getBuildDirectory(), "webapps" + contextPath);
// app dir is relative to server home
org.apache.catalina.Context ctx = tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
ctx.addApplicationListener(WsContextListener.class.getName());
// Override the default servlet with our own mappings
Tomcat.addServlet(ctx, "default2", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default2");
ctx.addServletMappingDecoded("/servlets/*", "default2");
ctx.addServletMappingDecoded("/static/*", "default2");
tomcat.start();
final ByteChunk res = new ByteChunk();
// Make sure DefaultServlet isn't exposing special directories
// by remounting the webapp under a sub-path
int rc = getUrl("http://localhost:" + getPort() + contextPath + "/static/WEB-INF/web.xml", res, null);
assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
rc = getUrl("http://localhost:" + getPort() + contextPath + "/static/WEB-INF/doesntexistanywhere", res, null);
assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
rc = getUrl("http://localhost:" + getPort() + contextPath + "/static/WEB-INF/", res, null);
assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
rc = getUrl("http://localhost:" + getPort() + contextPath + "/static/META-INF/MANIFEST.MF", res, null);
assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
rc = getUrl("http://localhost:" + getPort() + contextPath + "/static/META-INF/doesntexistanywhere", res, null);
assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
// Make sure DefaultServlet is serving resources relative to the
// context root regardless of where the it is mapped
final ByteChunk rootResource = new ByteChunk();
rc = getUrl("http://localhost:" + getPort() + contextPath + "/index.html", rootResource, null);
assertEquals(HttpServletResponse.SC_OK, rc);
final ByteChunk subpathResource = new ByteChunk();
rc = getUrl("http://localhost:" + getPort() + contextPath + "/servlets/index.html", subpathResource, null);
assertEquals(HttpServletResponse.SC_OK, rc);
assertFalse(rootResource.toString().equals(subpathResource.toString()));
rc = getUrl("http://localhost:" + getPort() + contextPath + "/static/index.html", res, null);
assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestTomcat method testSingleWebapp.
@Test
public void testSingleWebapp() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File(getBuildDirectory(), "webapps/examples");
// app dir is relative to server home
Context ctxt = tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
ctxt.addApplicationListener(WsContextListener.class.getName());
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/examples/servlets/servlet/HelloWorldExample");
String text = res.toString();
assertTrue(text, text.indexOf("<a href=\"../helloworld.html\">") > 0);
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestTomcat method testEnableNamingGlobal.
/*
* Test for enabling JNDI and using global resources.
*/
@Test
public void testEnableNamingGlobal() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
// Enable JNDI - it is disabled by default
tomcat.enableNaming();
ContextEnvironment environment = new ContextEnvironment();
environment.setType("java.lang.String");
environment.setName("globalTest");
environment.setValue("Tomcat User");
tomcat.getServer().getGlobalNamingResources().addEnvironment(environment);
ContextResourceLink link = new ContextResourceLink();
link.setGlobal("globalTest");
link.setName(HelloWorldJndi.JNDI_ENV_NAME);
link.setType("java.lang.String");
ctx.getNamingResources().addResourceLink(link);
Tomcat.addServlet(ctx, "jndiServlet", new HelloWorldJndi());
ctx.addServletMappingDecoded("/", "jndiServlet");
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
assertEquals("Hello, Tomcat User", res.toString());
}
Aggregations