Java 类org.springframework.boot.context.embedded.ServletContextInitializer 实例源码

项目:contestparser    文件:TomcatEmbeddedServletContainerFactory.java   
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
        ServletContextInitializer... initializers) {
    Tomcat tomcat = new Tomcat();
    File baseDir = (this.baseDirectory != null ? this.baseDirectory
            : createTempDir("tomcat"));
    tomcat.setBaseDir(baseDir.getAbsolutePath());
    Connector connector = new Connector(this.protocol);
    tomcat.getService().addConnector(connector);
    customizeConnector(connector);
    tomcat.setConnector(connector);
    tomcat.getHost().setAutoDeploy(false);
    tomcat.getEngine().setBackgroundProcessorDelay(-1);
    for (Connector additionalConnector : this.additionalTomcatConnectors) {
        tomcat.getService().addConnector(additionalConnector);
    }
    prepareContext(tomcat.getHost(), initializers);
    return getTomcatEmbeddedServletContainer(tomcat);
}
项目:apollo-custom    文件:WebContextConfiguration.java   
@Bean
public ServletContextInitializer servletContextInitializer() {

  return new ServletContextInitializer() {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
      String loggingServerIP = portalConfig.cloggingUrl();
      String loggingServerPort = portalConfig.cloggingPort();
      String credisServiceUrl = portalConfig.credisServiceUrl();

      servletContext.setInitParameter("loggingServerIP",
          Strings.isNullOrEmpty(loggingServerIP) ? "" : loggingServerIP);
      servletContext.setInitParameter("loggingServerPort",
          Strings.isNullOrEmpty(loggingServerPort) ? "" : loggingServerPort);
      servletContext.setInitParameter("credisServiceUrl",
          Strings.isNullOrEmpty(credisServiceUrl) ? "" : credisServiceUrl);
    }
  };
}
项目:nebo    文件:NettyEmbeddedServletContainerFactory.java   
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer... initializers) {
    ClassLoader parentClassLoader = resourceLoader != null ? resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader();
    Package nettyPackage = Bootstrap.class.getPackage();
    String title = nettyPackage.getImplementationTitle();
    String version = nettyPackage.getImplementationVersion();
    logger.info("Running with " + title + " " + version);
    NettyEmbeddedContext context = new NettyEmbeddedContext(getContextPath(), new URLClassLoader(new URL[]{}, parentClassLoader), SERVER_INFO);
    if (isRegisterDefaultServlet()) {
        logger.warn("This container does not support a default servlet");
    }

    for (ServletContextInitializer initializer : initializers) {
        try {
            initializer.onStartup(context);
        } catch (ServletException e) {
            throw new RuntimeException(e);
        }
    }
    int port = getPort() > 0 ? getPort() : new Random().nextInt(65535 - 1024) + 1024;
    InetSocketAddress address = new InetSocketAddress(port);
    logger.info("Server initialized with port: " + port);
    return new NettyEmbeddedServletContainer(address, context);
}
项目:apollo    文件:WebContextConfiguration.java   
@Bean
public ServletContextInitializer servletContextInitializer() {

  return new ServletContextInitializer() {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
      String loggingServerIP = portalConfig.cloggingUrl();
      String loggingServerPort = portalConfig.cloggingPort();
      String credisServiceUrl = portalConfig.credisServiceUrl();

      servletContext.setInitParameter("loggingServerIP",
          Strings.isNullOrEmpty(loggingServerIP) ? "" : loggingServerIP);
      servletContext.setInitParameter("loggingServerPort",
          Strings.isNullOrEmpty(loggingServerPort) ? "" : loggingServerPort);
      servletContext.setInitParameter("credisServiceUrl",
          Strings.isNullOrEmpty(credisServiceUrl) ? "" : credisServiceUrl);
    }
  };
}
项目:contestparser    文件:TomcatEmbeddedServletContainerFactory.java   
/**
 * Configure the Tomcat {@link Context}.
 * @param context the Tomcat context
 * @param initializers initializers to apply
 */
