當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletContainerInitializer類代碼示例

本文整理匯總了Java中javax.servlet.ServletContainerInitializer的典型用法代碼示例。如果您正苦於以下問題:Java ServletContainerInitializer類的具體用法?Java ServletContainerInitializer怎麽用?Java ServletContainerInitializer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ServletContainerInitializer類屬於javax.servlet包,在下文中一共展示了ServletContainerInitializer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onStartup

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
@Override
public void onStartup(final Set<Class<?>> classes, final ServletContext ctx) throws ServletException {
    if (System.getProperty("openejb.embedder.source") != null) {
        ctx.log("TomEE already initialized");
        return;
    }

    ctx.log("Embedded TomEE starting");

    final Properties properties = new Properties();
    properties.putAll(System.getProperties());
    properties.setProperty("openejb.system.apps", Boolean.toString(Boolean.getBoolean("openejb.system.apps")));
    properties.setProperty("tomee.war", new File(ctx.getRealPath("WEB-INF")).getParentFile().getAbsolutePath());
    properties.setProperty("openejb.embedder.source", getClass().getSimpleName());

    TomcatEmbedder.embed(properties, ServletContainerInitializer.class.getClassLoader());

    ctx.log("Embedded TomEE started");

    Deployer.deploy(ctx);

    ctx.log("Application '" + ctx.getContextPath() + "' TomEE-ised");
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:24,代碼來源:TomEEOverlayRunner.java

示例2: start

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
private void start() throws InstantiationException, IllegalAccessException {

        TomcatApplicationBuilderFactory builderFactory = factoryClass.newInstance();
        TomcatApplicationBuilder builder = builderFactory.getBuilder(annotation);

        for (ServletContainerInitializer initializer : initializers) {
            builder.addServletContainerInitializer(initializer);
        }

        if (annotation != null) {
            this.timeout = annotation.timeout();
        } else {
            this.timeout = TomcatServerConfig.DEFAULT_TIMEOUT;
        }

        Tomcat tomcat = builder.build();

        this.runtime = tomcat.start(timeout);
    }
 
開發者ID:pidster-dot-org,項目名稱:embed-apache-tomcat,代碼行數:20,代碼來源:TomcatServerRule.java

示例3: getBuilder

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
@Override
public TomcatApplicationBuilder getBuilder(TomcatServerConfig annotation) {

    File baseFile = getBaseDir(annotation);
    String appName = getAppName(annotation);
    int port = getPort(annotation);

    File appDir = new File(baseFile, String.format("webapps/%s", appName));
    if (!appDir.exists() && !appDir.mkdirs()) {
        throw new IllegalStateException("Unable to create app dir at: " + appDir);
    }

    TomcatApplicationBuilder builder = new TomcatFactory().create()
        .newMinimalServer(baseFile, port)
            .createApplication(appName)
            .setStartStopThreads(1)
            .withDefaultConfig();

    if (annotation != null) {
        for (Class<? extends ServletContainerInitializer> initializer : annotation.value()) {
            builder.addServletContainerInitializer(initializer);
        }
    }

    return builder;
}
 
開發者ID:pidster-dot-org,項目名稱:embed-apache-tomcat,代碼行數:27,代碼來源:SimpleTomcatApplicationBuilderFactory.java

示例4: getSCIsForClass

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
private Set<ServletContainerInitializer> getSCIsForClass(String className) {
    for (Map.Entry<Class<?>, Set<ServletContainerInitializer>> entry :
            typeInitializerMap.entrySet()) {
        Class<?> clazz = entry.getKey();
        if (!clazz.isAnnotation()) {
            if (clazz.getName().equals(className)) {
                return entry.getValue();
            }
        }
    }
    return EMPTY_SCI_SET;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:13,代碼來源:ContextConfig.java

示例5: testWebapp

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
@Test
public void testWebapp() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File appDir = new File("test/webapp-3.0-fragments-empty-absolute-ordering");
    StandardContext ctxt = (StandardContext) tomcat.addContext(null, "/test", appDir.getAbsolutePath());
    ctxt.addLifecycleListener(new ContextConfig());
    tomcat.start();

    WebappServiceLoader<ServletContainerInitializer> loader =
            new WebappServiceLoader<ServletContainerInitializer>(ctxt);
    @SuppressWarnings("unused")
    Collection<ServletContainerInitializer> initializers = loader.load(ServletContainerInitializer.class);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:14,代碼來源:TestWebappServiceLoader.java

示例6: testBug50015

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
@Test
public void testBug50015() throws Exception {
    // Test that configuring servlet security constraints programmatically
    // does work.

    // Set up a container
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    // Setup realm
    MapRealm realm = new MapRealm();
    realm.addUser("tomcat", "tomcat");
    realm.addUserRole("tomcat", "tomcat");
    ctx.setRealm(realm);

    // Configure app for BASIC auth
    LoginConfig lc = new LoginConfig();
    lc.setAuthMethod("BASIC");
    ctx.setLoginConfig(lc);
    ctx.getPipeline().addValve(new BasicAuthenticator());

    // Add ServletContainerInitializer
    ServletContainerInitializer sci = new Bug50015SCI();
    ctx.addServletContainerInitializer(sci, null);

    // Start the context
    tomcat.start();

    // Request the first servlet
    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() + "/bug50015",
            bc, null);

    // Check for a 401
    assertNotSame("OK", bc.toString());
    assertEquals(401, rc);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:40,代碼來源:TestStandardContext.java

示例7: doTestSecurityAnnotationsAddServlet

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
private void doTestSecurityAnnotationsAddServlet(boolean useCreateServlet)
        throws Exception {

    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Servlet s = new DenyAllServlet();
    ServletContainerInitializer sci = new SCI(s, useCreateServlet);
    ctx.addServletContainerInitializer(sci, null);

    tomcat.start();

    ByteChunk bc = new ByteChunk();
    int rc;
    rc = getUrl("http://localhost:" + getPort() + "/", bc, null, null);

    if (useCreateServlet) {
        assertTrue(bc.getLength() > 0);
        assertEquals(403, rc);
    } else {
        assertEquals("OK", bc.toString());
        assertEquals(200, rc);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:28,代碼來源:TestStandardWrapper.java

示例8: populateSCIsForCacheEntry

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
private void populateSCIsForCacheEntry(JavaClassCacheEntry cacheEntry) {
	Set<ServletContainerInitializer> result = new HashSet<ServletContainerInitializer>();

	// Super class
	String superClassName = cacheEntry.getSuperclassName();
	JavaClassCacheEntry superClassCacheEntry = javaClassCache.get(superClassName);

	// Avoid an infinite loop with java.lang.Object
	if (cacheEntry.equals(superClassCacheEntry)) {
		cacheEntry.setSciSet(EMPTY_SCI_SET);
		return;
	}

	// May be null of the class is not present or could not be loaded.
	if (superClassCacheEntry != null) {
		if (superClassCacheEntry.getSciSet() == null) {
			populateSCIsForCacheEntry(superClassCacheEntry);
		}
		result.addAll(superClassCacheEntry.getSciSet());
	}
	result.addAll(getSCIsForClass(superClassName));

	// Interfaces
	for (String interfaceName : cacheEntry.getInterfaceNames()) {
		JavaClassCacheEntry interfaceEntry = javaClassCache.get(interfaceName);
		// A null could mean that the class not present in application or
		// that there is nothing of interest. Either way, nothing to do here
		// so move along
		if (interfaceEntry != null) {
			if (interfaceEntry.getSciSet() == null) {
				populateSCIsForCacheEntry(interfaceEntry);
			}
			result.addAll(interfaceEntry.getSciSet());
		}
		result.addAll(getSCIsForClass(interfaceName));
	}

	cacheEntry.setSciSet(result.isEmpty() ? EMPTY_SCI_SET : result);
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:40,代碼來源:ContextConfig.java

示例9: getSCIsForClass

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
private Set<ServletContainerInitializer> getSCIsForClass(String className) {
	for (Map.Entry<Class<?>, Set<ServletContainerInitializer>> entry : typeInitializerMap.entrySet()) {
		Class<?> clazz = entry.getKey();
		if (!clazz.isAnnotation()) {
			if (clazz.getName().equals(className)) {
				return entry.getValue();
			}
		}
	}
	return EMPTY_SCI_SET;
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:12,代碼來源:ContextConfig.java

示例10: getServletContainerInitializer

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
@Override
public ServletContainerInitializer getServletContainerInitializer() {
	if (this.servletContainerInitializer == null) {
		this.servletContainerInitializer = new FacesInitializer();
	}
	return this.servletContainerInitializer;
}
 
開發者ID:joinfaces,項目名稱:joinfaces,代碼行數:8,代碼來源:MojarraServletContextInitializer.java

示例11: getServletContainerInitializer

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
@Override
public ServletContainerInitializer getServletContainerInitializer() {
	if (this.servletContainerInitializer == null) {
		this.servletContainerInitializer = new MyFacesContainerInitializer();
	}
	return this.servletContainerInitializer;
}
 
開發者ID:joinfaces,項目名稱:joinfaces,代碼行數:8,代碼來源:MyfacesServletContextInitializer.java

示例12: onStartup

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
@Override
public void onStartup(ServletContext sc) throws ServletException {
	ServletContainerInitializer servletContainerInitializer = getServletContainerInitializer();
	JsfClassFactory jsfClassFactory = new JsfClassFactory(this);
	JoinFacesAnnotationProvider.setAnnotatedClasses(jsfClassFactory.getAnnotatedClassMap());
	JoinFacesAnnotationProvider.setUrls(jsfClassFactory.getURLs());
	servletContainerInitializer.onStartup(jsfClassFactory.getAllClasses(), sc);
}
 
開發者ID:joinfaces,項目名稱:joinfaces,代碼行數:9,代碼來源:MyfacesServletContextInitializer.java

示例13: getServletContainerInitializer

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
@Override
public ServletContainerInitializer getServletContainerInitializer() {
	if (this.servletContainerInitializer == null) {
		this.servletContainerInitializer = new FacesViewsInitializer();
	}
	return this.servletContainerInitializer;
}
 
開發者ID:joinfaces,項目名稱:joinfaces,代碼行數:8,代碼來源:OmnifacesServletContextInitializer.java

示例14: addJasperInitializer

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
private void addJasperInitializer(TomcatEmbeddedContext context) {
	try {
		ServletContainerInitializer initializer = (ServletContainerInitializer) ClassUtils
				.forName("org.apache.jasper.servlet.JasperInitializer", null)
				.newInstance();
		context.addServletContainerInitializer(initializer, null);
	}
	catch (Exception ex) {
		// Probably not Tomcat 8
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:TomcatEmbeddedServletContainerFactory.java

示例15: registerServletContainerInitializerToDriveServletContextInitializers

import javax.servlet.ServletContainerInitializer; //導入依賴的package包/類
private void registerServletContainerInitializerToDriveServletContextInitializers(
		DeploymentInfo deployment, ServletContextInitializer... initializers) {
	ServletContextInitializer[] mergedInitializers = mergeInitializers(initializers);
	Initializer initializer = new Initializer(mergedInitializers);
	deployment.addServletContainerInitalizer(new ServletContainerInitializerInfo(
			Initializer.class,
			new ImmediateInstanceFactory<ServletContainerInitializer>(initializer),
			NO_CLASSES));
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:UndertowEmbeddedServletContainerFactory.java


注:本文中的javax.servlet.ServletContainerInitializer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。