本文整理匯總了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);
}
}