protected void configureContext(Context context,
        ServletContextInitializer[] initializers) {
    TomcatStarter starter = new TomcatStarter(initializers);
    if (context instanceof TomcatEmbeddedContext) {
        // Should be true
        ((TomcatEmbeddedContext) context).setStarter(starter);
    }
    context.addServletContainerInitializer(starter, NO_CLASSES);
    for (LifecycleListener lifecycleListener : this.contextLifecycleListeners) {
        context.addLifecycleListener(lifecycleListener);
    }
    for (Valve valve : this.contextValves) {
        context.getPipeline().addValve(valve);
    }
    for (ErrorPage errorPage : getErrorPages()) {
        new TomcatErrorPage(errorPage).addToContext(context);
    }
    for (MimeMappings.Mapping mapping : getMimeMappings()) {
        context.addMimeMapping(mapping.getExtension(), mapping.getMimeType());
    }
    configureSession(context);
    for (TomcatContextCustomizer customizer : this.tomcatContextCustomizers) {
        customizer.customize(context);
    }
}
项目:contestparser    文件:TomcatStarter.java   
@Override
public void onStartup(Set<Class<?>> classes, ServletContext servletContext)
        throws ServletException {
    try {
        for (ServletContextInitializer initializer : this.initializers) {
            initializer.onStartup(servletContext);
        }
    }
    catch (Exception ex) {
        this.startUpException = ex;
        // Prevent Tomcat from logging and re-throwing when we know we can
        // deal with it in the main thread, but log for information here.
        if (logger.isErrorEnabled()) {
            logger.error("Error starting Tomcat context: " + ex.getClass().getName());
        }
    }
}
项目:contestparser    文件:JettyEmbeddedServletContainerFactory.java   
/**
 * Configure the given Jetty {@link WebAppContext} for use.
 * @param context the context to configure
 * @param initializers the set of initializers to apply
 */
protected final void configureWebAppContext(WebAppContext context,
        ServletContextInitializer... initializers) {
    Assert.notNull(context, "Context must not be null");
    context.setTempDirectory(getTempDirectory());
    if (this.resourceLoader != null) {
        context.setClassLoader(this.resourceLoader.getClassLoader());
    }
    String contextPath = getContextPath();
    context.setContextPath(StringUtils.hasLength(contextPath) ? contextPath : "/");
    context.setDisplayName(getDisplayName());
    configureDocumentRoot(context);
    if (isRegisterDefaultServlet()) {
        addDefaultServlet(context);
    }
    if (shouldRegisterJspServlet()) {
        addJspServlet(context);
    }
    ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
    Configuration[] configurations = getWebAppContextConfigurations(context,
            initializersToUse);
    context.setConfigurations(configurations);
    configureSession(context);
    postProcessWebAppContext(context);
}
项目:spring-boot-starter-lightadmin    文件:LightAdminAutoConfig.java   
/**
    * public void onStartup(ServletContext servletContext) throws ServletException {
    * LightAdmin.configure(servletContext)
    * .basePackage("org.lightadmin.boot.administration")
    * .baseUrl("/admin")
    * .security(false)
    * .backToSiteUrl("http://lightadmin.org");
    * super.onStartup(servletContext);
    * }
    */

/* Used for running in "embedded" mode */
   @Bean
   public ServletContextInitializer servletContextInitializer() {
       return new ServletContextInitializer() {
           @Override
           public void onStartup(ServletContext servletContext) throws ServletException {
               LightAdmin.configure(servletContext)
                       //.basePackage("org.lightadmin.boot.administration")
                       .baseUrl("/lightadmin")
                       .security(false)
                       .backToSiteUrl("http://lightadmin.org");

               new LightAdminWebApplicationInitializer().onStartup(servletContext);
           }
       };
   }
