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


Java Context.setLoader方法代码示例

本文整理汇总了Java中org.apache.catalina.Context.setLoader方法的典型用法代码示例。如果您正苦于以下问题:Java Context.setLoader方法的具体用法?Java Context.setLoader怎么用?Java Context.setLoader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.catalina.Context的用法示例。


在下文中一共展示了Context.setLoader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testParallelCapableOnJre7

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testParallelCapableOnJre7() {
    if (!JreCompat.isJre7Available()) {
        // ignore on Jre6 or lower
        return;
    }
    try {
        Tomcat tomcat = getTomcatInstance();
        Context ctx = tomcat.addContext("", null);

        WebappLoader webappLoader = new WebappLoader();
        webappLoader.setLoaderClass(PARALLEL_CLASSLOADER);
        ctx.setLoader(webappLoader);

        tomcat.start();

        ClassLoader classloader = ctx.getLoader().getClassLoader();

        Assert.assertTrue(classloader instanceof ParallelWebappClassLoader);

        // parallel class loading capable
        Method getClassLoadingLock =
                getDeclaredMethod(classloader.getClass(), "getClassLoadingLock", String.class);
        // make sure we have getClassLoadingLock on JRE7.
        Assert.assertNotNull(getClassLoadingLock);
        // give us permission to access protected method
        getClassLoadingLock.setAccessible(true);

        Object lock = getClassLoadingLock.invoke(classloader, DUMMY_SERVLET);
        // make sure it is not a ParallelWebappClassLoader object lock
        Assert.assertNotEquals(lock, classloader);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("testParallelCapableOnJre7 fails.");
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:37,代码来源:TestParallelWebappClassLoader.java

示例2: testParallelIncapableOnJre6

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testParallelIncapableOnJre6() {
    if (JreCompat.isJre7Available()) {
        // ignore on Jre7 or above
        return;
    }
    try {
        Tomcat tomcat = getTomcatInstance();
        // Must have a real docBase - just use temp
        Context ctx = tomcat.addContext("",
                System.getProperty("java.io.tmpdir"));

        WebappLoader webappLoader = new WebappLoader();
        webappLoader.setLoaderClass(PARALLEL_CLASSLOADER);
        ctx.setLoader(webappLoader);

        tomcat.start();

        ClassLoader classloader = ctx.getLoader().getClassLoader();

        Assert.assertTrue(classloader instanceof ParallelWebappClassLoader);

        // parallel class loading capable
        Method getClassLoadingLock =
                getDeclaredMethod(classloader.getClass(), "getClassLoadingLock", String.class);
        // make sure we don't have getClassLoadingLock on JRE6.
        Assert.assertNull(getClassLoadingLock);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("testParallelIncapableOnJre6 fails.");
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:33,代码来源:TestParallelWebappClassLoader.java

示例3: testWebappLoaderStartFail

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testWebappLoaderStartFail() throws Exception {
    // Test that if WebappLoader start() fails and if the cause of
    // the failure is gone, the context can be started without
    // a need to redeploy it.

    // Set up a container
    Tomcat tomcat = getTomcatInstance();
    tomcat.start();
    // To not start Context automatically, as we have to configure it first
    ((ContainerBase) tomcat.getHost()).setStartChildren(false);

    FailingWebappLoader loader = new FailingWebappLoader();
    File root = new File("test/webapp-3.0");
    Context context = tomcat.addWebapp("", root.getAbsolutePath());
    context.setLoader(loader);

    try {
        context.start();
        fail();
    } catch (LifecycleException ex) {
        // As expected
    }
    assertEquals(LifecycleState.FAILED, context.getState());

    // The second attempt
    loader.setFail(false);
    context.start();
    assertEquals(LifecycleState.STARTED, context.getState());

    // Using a test from testBug49922() to check that the webapp is running
    ByteChunk result = getUrl("http://localhost:" + getPort() +
            "/bug49922/target");
    assertEquals("Target", result.toString());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:36,代码来源:TestStandardContext.java


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