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

项目: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);
}
项目:tasfe-framework    文件: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);
}
项目: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);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件: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);
    configureEngine(tomcat.getEngine());
    for (Connector additionalConnector : this.additionalTomcatConnectors) {
        tomcat.getService().addConnector(additionalConnector);
    }
    prepareContext(tomcat.getHost(), initializers);
    return getTomcatEmbeddedServletContainer(tomcat);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JettyEmbeddedServletContainerFactory.java   
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
        ServletContextInitializer... initializers) {
    JettyEmbeddedWebAppContext context = new JettyEmbeddedWebAppContext();
    int port = (getPort() >= 0 ? getPort() : 0);
    InetSocketAddress address = new InetSocketAddress(getAddress(), port);
    Server server = createServer(address);
    configureWebAppContext(context, initializers);
    server.setHandler(addHandlerWrappers(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);
}
项目:spring-boot-concourse    文件: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);
}
项目:spring-boot-concourse    文件:JettyEmbeddedServletContainerFactory.java   
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
        ServletContextInitializer... initializers) {
    JettyEmbeddedWebAppContext context = new JettyEmbeddedWebAppContext();
    int port = (getPort() >= 0 ? getPort() : 0);
    InetSocketAddress address = new InetSocketAddress(getAddress(), port);
    Server server = createServer(address);
    configureWebAppContext(context, initializers);
    server.setHandler(addHandlerWrappers(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);
}
项目:Kafdrop    文件:ServiceDiscoveryConfiguration.java   
private Integer getServicePort(EmbeddedWebApplicationContext webContext)
{
   Integer port = null;
   if (webContext != null)
   {
      final EmbeddedServletContainer container = webContext.getEmbeddedServletContainer();

      if (container instanceof TomcatEmbeddedServletContainer)
      {
         // Work around an issue with the tomcat container, which uses the local port
         // as the port (-1) instead of the registered port
         port = ((TomcatEmbeddedServletContainer) container).getTomcat().getConnector().getPort();
      }
      else
      {
         port = container.getPort();
      }
   }
   return port;
}
项目: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);
}
项目:micrometer    文件:TomcatMetricsConfiguration.java   
private Manager getManagerFromContext(EmbeddedWebApplicationContext applicationContext) {
    EmbeddedServletContainer embeddedServletContainer = applicationContext.getEmbeddedServletContainer();
    if (embeddedServletContainer instanceof TomcatEmbeddedServletContainer) {
        return getManagerFromContainer((TomcatEmbeddedServletContainer) embeddedServletContainer);
    }
    return null;
}
项目:springboot-camel-metrics-publisher    文件:MetricsServletConfiguration.java   
/**
 * Initialise the embedded servlet container metrics reporting.
 *
 * @return An ApplicationListener which will register a MetricsPublisher when the Servlet container is
 *          initialised
 */
