本文整理汇总了Java中org.apache.catalina.core.StandardContext类的典型用法代码示例。如果您正苦于以下问题:Java StandardContext类的具体用法?Java StandardContext怎么用?Java StandardContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StandardContext类属于org.apache.catalina.core包,在下文中一共展示了StandardContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateSessionAndPassivate
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
@Test
public void testCreateSessionAndPassivate() throws IOException, LifecycleException, ClassNotFoundException {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
ctx.setDistributable(true);
Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet());
ctx.addServletMapping("/dummy", "DummyServlet");
PersistentManager manager = new PersistentManager();
TesterStore store = new TesterStore();
manager.setStore(store);
manager.setMaxIdleBackup(0);
ctx.setManager(manager);
ctx.addValve(new PersistentValve());
tomcat.start();
Assert.assertEquals("No active sessions", manager.getActiveSessions(), 0);
Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
String sessionId = getUrl(
"http://localhost:" + getPort()
+ "/dummy?no_create_session=false").toString();
Assert.assertNotNull("Session is stored", store.load(sessionId));
Assert.assertEquals("All sessions are passivated", manager.getActiveSessions(), 0);
Assert.assertTrue("One session was created", !manager.getSessionIdsFull().isEmpty());
}
示例2: backgroundProcess
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
/**
* Execute a periodic task, such as reloading, etc. This method will be
* invoked inside the classloading context of this container. Unexpected
* throwables will be caught and logged.
*/
@Override
public void backgroundProcess() {
if (reloadable && modified()) {
try {
Thread.currentThread().setContextClassLoader
(WebappLoader.class.getClassLoader());
if (container instanceof StandardContext) {
((StandardContext) container).reload();
}
} finally {
if (container.getLoader() != null) {
Thread.currentThread().setContextClassLoader
(container.getLoader().getClassLoader());
}
}
} else {
closeJARs(false);
}
}
示例3: testBug48701Fail
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
@Test
public void testBug48701Fail() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir =
new File("test/webapp-3.0");
// app dir is relative to server home
StandardContext ctxt = (StandardContext) tomcat.addWebapp(null,
"/test", appDir.getAbsolutePath());
// This test needs the JSTL libraries
File lib = new File("webapps/examples/WEB-INF/lib");
ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());
tomcat.start();
int rc = getUrl("http://localhost:" + getPort() +
"/test/bug48nnn/bug48701-fail.jsp", new ByteChunk(), null);
assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
}
示例4: 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();
}
示例5: run
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
public void run() {
while (true) {
if (true)
return;
try {
Thread.sleep(1000);
if (null != host) {
Container[] csa = host.findChildren();
// System.out.println(host);
// System.out.println(csa);
// System.out.println(csa.length);
for (Container c : csa) {
StandardContext sc = (StandardContext) c;
System.out.println(sc.getState());
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
示例6: onAppStarting
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
/**
* onAppStarting
*
* @param args
*/
public void onAppStarting(Object... args) {
// release the left contexts
StandardInterceptContextHelper.releaseContext(Event.WEBCONTAINER_RESOURCE_INIT);
StandardInterceptContextHelper.releaseContext(Event.WEBCONTAINER_RESOURCE_CREATE);
StandardContext sc = (StandardContext) args[0];
InterceptSupport iSupport = InterceptSupport.instance();
InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_INIT);
context.put(InterceptConstants.WEBAPPLOADER, sc.getLoader().getClassLoader());
context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());
context.put(InterceptConstants.CONTEXTPATH,
ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true));
context.put(InterceptConstants.APPNAME, ReflectionHelper.getField(StandardContext.class, sc, "displayName", true));
ServletContext sContext = (ServletContext) ReflectionHelper.getField(StandardContext.class, sc, "context", true);
context.put(InterceptConstants.SERVLET_CONTEXT, sContext);
getBasePath(context, sContext);
iSupport.doIntercept(context);
}
示例7: setUp
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
ConcurrentMessageDigest.init("MD5");
// Configure the Realm
MapRealm realm = new MapRealm();
realm.addUser(USER, PWD);
realm.addUserRole(USER, ROLE);
// Add the Realm to the Context
Context context = new StandardContext();
context.setName(CONTEXT_PATH);
context.setRealm(realm);
// Make the Context and Realm visible to the Authenticator
authenticator.setContainer(context);
authenticator.setNonceCountWindowSize(8 * 1024);
authenticator.start();
}
示例8: testListBindings
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
@Test
public void testListBindings() throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.enableNaming();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
// Create the resource
ContextResource cr = new ContextResource();
cr.setName("list/foo");
cr.setType("org.apache.naming.resources.TesterObject");
cr.setProperty("factory", "org.apache.naming.resources.TesterFactory");
ctx.getNamingResources().addResource(cr);
// Map the test Servlet
Bug23950Servlet bug23950Servlet = new Bug23950Servlet();
Tomcat.addServlet(ctx, "bug23950Servlet", bug23950Servlet);
ctx.addServletMapping("/", "bug23950Servlet");
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
assertEquals("org.apache.naming.resources.TesterObject", bc.toString());
}
示例9: testBeanFactory
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
@Test
public void testBeanFactory() throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.enableNaming();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
// Create the resource
ContextResource cr = new ContextResource();
cr.setName("bug50351");
cr.setType("org.apache.naming.resources.TesterObject");
cr.setProperty("factory", "org.apache.naming.factory.BeanFactory");
cr.setProperty("foo", "value");
ctx.getNamingResources().addResource(cr);
// Map the test Servlet
Bug50351Servlet bug50351Servlet = new Bug50351Servlet();
Tomcat.addServlet(ctx, "bug50351Servlet", bug50351Servlet);
ctx.addServletMapping("/", "bug50351Servlet");
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
assertEquals("value", bc.toString());
}
示例10: testAuthenticate
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
@Test
public void testAuthenticate() throws Exception {
InMemoryRealm realm = new InMemoryRealm();
StandardContext ctx = new StandardContext();
ctx.setName("OryxTest");
realm.setContainer(ctx);
realm.start();
realm.addUser("foo", "bar");
Principal authPrincipal = realm.authenticate("foo", "bar");
assertNotNull(authPrincipal);
assertEquals("foo", authPrincipal.getName());
assertNull(realm.authenticate("foo", "baz"));
assertNull(realm.authenticate("bar", "foo"));
assertEquals("bar", realm.getPassword("foo"));
assertEquals("foo", realm.getPrincipal("foo").getName());
}
示例11: testReservedJNDIFileNamesNoCache
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
/**
* Additional test following on from SPR-7350 above to check files that
* contain JNDI reserved characters can be served when caching is disabled.
*/
@Test
public void testReservedJNDIFileNamesNoCache() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0-fragments");
// app dir is relative to server home
StandardContext ctxt = (StandardContext) tomcat.addWebapp(
null, "/test", appDir.getAbsolutePath());
ctxt.setCachingAllowed(false);
tomcat.start();
// Should be found in resources.jar
ByteChunk bc = getUrl("http://localhost:" + getPort() +
"/test/'singlequote.jsp");
assertEquals("<p>'singlequote.jsp in resources.jar</p>",
bc.toString());
// Should be found in file system
bc = getUrl("http://localhost:" + getPort() +
"/test/'singlequote2.jsp");
assertEquals("<p>'singlequote2.jsp in file system</p>",
bc.toString());
}
示例12: onAppInit
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
/**
* onAppInit
*
* @param args
*/
public void onAppInit(Object... args) {
StandardContext sc = (StandardContext) args[0];
InterceptSupport iSupport = InterceptSupport.instance();
InterceptContext ic = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_INIT);
InterceptContext ic2 = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_CREATE);
/**
* NOTE: onAppInit, we put the Context Object into threadlocal, then all other later process for
* PRE_WEBCONTAINER_INIT, which can get the object, as not everywhere we can get the object
*
* for example, the DataSource related injection
*/
ic.put(InterceptConstants.CONTEXTOBJ, sc);
ic2.put(InterceptConstants.CONTEXTOBJ, sc);
}
示例13: testBug56029
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
@Test
public void testBug56029() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0");
// app dir is relative to server home
StandardContext ctxt = (StandardContext) tomcat.addWebapp(
null, "/test", appDir.getAbsolutePath());
// This test needs the JSTL libraries
File lib = new File("webapps/examples/WEB-INF/lib");
ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() +
"/test/bug5nnnn/bug56029.jspx");
String result = res.toString();
Assert.assertTrue(result.contains("[1]:[1]"));
}
示例14: testBug56147
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
@Test
public void testBug56147() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0");
// app dir is relative to server home
StandardContext ctx = (StandardContext) tomcat.addWebapp(
null, "/test", appDir.getAbsolutePath());
// This test needs the JSTL libraries
File lib = new File("webapps/examples/WEB-INF/lib");
ctx.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() +
"/test/bug5nnnn/bug56147.jsp");
String result = res.toString();
assertEcho(result, "00-OK");
}
示例15: onAppStart
import org.apache.catalina.core.StandardContext; //导入依赖的package包/类
/**
* onAppStart
*
* @param args
*/
public void onAppStart(Object... args) {
StandardContext sc = (StandardContext) args[0];
InterceptSupport iSupport = InterceptSupport.instance();
InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_STARTED);
context.put(InterceptConstants.WEBAPPLOADER, sc.getLoader().getClassLoader());
context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());
context.put(InterceptConstants.CONTEXTPATH,
ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true));
context.put(InterceptConstants.APPNAME, ReflectionHelper.getField(StandardContext.class, sc, "displayName", true));
ServletContext sContext = (ServletContext) ReflectionHelper.getField(StandardContext.class, sc, "context", true);
context.put(InterceptConstants.SERVLET_CONTEXT, sContext);
getBasePath(context, sContext);
iSupport.doIntercept(context);
}