项目:spring-boot-starter-netty    文件:NettyEmbeddedServletContainerFactory.java   
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer... initializers) {
    ClassLoader parentClassLoader = resourceLoader != null ? resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader();
    Package nettyPackage = Bootstrap.class.getPackage();
    String title = nettyPackage.getImplementationTitle();
    String version = nettyPackage.getImplementationVersion();
    logger.info("Running with " + title + " " + version);
    NettyEmbeddedContext context = new NettyEmbeddedContext(getContextPath(), new URLClassLoader(new URL[]{}, parentClassLoader), SERVER_INFO);
    if (isRegisterDefaultServlet()) {
        logger.warn("This container does not support a default servlet");
    }
    if (isRegisterJspServlet()) {
        logger.warn("This container does not support a JSP servlet");
    }
    for (ServletContextInitializer initializer : initializers) {
        try {
            initializer.onStartup(context);
        } catch (ServletException e) {
            throw new RuntimeException(e);
        }
    }
    int port = getPort() > 0 ? getPort() : new Random().nextInt(65535 - 1024) + 1024;
    InetSocketAddress address = new InetSocketAddress(port);
    logger.info("Server initialized with port: " + port);
    return new NettyEmbeddedServletContainer(address, context);
}
项目:lightadmin-springboot    文件:LightAdminBootApplication.java   
/**
 * public void onStartup(ServletContext servletContext) throws ServletException {
 * LightAdmin.configure(servletContext)
 * .basePackage("org.lightadmin.boot.administration")
 * .baseUrl("/admin")
 * .security(false)
 * .backToSiteUrl("http://lightadmin.org");
 * super.onStartup(servletContext);
 * }
 */

