本文整理汇总了Java中org.apache.catalina.Context.addServletContainerInitializer方法的典型用法代码示例。如果您正苦于以下问题:Java Context.addServletContainerInitializer方法的具体用法?Java Context.addServletContainerInitializer怎么用?Java Context.addServletContainerInitializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.catalina.Context
的用法示例。
在下文中一共展示了Context.addServletContainerInitializer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTestBug51376
import org.apache.catalina.Context; //导入方法依赖的package包/类
private void doTestBug51376(boolean loadOnStartUp) throws Exception {
// Test that for a servlet that was added programmatically its
// loadOnStartup property is honored and its init() and destroy()
// methods are called.
// Set up a container
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
// Add ServletContainerInitializer
Bug51376SCI sci = new Bug51376SCI(loadOnStartUp);
ctx.addServletContainerInitializer(sci, null);
// Start the context
tomcat.start();
// Stop the context
ctx.stop();
// Make sure that init() and destroy() were called correctly
assertTrue(sci.getServlet().isOk());
assertTrue(loadOnStartUp == sci.getServlet().isInitCalled());
}
示例2: testServletContainerInitializer
import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
* Check that a ServletContainerInitializer can install a
* {@link ServletContextListener} and that it gets initialized.
* @throws Exception
*/
@Test
public void testServletContainerInitializer() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context context = tomcat.addContext("", null);
context.addServletContainerInitializer(new SCI(), null);
tomcat.start();
assertTrue(SCL.initialized);
}
示例3: testBug50015
import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testBug50015() throws Exception {
// Test that configuring servlet security constraints programmatically
// does work.
// Set up a container
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
// Setup realm
MapRealm realm = new MapRealm();
realm.addUser("tomcat", "tomcat");
realm.addUserRole("tomcat", "tomcat");
ctx.setRealm(realm);
// Configure app for BASIC auth
LoginConfig lc = new LoginConfig();
lc.setAuthMethod("BASIC");
ctx.setLoginConfig(lc);
ctx.getPipeline().addValve(new BasicAuthenticator());
// Add ServletContainerInitializer
ServletContainerInitializer sci = new Bug50015SCI();
ctx.addServletContainerInitializer(sci, null);
// Start the context
tomcat.start();
// Request the first servlet
ByteChunk bc = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/bug50015",
bc, null);
// Check for a 401
assertNotSame("OK", bc.toString());
assertEquals(401, rc);
}
示例4: doTestSecurityAnnotationsAddServlet
import org.apache.catalina.Context; //导入方法依赖的package包/类
private void doTestSecurityAnnotationsAddServlet(boolean useCreateServlet)
throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Servlet s = new DenyAllServlet();
ServletContainerInitializer sci = new SCI(s, useCreateServlet);
ctx.addServletContainerInitializer(sci, null);
tomcat.start();
ByteChunk bc = new ByteChunk();
int rc;
rc = getUrl("http://localhost:" + getPort() + "/", bc, null, null);
if (useCreateServlet) {
assertTrue(bc.getLength() > 0);
assertEquals(403, rc);
} else {
assertEquals("OK", bc.toString());
assertEquals(200, rc);
}
}