本文整理匯總了Java中org.apache.catalina.Wrapper.setLoadOnStartup方法的典型用法代碼示例。如果您正苦於以下問題:Java Wrapper.setLoadOnStartup方法的具體用法?Java Wrapper.setLoadOnStartup怎麽用?Java Wrapper.setLoadOnStartup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.catalina.Wrapper
的用法示例。
在下文中一共展示了Wrapper.setLoadOnStartup方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initWebappDefaults
import org.apache.catalina.Wrapper; //導入方法依賴的package包/類
/**
* Static version of {@link #initWebappDefaults(String)}
* @param ctx The context to set the defaults for
*/
public static void initWebappDefaults(Context ctx) {
// Default servlet
Wrapper servlet = addServlet(
ctx, "default", "org.apache.catalina.servlets.DefaultServlet");
servlet.setLoadOnStartup(1);
servlet.setOverridable(true);
// JSP servlet (by class name - to avoid loading all deps)
servlet = addServlet(
ctx, "jsp", "org.apache.jasper.servlet.JspServlet");
servlet.addInitParameter("fork", "false");
servlet.setLoadOnStartup(3);
servlet.setOverridable(true);
// Servlet mappings
ctx.addServletMapping("/", "default");
ctx.addServletMapping("*.jsp", "jsp");
ctx.addServletMapping("*.jspx", "jsp");
// Sessions
ctx.setSessionTimeout(30);
// MIME mappings
for (int i = 0; i < DEFAULT_MIME_MAPPINGS.length;) {
ctx.addMimeMapping(DEFAULT_MIME_MAPPINGS[i++],
DEFAULT_MIME_MAPPINGS[i++]);
}
// Welcome files
ctx.addWelcomeFile("index.html");
ctx.addWelcomeFile("index.htm");
ctx.addWelcomeFile("index.jsp");
}
示例2: testFlagFailCtxIfServletStartFails
import org.apache.catalina.Wrapper; //導入方法依賴的package包/類
@Test
public void testFlagFailCtxIfServletStartFails() throws Exception {
Tomcat tomcat = getTomcatInstance();
File docBase = new File(System.getProperty("java.io.tmpdir"));
StandardContext context = (StandardContext) tomcat.addContext("",
docBase.getAbsolutePath());
// first we test the flag itself, which can be set on the Host and
// Context
assertFalse(context.getComputedFailCtxIfServletStartFails());
StandardHost host = (StandardHost) tomcat.getHost();
host.setFailCtxIfServletStartFails(true);
assertTrue(context.getComputedFailCtxIfServletStartFails());
context.setFailCtxIfServletStartFails(Boolean.FALSE);
assertFalse("flag on Context should override Host config",
context.getComputedFailCtxIfServletStartFails());
// second, we test the actual effect of the flag on the startup
Wrapper servlet = Tomcat.addServlet(context, "myservlet",
new FailingStartupServlet());
servlet.setLoadOnStartup(1);
tomcat.start();
assertTrue("flag false should not fail deployment", context.getState()
.isAvailable());
tomcat.stop();
assertFalse(context.getState().isAvailable());
host.removeChild(context);
context = (StandardContext) tomcat.addContext("",
docBase.getAbsolutePath());
servlet = Tomcat.addServlet(context, "myservlet",
new FailingStartupServlet());
servlet.setLoadOnStartup(1);
tomcat.start();
assertFalse("flag true should fail deployment", context.getState()
.isAvailable());
}
示例3: makeContext
import org.apache.catalina.Wrapper; //導入方法依賴的package包/類
private void makeContext(Tomcat tomcat, Path noSuchBaseDir) throws IOException {
Path contextPath = noSuchBaseDir.resolve("context");
Files.createDirectories(contextPath);
context = tomcat.addContext(contextPathURIBase, contextPath.toAbsolutePath().toString());
context.setWebappVersion("3.1");
context.setName("Oryx");
context.addWelcomeFile("index.html");
addErrorPages(context);
// OryxApplication only needs one config value, so just pass it
context.addParameter(OryxApplication.class.getName() + ".packages", appResourcesPackages);
// ModelManagerListener will need whole config
String serializedConfig = ConfigUtils.serialize(config);
context.addParameter(ConfigUtils.class.getName() + ".serialized", serializedConfig);
Wrapper wrapper =
Tomcat.addServlet(context, "Jersey", "org.glassfish.jersey.servlet.ServletContainer");
wrapper.addInitParameter("javax.ws.rs.Application", OryxApplication.class.getName());
//wrapper.addInitParameter(OryxApplication.class.getName() + ".packages", appResourcesPackage);
wrapper.addMapping("/*");
wrapper.setLoadOnStartup(1);
wrapper.setMultipartConfigElement(new MultipartConfigElement(""));
if (!doNotInitTopics) { // Only for tests
context.addApplicationListener(ModelManagerListener.class.getName());
}
// Better way to configure JASPIC?
AuthConfigFactory.setFactory(new AuthConfigFactoryImpl());
boolean needHTTPS = keystoreFile != null;
boolean needAuthentication = userName != null;
if (needHTTPS || needAuthentication) {
SecurityCollection securityCollection = new SecurityCollection();
securityCollection.addPattern("/*");
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.addCollection(securityCollection);
if (needHTTPS) {
securityConstraint.setUserConstraint("CONFIDENTIAL");
}
if (needAuthentication) {
LoginConfig loginConfig = new LoginConfig();
loginConfig.setAuthMethod("DIGEST");
loginConfig.setRealmName(InMemoryRealm.NAME);
context.setLoginConfig(loginConfig);
securityConstraint.addAuthRole(InMemoryRealm.AUTH_ROLE);
context.addSecurityRole(InMemoryRealm.AUTH_ROLE);
DigestAuthenticator authenticator = new DigestAuthenticator();
authenticator.setNonceValidity(10 * 1000L); // Shorten from 5 minutes to 10 seconds
authenticator.setNonceCacheSize(20000); // Increase from 1000 to 20000
context.getPipeline().addValve(authenticator);
}
context.addConstraint(securityConstraint);
}
context.setCookies(false);
}