本文整理汇总了Java中org.apache.catalina.core.StandardContext.setLoader方法的典型用法代码示例。如果您正苦于以下问题:Java StandardContext.setLoader方法的具体用法?Java StandardContext.setLoader怎么用?Java StandardContext.setLoader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.catalina.core.StandardContext
的用法示例。
在下文中一共展示了StandardContext.setLoader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStartInternal
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
@Test
public void testStartInternal() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0");
// Must have a real docBase - just use temp
StandardContext ctx =
(StandardContext)tomcat.addContext("", appDir.getAbsolutePath());
VirtualWebappLoader loader = new VirtualWebappLoader();
loader.setContainer(ctx);
ctx.setLoader(loader);
ctx.setResources(new FileDirContext());
ctx.resourcesStart();
File dir = new File("test/webapp-3.0-fragments/WEB-INF/lib");
loader.setVirtualClasspath(dir.getAbsolutePath() + "/*.jar");
loader.start();
String[] repos = loader.getRepositories();
assertEquals(2,repos.length);
loader.stop();
// ToDo: Why doesn't remove repositories?
repos = loader.getRepositories();
assertEquals(2, repos.length);
// no leak
loader.start();
repos = loader.getRepositories();
assertEquals(2,repos.length);
// clear loader
ctx.setLoader(null);
// see tearDown()!
tomcat.start();
}
示例2: test
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
StandardContext context = new StandardContext();
context.setName("foo");
WebappLoader loader = new WebappLoader() {
@Override
public ClassLoader getClassLoader() {
return WebappLoader.class.getClassLoader();
}
};
context.setLoader(loader);
StandardHost host = new StandardHost();
StandardEngine engine = new StandardEngine();
engine.setService(new StandardService());
host.setParent(engine);
context.setParent(host);
loader.setContext(context);
RedisSessionManager manager = new RedisSessionManager();
manager.setSessionIdGenerator(new StandardSessionIdGenerator());
manager.setContext(context);
manager.initializeSerializer();
manager.initializeDatabaseConnection();
manager.clear();
StandardSession session = manager.createSession(null);
session.setAttribute("foo", "test");
manager.afterRequest();
StandardSession loaded = manager.findSession(session.getId());
Assert.assertEquals(session.getAttribute("foo"), loaded.getAttribute("foo"));
Assert.assertEquals(1, manager.getSize());
Assert.assertArrayEquals(new String[] { session.getId() }, manager.keys());
manager.processExpires();
}
示例3: testCheckHandleTypes
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
@Test
public void testCheckHandleTypes() throws Exception {
ContextConfig config = new ContextConfig();
config.handlesTypesAnnotations = true;
config.handlesTypesNonAnnotations = true;
// Need a Context, Loader and ClassLoader for checkHandleTypes
StandardContext context = new StandardContext();
context.setLoader(new TesterLoader());
config.context = context;
// Add an SCI that has no interest in any type
SCI sciNone = new SCI();
config.initializerClassMap.put(sciNone, new HashSet<Class<?>>());
// Add an SCI with an interest in Servlets
SCI sciServlet = new SCI();
config.initializerClassMap.put(sciServlet, new HashSet<Class<?>>());
config.typeInitializerMap.put(Servlet.class,
new HashSet<ServletContainerInitializer>());
config.typeInitializerMap.get(Servlet.class).add(sciServlet);
// Add an SCI with an interest in Objects - i.e. everything
SCI sciObject = new SCI();
config.initializerClassMap.put(sciObject, new HashSet<Class<?>>());
config.typeInitializerMap.put(Object.class,
new HashSet<ServletContainerInitializer>());
config.typeInitializerMap.get(Object.class).add(sciObject);
// Scan Servlet, Filter, Servlet, Listener
WebXml ignore = new WebXml();
File file = paramClassResource(
"org/apache/catalina/startup/ParamServlet");
config.processAnnotationsFile(file, ignore, false);
file = paramClassResource("org/apache/catalina/startup/ParamFilter");
config.processAnnotationsFile(file, ignore, false);
file = paramClassResource("org/apache/catalina/startup/TesterServlet");
config.processAnnotationsFile(file, ignore, false);
file = paramClassResource("org/apache/catalina/startup/TestListener");
config.processAnnotationsFile(file, ignore, false);
// Check right number of classes were noted to be handled
assertEquals(0, config.initializerClassMap.get(sciNone).size());
assertEquals(2, config.initializerClassMap.get(sciServlet).size());
assertEquals(4, config.initializerClassMap.get(sciObject).size());
}
示例4: test
import org.apache.catalina.core.StandardContext; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
StandardContext context = new StandardContext();
context.setName("foo");
WebappLoader loader = new WebappLoader() {
@Override
public ClassLoader getClassLoader() {
return WebappLoader.class.getClassLoader();
}
};
context.setLoader(loader);
StandardHost host = new StandardHost();
StandardEngine engine = new StandardEngine();
engine.setService(new StandardService());
host.setParent(engine);
context.setParent(host);
loader.setContext(context);
MongoPersistentManager manager = new MongoPersistentManager();
manager.setContext(context);
MongoStore store = new MongoStore();
store.setManager(manager);
store.setHosts("localhost:27017");
store.setDbName("mongo_session_test");
store.setCollectionName("mongo_session_test");
manager.setStore(store);
store.start();
StandardSession session = new StandardSession(manager);
session.setId("4711");
session.setNew(true);
session.setValid(true);
session.setCreationTime(System.currentTimeMillis());
session.setAttribute("foo", "test");
store.save(session);
StandardSession loaded = store.load(session.getId());
Assert.assertEquals(session.getAttribute("foo"), loaded.getAttribute("foo"));
Assert.assertEquals(1, store.getSize());
Assert.assertArrayEquals(new String[] { "4711" }, store.keys());
}