本文整理汇总了Java中org.apache.catalina.core.StandardContext.addServletMapping方法的典型用法代码示例。如果您正苦于以下问题:Java StandardContext.addServletMapping方法的具体用法?Java StandardContext.addServletMapping怎么用?Java StandardContext.addServletMapping使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.catalina.core.StandardContext
的用法示例。
在下文中一共展示了StandardContext.addServletMapping方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateSessionAndPassivate
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
@Test
public void testCreateSessionAndPassivate() throws IOException, LifecycleException, ClassNotFoundException {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
ctx.setDistributable(true);
Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet());
ctx.addServletMapping("/dummy", "DummyServlet");
PersistentManager manager = new PersistentManager();
TesterStore store = new TesterStore();
manager.setStore(store);
manager.setMaxIdleBackup(0);
ctx.setManager(manager);
ctx.addValve(new PersistentValve());
tomcat.start();
Assert.assertEquals("No active sessions", manager.getActiveSessions(), 0);
Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
String sessionId = getUrl(
"http://localhost:" + getPort()
+ "/dummy?no_create_session=false").toString();
Assert.assertNotNull("Session is stored", store.load(sessionId));
Assert.assertEquals("All sessions are passivated", manager.getActiveSessions(), 0);
Assert.assertTrue("One session was created", !manager.getSessionIdsFull().isEmpty());
}
示例2: testListBindings
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
@Test
public void testListBindings() throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.enableNaming();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
// Create the resource
ContextResource cr = new ContextResource();
cr.setName("list/foo");
cr.setType("org.apache.naming.resources.TesterObject");
cr.setProperty("factory", "org.apache.naming.resources.TesterFactory");
ctx.getNamingResources().addResource(cr);
// Map the test Servlet
Bug23950Servlet bug23950Servlet = new Bug23950Servlet();
Tomcat.addServlet(ctx, "bug23950Servlet", bug23950Servlet);
ctx.addServletMapping("/", "bug23950Servlet");
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
assertEquals("org.apache.naming.resources.TesterObject", bc.toString());
}
示例3: testBeanFactory
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
@Test
public void testBeanFactory() throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.enableNaming();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
// Create the resource
ContextResource cr = new ContextResource();
cr.setName("bug50351");
cr.setType("org.apache.naming.resources.TesterObject");
cr.setProperty("factory", "org.apache.naming.factory.BeanFactory");
cr.setProperty("foo", "value");
ctx.getNamingResources().addResource(cr);
// Map the test Servlet
Bug50351Servlet bug50351Servlet = new Bug50351Servlet();
Tomcat.addServlet(ctx, "bug50351Servlet", bug50351Servlet);
ctx.addServletMapping("/", "bug50351Servlet");
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
assertEquals("value", bc.toString());
}
示例4: doTestBug51744
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
private void doTestBug51744(boolean exceptionOnFailedWrite)
throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.enableNaming();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
ctx.setJndiExceptionOnFailedWrite(exceptionOnFailedWrite);
// Map the test Servlet
Bug51744Servlet bug51744Servlet = new Bug51744Servlet();
Tomcat.addServlet(ctx, "bug51744Servlet", bug51744Servlet);
ctx.addServletMapping("/", "bug51744Servlet");
tomcat.start();
ByteChunk bc = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/", bc, null);
assertEquals(200, rc);
assertTrue(bc.toString().contains(Bug51744Servlet.EXPECTED));
if (exceptionOnFailedWrite) {
assertTrue(bc.toString().contains(Bug51744Servlet.ERROR_MESSAGE));
}
}
示例5: testBug53454
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
@Test
public void testBug53454() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
StandardContext ctx = (StandardContext)
tomcat.addContext("", null);
// Map the test Servlet
LargeBodyServlet largeBodyServlet = new LargeBodyServlet();
Tomcat.addServlet(ctx, "largeBodyServlet", largeBodyServlet);
ctx.addServletMapping("/", "largeBodyServlet");
tomcat.start();
Map<String,List<String>> resHeaders=
new HashMap<String, List<String>>();
int rc = headUrl("http://localhost:" + getPort() + "/", new ByteChunk(),
resHeaders);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
Assert.assertEquals(LargeBodyServlet.RESPONSE_LENGTH,
resHeaders.get("Content-Length").get(0));
}
示例6: noSessionCreate_57637
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
@Test
public void noSessionCreate_57637() throws IOException, LifecycleException {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
ctx.setDistributable(true);
Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet());
ctx.addServletMapping("/dummy", "DummyServlet");
PersistentManager manager = new PersistentManager();
TesterStore store = new TesterStore();
manager.setStore(store);
manager.setMaxIdleBackup(0);
ctx.setManager(manager);
ctx.addValve(new PersistentValve());
tomcat.start();
Assert.assertEquals(manager.getActiveSessions(), 0);
Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
Assert.assertEquals(
"NO_SESSION",
getUrl(
"http://localhost:" + getPort()
+ "/dummy?no_create_session=true").toString());
Assert.assertEquals(manager.getActiveSessions(), 0);
Assert.assertTrue("No sessions where created", manager.getSessionIdsFull().isEmpty());
}
示例7: doTestLookup
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
public void doTestLookup(boolean useSingletonResource) throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.enableNaming();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
// Create the resource
ContextResource cr = new ContextResource();
cr.setName("list/foo");
cr.setType("org.apache.naming.resources.TesterObject");
cr.setProperty("factory", "org.apache.naming.resources.TesterFactory");
cr.setSingleton(useSingletonResource);
ctx.getNamingResources().addResource(cr);
// Map the test Servlet
Bug49994Servlet bug49994Servlet = new Bug49994Servlet();
Tomcat.addServlet(ctx, "bug49994Servlet", bug49994Servlet);
ctx.addServletMapping("/", "bug49994Servlet");
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
String expected;
if (useSingletonResource) {
expected = "EQUAL";
} else {
expected = "NOTEQUAL";
}
assertEquals(expected, bc.toString());
}
示例8: testBug52830
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
@Test
public void testBug52830() throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.enableNaming();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
// Create the resource
ContextEnvironment env = new ContextEnvironment();
env.setName("boolean");
env.setType(Boolean.class.getName());
env.setValue("true");
ctx.getNamingResources().addEnvironment(env);
// Map the test Servlet
Bug52830Servlet bug52830Servlet = new Bug52830Servlet();
Tomcat.addServlet(ctx, "bug52830Servlet", bug52830Servlet);
ctx.addServletMapping("/", "bug52830Servlet");
tomcat.start();
ByteChunk bc = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/", bc, null);
assertEquals(200, rc);
assertTrue(bc.toString().contains("truetrue"));
}
示例9: testBug57602
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
/**
* Verifies that the same Content-Length is returned for both GET and HEAD
* operations when a Servlet includes content from another Servlet
*/
@Test
public void testBug57602() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
Bug57602ServletOuter outer = new Bug57602ServletOuter();
Tomcat.addServlet(ctx, "Bug57602ServletOuter", outer);
ctx.addServletMapping("/outer", "Bug57602ServletOuter");
Bug57602ServletInner inner = new Bug57602ServletInner();
Tomcat.addServlet(ctx, "Bug57602ServletInner", inner);
ctx.addServletMapping("/inner", "Bug57602ServletInner");
tomcat.start();
Map<String,List<String>> resHeaders= new HashMap<String,List<String>>();
String path = "http://localhost:" + getPort() + "/outer";
ByteChunk out = new ByteChunk();
int rc = getUrl(path, out, resHeaders);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
String length = resHeaders.get("Content-Length").get(0);
Assert.assertEquals(Long.parseLong(length), out.getLength());
out.recycle();
rc = headUrl(path, out, resHeaders);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
Assert.assertEquals(0, out.getLength());
Assert.assertEquals(length, resHeaders.get("Content-Length").get(0));
tomcat.stop();
}
示例10: initWebappDefaults
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
/** Init default servlets for the context. This should be the programmatic
* equivalent of the default web.xml.
*
* TODO: in normal tomcat, if default-web.xml is not found, use this
* method
*/
protected void initWebappDefaults(StandardContext ctx) {
// Default servlet
StandardWrapper servlet =
addServlet(ctx, "default",
//new DefaultServlet());
// Or:
"org.apache.catalina.servlets.DefaultServlet");
servlet.addInitParameter("listings", "false");
servlet.setLoadOnStartup(1);
// class name - to avoid loading all deps
servlet = addServlet(ctx, "jsp",
"org.apache.jasper.servlet.JspServlet");
servlet.addInitParameter("fork", "false");
servlet.addInitParameter("xpoweredBy", "false");
// in default web.xml - but not here, only needed if you have
// jsps.
//servlet.setLoadOnStartup(3);
ctx.addServletMapping("/", "default");
ctx.addServletMapping("*.jsp", "jsp");
ctx.addServletMapping("*.jspx", "jsp");
// Sessions
ctx.setManager( new StandardManager());
ctx.setSessionTimeout(30);
// TODO: read mime from /etc/mime.types on linux, or some
// resource
for (int i = 0; i < DEFAULT_MIME_MAPPINGS.length; ) {
ctx.addMimeMapping(DEFAULT_MIME_MAPPINGS[i++],
DEFAULT_MIME_MAPPINGS[i++]);
}
ctx.addWelcomeFile("index.html");
ctx.addWelcomeFile("index.htm");
ctx.addWelcomeFile("index.jsp");
ctx.setLoginConfig( new LoginConfig("NONE", null, null, null));
// TODO: set a default realm, add simple API to add users
}