@Bean
public ApplicationListener<EmbeddedServletContainerInitializedEvent> embeddedServletContainerMetricsInitializer() {

    final MetricRegistry registry = codahaleMetricsRegistry();

    return new ApplicationListener<EmbeddedServletContainerInitializedEvent>() {

        @Override
        public void onApplicationEvent(EmbeddedServletContainerInitializedEvent embeddedServletContainerInitializedEvent) {

            EmbeddedServletContainer initializedServletContainer = embeddedServletContainerInitializedEvent.getEmbeddedServletContainer();

            if (initializedServletContainer == null) {
                LOGGER.error("The EmbeddedServletContainer obtained from the EmbeddedServletContainerInitializedEvent was null; metrics will not be published");
                return;
            }

            int serverPort = initializedServletContainer.getPort();

            LOGGER.info("Initialising MetricsPublisher on port {}", serverPort);

            TomcatMetricsPublisher.forRegistry(registry)
                    .serverPortIs(serverPort)
                    .start();

            // register the graphite reporter
            Statsd statsd = new Statsd(metricsReporterHost, metricsReporterPort);
            StatsdReporter statsdReporter = StatsdReporter.forRegistry(registry)
                    .prefixedWith(metricsPrefix + serverPort)
                    .convertDurationsTo(TimeUnit.MILLISECONDS)
                    .convertRatesTo(TimeUnit.SECONDS)
                    .filter(new ConfigurableCodaHaleMetricFilter(DynamicPropertyFactory.getInstance()))
                    .build(statsd);
            statsdReporter.start(pollingPeriodInSeconds, TimeUnit.SECONDS);

        }
    };
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:UndertowEmbeddedServletContainerFactory.java   
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
        ServletContextInitializer... initializers) {
    DeploymentManager manager = createDeploymentManager(initializers);
    int port = getPort();
    Builder builder = createBuilder(port);
    return getUndertowEmbeddedServletContainer(builder, manager, port);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:TomcatPublicMetrics.java   
private Manager getManager(EmbeddedWebApplicationContext applicationContext) {
    EmbeddedServletContainer embeddedServletContainer = applicationContext
            .getEmbeddedServletContainer();
    if (embeddedServletContainer instanceof TomcatEmbeddedServletContainer) {
        return getManager((TomcatEmbeddedServletContainer) embeddedServletContainer);
    }
    return null;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EmbeddedServerPortFileWriterTests.java   
private EmbeddedServletContainerInitializedEvent mockEvent(String name, int port) {
    EmbeddedWebApplicationContext applicationContext = mock(
            EmbeddedWebApplicationContext.class);
    EmbeddedServletContainer source = mock(EmbeddedServletContainer.class);
    given(applicationContext.getNamespace()).willReturn(name);
    given(source.getPort()).willReturn(port);
    EmbeddedServletContainerInitializedEvent event = new EmbeddedServletContainerInitializedEvent(
            applicationContext, source);
    return event;
}
项目:funcatron    文件:MockServer.java   
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
        ServletContextInitializer... initializers) {
    this.container = new MockEmbeddedServletContainer(
            mergeInitializers(initializers), getPort());
    return this.container;
}
项目:spring-boot-concourse    文件:UndertowEmbeddedServletContainerFactory.java   
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
        ServletContextInitializer... initializers) {
    DeploymentManager manager = createDeploymentManager(initializers);
    int port = getPort();
    Builder builder = createBuilder(port);
    return getUndertowEmbeddedServletContainer(builder, manager, port);
}
项目:spring-boot-concourse    文件:TomcatPublicMetrics.java   
private Manager getManager(EmbeddedWebApplicationContext applicationContext) {
    EmbeddedServletContainer embeddedServletContainer = applicationContext
            .getEmbeddedServletContainer();
    if (embeddedServletContainer instanceof TomcatEmbeddedServletContainer) {
        return getManager((TomcatEmbeddedServletContainer) embeddedServletContainer);
    }
    return null;
}
项目:spring-boot-concourse    文件:EmbeddedServerPortFileWriterTests.java   
private EmbeddedServletContainerInitializedEvent mockEvent(String name, int port) {
    EmbeddedWebApplicationContext applicationContext = mock(
            EmbeddedWebApplicationContext.class);
    EmbeddedServletContainer source = mock(EmbeddedServletContainer.class);
    given(applicationContext.getNamespace()).willReturn(name);
    given(source.getPort()).willReturn(port);
    EmbeddedServletContainerInitializedEvent event = new EmbeddedServletContainerInitializedEvent(
            applicationContext, source);
    return event;
}
项目: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    文件: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    文件:TomcatPublicMetrics.java   
private Manager getManager(EmbeddedWebApplicationContext applicationContext) {
    EmbeddedServletContainer embeddedServletContainer = applicationContext
            .getEmbeddedServletContainer();
    if (embeddedServletContainer instanceof TomcatEmbeddedServletContainer) {
        return getManager((TomcatEmbeddedServletContainer) embeddedServletContainer);
    }
    return null;
}
项目:contestparser    文件:EmbeddedServerPortFileWriterTests.java   
private EmbeddedServletContainerInitializedEvent mockEvent(String name, int port) {
    EmbeddedWebApplicationContext applicationContext = mock(
            EmbeddedWebApplicationContext.class);
    EmbeddedServletContainer source = mock(EmbeddedServletContainer.class);
    given(applicationContext.getNamespace()).willReturn(name);
    given(source.getPort()).willReturn(port);
    EmbeddedServletContainerInitializedEvent event = new EmbeddedServletContainerInitializedEvent(
            applicationContext, source);
    return event;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EndpointWebMvcAutoConfigurationTests.java   
public EmbeddedServletContainer getServletContainer() {
    return this.servletContainer;
}
项目:spring-boot-concourse    文件:EndpointWebMvcAutoConfigurationTests.java   
public EmbeddedServletContainer getServletContainer() {
    return this.servletContainer;
}
项目:contestparser    文件:EndpointWebMvcAutoConfigurationTests.java   
public EmbeddedServletContainer getServletContainer() {
    return this.servletContainer;
}
项目:sdcct    文件:SdcctTomcatEmbeddedServletContainerFactory.java   
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer ... servletContextInits) {
    (this.tomcat = new Tomcat()).setBaseDir(this.baseDir.getAbsolutePath());

    Service service = this.tomcat.getService();

    Connector conn = new SdcctConnector();
    service.addConnector(conn);

    this.customizeConnector(conn);
    this.tomcat.setConnector(conn);

    Host host = this.tomcat.getHost();
    host.setAutoDeploy(false);

    this.tomcat.getEngine().setBackgroundProcessorDelay(-1);

    this.prepareContext(host, servletContextInits);

    return this.getTomcatEmbeddedServletContainer(this.tomcat);
}