当前位置: 首页>>代码示例>>Java>>正文


Java Context.addServletContainerInitializer方法代码示例

本文整理汇总了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());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:26,代码来源:TestStandardContext.java

示例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);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:17,代码来源:TestListener.java

示例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);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:40,代码来源:TestStandardContext.java

示例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);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:28,代码来源:TestStandardWrapper.java


注:本文中的org.apache.catalina.Context.addServletContainerInitializer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。