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