/* Used for running in "embedded" mode */
@Bean
public ServletContextInitializer servletContextInitializer() {
    return new ServletContextInitializer() {
        @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
            LightAdmin.configure(servletContext)
                    .basePackage("org.lightadmin.boot.administration")
                    .baseUrl("/admin")
                    .security(true)
                    .backToSiteUrl("http://lightadmin.org");

            new LightAdminWebApplicationInitializer().onStartup(servletContext);
        }
    };
}
项目:Voting_2b    文件:Main.java   
@Bean
public ServletContextInitializer servletContextInitializer() {
    return servletContext -> {
        servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
        servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", Boolean.TRUE.toString());
        servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", "true");
        servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development");
        servletContext.addListener(com.sun.faces.config.ConfigureListener.class);
        servletContext.setInitParameter("BootsFaces_THEME", "default");
    };
}
项目:Voting_2b    文件:Application.java   
@Bean
public ServletContextInitializer servletContextInitializer() {
    return servletContext -> {
        servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
        servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", Boolean.TRUE.toString());
    };
}
项目:VoteCounting_2b    文件:Main.java   
@Bean
public ServletContextInitializer servletContextInitializer() {
    return servletContext -> {
        servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
        servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", Boolean.TRUE.toString());
        servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", "true");
        servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development");
        servletContext.addListener(com.sun.faces.config.ConfigureListener.class);
        servletContext.setInitParameter("BootsFaces_THEME", "default");
    };
}
项目:VulnerableJavaWebApplication    文件:AppLauncher.java   
@SuppressWarnings("deprecation")
@Bean
public ServletContextInitializer servletContextInitializer() {
    return new ServletContextInitializer() {
        @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
            servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
            SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
            sessionCookieConfig.setHttpOnly(true);
        }
    };

}
项目:contestparser    文件:TomcatEmbeddedServletContainerFactory.java   
protected void prepareContext(Host host, ServletContextInitializer[] initializers) {
    File docBase = getValidDocumentRoot();
    docBase = (docBase != null ? docBase : createTempDir("tomcat-docbase"));
    TomcatEmbeddedContext context = new TomcatEmbeddedContext();
    context.setName(getContextPath());
    context.setDisplayName(getDisplayName());
    context.setPath(getContextPath());
    context.setDocBase(docBase.getAbsolutePath());
    context.addLifecycleListener(new FixContextListener());
    context.setParentClassLoader(
            this.resourceLoader != null ? this.resourceLoader.getClassLoader()
                    : ClassUtils.getDefaultClassLoader());
    SkipPatternJarScanner.apply(context, this.tldSkip);
    WebappLoader loader = new WebappLoader(context.getParentClassLoader());
    loader.setLoaderClass(TomcatEmbeddedWebappClassLoader.class.getName());
    loader.setDelegate(true);
    context.setLoader(loader);
    if (isRegisterDefaultServlet()) {
        addDefaultServlet(context);
    }
    if (shouldRegisterJspServlet()) {
        addJspServlet(context);
        addJasperInitializer(context);
        context.addLifecycleListener(new StoreMergedWebXmlListener());
    }
    ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
    configureContext(context, initializersToUse);
    host.addChild(context);
    postProcessContext(context);
}
项目:contestparser    文件:UndertowEmbeddedServletContainerFactory.java   
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
        ServletContextInitializer... initializers) {
    DeploymentManager manager = createDeploymentManager(initializers);
    int port = getPort();
    Builder builder = createBuilder(port);
    return new UndertowEmbeddedServletContainer(builder, manager, getContextPath(),
            port, this.useForwardHeaders, port >= 0, getCompression());
}
项目:contestparser    文件:UndertowEmbeddedServletContainerFactory.java   
private DeploymentManager createDeploymentManager(
        ServletContextInitializer... initializers) {
    DeploymentInfo deployment = Servlets.deployment();
    registerServletContainerInitializerToDriveServletContextInitializers(deployment,
            initializers);
    deployment.setClassLoader(getServletClassLoader());
    deployment.setContextPath(getContextPath());
    deployment.setDisplayName(getDisplayName());
    deployment.setDeploymentName("spring-boot");
    if (isRegisterDefaultServlet()) {
        deployment.addServlet(Servlets.servlet("default", DefaultServlet.class));
    }
    configureErrorPages(deployment);
    deployment.setServletStackTraces(ServletStackTraces.NONE);
    deployment.setResourceManager(getDocumentRootResourceManager());
    configureMimeMappings(deployment);
    for (UndertowDeploymentInfoCustomizer customizer : this.deploymentInfoCustomizers) {
        customizer.customize(deployment);
    }
    if (isAccessLogEnabled()) {
        configureAccessLog(deployment);
    }
    if (isPersistSession()) {
        File folder = getValidSessionStoreDir();
        deployment.setSessionPersistenceManager(new FileSessionPersistence(folder));
    }
    DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment);
    manager.deploy();
    SessionManager sessionManager = manager.getDeployment().getSessionManager();
    int sessionTimeout = (getSessionTimeout() > 0 ? getSessionTimeout() : -1);
    sessionManager.setDefaultSessionTimeout(sessionTimeout);
    return manager;
}
项目:contestparser    文件:UndertowEmbeddedServletContainerFactory.java   
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));
}
项目:contestparser    文件:UndertowEmbeddedServletContainerFactory.java   
@Override
public void onStartup(Set<Class<?>> classes, ServletContext servletContext)
        throws ServletException {
    for (ServletContextInitializer initializer : this.initializers) {
        initializer.onStartup(servletContext);
    }
}
项目:contestparser    文件:JettyEmbeddedServletContainerFactory.java   
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
        ServletContextInitializer... initializers) {
    JettyEmbeddedWebAppContext context = new JettyEmbeddedWebAppContext();
    int port = (getPort() >= 0 ? getPort() : 0);
    Server server = new Server(new InetSocketAddress(getAddress(), port));
    configureWebAppContext(context, initializers);
    if (getCompression() != null && getCompression().getEnabled()) {
        HandlerWrapper gzipHandler = createGzipHandler();
        gzipHandler.setHandler(context);
        server.setHandler(gzipHandler);
    }
    else {
        server.setHandler(context);
    }
    this.logger.info("Server initialized with port: " + port);
    if (getSsl() != null && getSsl().isEnabled()) {
        SslContextFactory sslContextFactory = new SslContextFactory();
        configureSsl(sslContextFactory, getSsl());
        AbstractConnector connector = getSslServerConnectorFactory()
                .getConnector(server, sslContextFactory, port);
        server.setConnectors(new Connector[] { connector });
    }
    for (JettyServerCustomizer customizer : getServerCustomizers()) {
        customizer.customize(server);
    }
    if (this.useForwardHeaders) {
        new ForwardHeadersCustomizer().customize(server);
    }
    return getJettyEmbeddedServletContainer(server);
}
项目:contestparser    文件:JettyEmbeddedServletContainerFactory.java   
/**
 * Return the Jetty {@link Configuration}s that should be applied to the server.
 * @param webAppContext the Jetty {@link WebAppContext}
 * @param initializers the {@link ServletContextInitializer}s to apply
 * @return configurations to apply
 */
