本文整理匯總了Java中org.apache.catalina.Context.setCrossContext方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.setCrossContext方法的具體用法?Java Context.setCrossContext怎麽用?Java Context.setCrossContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.catalina.Context
的用法示例。
在下文中一共展示了Context.setCrossContext方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testBug57190
import org.apache.catalina.Context; //導入方法依賴的package包/類
@Test
public void testBug57190() throws Exception {
Tomcat tomcat = getTomcatInstance();
Context foo1 = new StandardContext();
foo1.setName("/foo##1");
foo1.setPath("/foo");
foo1.setWebappVersion("1");
foo1.setDocBase(System.getProperty("java.io.tmpdir"));
foo1.addLifecycleListener(new FixContextListener());
foo1.addLifecycleListener(new SetIdListener("foo1"));
tomcat.getHost().addChild(foo1);
Context foo2 = new StandardContext();
foo2.setName("/foo##2");
foo2.setPath("/foo");
foo2.setWebappVersion("2");
foo2.setDocBase(System.getProperty("java.io.tmpdir"));
foo2.addLifecycleListener(new FixContextListener());
foo2.addLifecycleListener(new SetIdListener("foo2"));
tomcat.getHost().addChild(foo2);
// No file system docBase required
Context bar = tomcat.addContext("/bar", null);
bar.addLifecycleListener(new SetIdListener("bar"));
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addLifecycleListener(new SetIdListener("ROOT"));
ctx.setCrossContext(true);
Tomcat.addServlet(ctx, "Bug57190Servlet", new Bug57190Servlet());
ctx.addServletMapping("/", "Bug57190Servlet");
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
String body = res.toString();
Assert.assertTrue(body, body.contains("01-bar"));
Assert.assertTrue(body, body.contains("02-foo2"));
Assert.assertTrue(body, body.contains("03-foo1"));
Assert.assertTrue(body, body.contains("04-foo2"));
Assert.assertTrue(body, body.contains("05-foo2"));
Assert.assertTrue(body, body.contains("06-ROOT"));
Assert.assertTrue(body, body.contains("07-ROOT"));
Assert.assertTrue(body, body.contains("08-foo2"));
Assert.assertTrue(body, body.contains("09-ROOT"));
}
示例2: importDefaultContext
import org.apache.catalina.Context; //導入方法依賴的package包/類
/**
* Import the configuration from the DefaultContext into
* current Context.
*
* @param context current web application context
*/
public void importDefaultContext(Context context) {
if (context instanceof StandardContext) {
((StandardContext)context).setUseNaming(isUseNaming());
((StandardContext)context).setSwallowOutput(getSwallowOutput());
if (!contexts.containsKey(context)) {
((StandardContext) context).addLifecycleListener(this);
}
}
context.setCookies(getCookies());
context.setCrossContext(getCrossContext());
context.setReloadable(getReloadable());
String [] listeners = findApplicationListeners();
for( int i = 0; i < listeners.length; i++ ) {
context.addApplicationListener(listeners[i]);
}
listeners = findInstanceListeners();
for( int i = 0; i < listeners.length; i++ ) {
context.addInstanceListener(listeners[i]);
}
String [] wrapper = findWrapperListeners();
for( int i = 0; i < wrapper.length; i++ ) {
context.addWrapperListener(wrapper[i]);
}
wrapper = findWrapperLifecycles();
for( int i = 0; i < wrapper.length; i++ ) {
context.addWrapperLifecycle(wrapper[i]);
}
String [] parameters = findParameters();
for( int i = 0; i < parameters.length; i++ ) {
context.addParameter(parameters[i],findParameter(parameters[i]));
}
ApplicationParameter [] appParam = findApplicationParameters();
for( int i = 0; i < appParam.length; i++ ) {
context.addApplicationParameter(appParam[i]);
}
if (!(context instanceof StandardContext)) {
ContextEjb [] contextEjb = findEjbs();
for( int i = 0; i < contextEjb.length; i++ ) {
context.addEjb(contextEjb[i]);
}
ContextEnvironment [] contextEnv = findEnvironments();
for( int i = 0; i < contextEnv.length; i++ ) {
context.addEnvironment(contextEnv[i]);
}
/*
if (context instanceof StandardContext) {
ResourceParams [] resourceParams = findResourceParams();
for( int i = 0; i < resourceParams.length; i++ ) {
((StandardContext)context).addResourceParams
(resourceParams[i]);
}
}
*/
ContextResource [] resources = findResources();
for( int i = 0; i < resources.length; i++ ) {
context.addResource(resources[i]);
}
String [] envRefs = findResourceEnvRefs();
for( int i = 0; i < envRefs.length; i++ ) {
context.addResourceEnvRef
(envRefs[i],findResourceEnvRef(envRefs[i]));
}
}
}