本文整理汇总了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.");
}
}
示例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.");
}
}
示例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());
}