protected Configuration[] getWebAppContextConfigurations(WebAppContext webAppContext,
        ServletContextInitializer... initializers) {
    List<Configuration> configurations = new ArrayList<Configuration>();
    configurations.add(
            getServletContextInitializerConfiguration(webAppContext, initializers));
    configurations.addAll(getConfigurations());
    configurations.add(getErrorPageConfiguration());
    configurations.add(getMimeTypeConfiguration());
    return configurations.toArray(new Configuration[configurations.size()]);
}
项目:contestparser    文件:ServletContextInitializerConfiguration.java   
private void callInitializers() throws ServletException {
    try {
        setExtendedListenerTypes(true);
        for (ServletContextInitializer initializer : ServletContextInitializerConfiguration.this.initializers) {
            initializer.onStartup(this.context.getServletContext());
        }
    }
    finally {
        setExtendedListenerTypes(false);
    }
}
项目:contestparser    文件:ServerPropertiesTests.java   
private void triggerInitializers(ConfigurableEmbeddedServletContainer container,
        ServletContext servletContext) throws ServletException {
    verify(container, atLeastOnce())
            .addInitializers(this.initializersCaptor.capture());
    for (Object initializers : this.initializersCaptor.getAllValues()) {
        if (initializers instanceof ServletContextInitializer) {
            ((ServletContextInitializer) initializers).onStartup(servletContext);
        }
        else {
            for (ServletContextInitializer initializer : (ServletContextInitializer[]) initializers) {
                initializer.onStartup(servletContext);
            }
        }
    }
}
项目:websec-saml2sp    文件:MvcConfig.java   
/**
 * Servlet context initializer that sets a custom session cookie name.
 *
 * Otherwise, saml2sp and WSO2's Identity Server overwrite each other's session cookie if they are
 * both serving localhost (on different ports). This breaks the SSO flow.
 *
 * @return a context initializer that sets the session cookie name to {@code "SAML2SPSESSIONID"}.
 */
@Bean
public ServletContextInitializer servletContextInitializer() {
    return new ServletContextInitializer() {

        @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
            servletContext.getSessionCookieConfig().setName("SAML2SPSESSIONID");
        }
    };
}
项目:SpringFrameworkSamples    文件:JsfConfiguration.java   
@Bean
public ServletContextInitializer contextInitializer(){
    ServletContextInitializer listener = new ServletContextInitializer() {
        @Override
        public void onStartup(ServletContext servletContext)
                throws ServletException {
            servletContext.setInitParameter("primefaces.THEME", "glass-x");

        }
    };

    return listener;
}
项目:spring-security-stateless    文件:AppConfig.java   
@Bean
ServletContextInitializer noSessionTrackingServletContextInitializer() {
    return servletContext -> servletContext.setSessionTrackingModes(Collections.emptySet());
}
项目:citizenship-appointment-server    文件:AppConfig.java   
@Bean
public ServletContextInitializer noSessionTrackingServletContextInitializer() {
    return servletContext -> servletContext.setSessionTrackingModes(Collections.emptySet());
}
项目:contestparser    文件:TomcatStarter.java   
TomcatStarter(ServletContextInitializer[] initializers) {
    this.initializers = initializers;
}
项目:contestparser    文件:UndertowEmbeddedServletContainerFactory.java   
Initializer(ServletContextInitializer[] initializers) {
    this.initializers = initializers;
}
项目:contestparser    文件:ServletContextInitializerConfiguration.java   
/**
 * Create a new {@link ServletContextInitializerConfiguration}.
 * @param initializers the initializers that should be invoked
 * @since 1.2.1
 */
public ServletContextInitializerConfiguration(
        ServletContextInitializer... initializers) {
    Assert.notNull(initializers, "Initializers must not be null");
    this.initializers = initializers;
}
项目:contestparser    文件:JettyEmbeddedServletContainerFactory.java   
/**
 * Return a Jetty {@link Configuration} that will invoke the specified
 * {@link ServletContextInitializer}s. By default this method will return a
 * {@link ServletContextInitializerConfiguration}.
 * @param webAppContext the Jetty {@link WebAppContext}
 * @param initializers the {@link ServletContextInitializer}s to apply
 * @return the {@link Configuration} instance
 */
protected Configuration getServletContextInitializerConfiguration(
        WebAppContext webAppContext, ServletContextInitializer... initializers) {
    return new ServletContextInitializerConfiguration(initializers);
}