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

项目:simple-hostel-management    文件:Utils.java   
/**
 * /!\ Work only if application run on embedded Tomcat server
 *
 * @return
 * @throws Exception
 */
public static String getBaseUrlForEmbeddedTomcat() throws Exception {

    // get embedded tomcat
    EmbeddedWebApplicationContext appContext = (EmbeddedWebApplicationContext) new ApplicationContextProvider().getApplicationContext();
    Tomcat tomcat = ((TomcatEmbeddedServletContainer) appContext.getEmbeddedServletContainer()).getTomcat();
    Connector connector = tomcat.getConnector();

    // compose address
    String scheme = connector.getScheme();
    String hostName = tomcat.getHost().getName();
    int port = connector.getPort();
    String contextPath = appContext.getServletContext().getContextPath();

    return scheme + "://" + hostName + ":" + port + contextPath;
}
项目: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;
}
项目:micrometer    文件:TomcatMetricsConfiguration.java   
private Manager getManagerFromContext(EmbeddedWebApplicationContext applicationContext) {
    EmbeddedServletContainer embeddedServletContainer = applicationContext.getEmbeddedServletContainer();
    if (embeddedServletContainer instanceof TomcatEmbeddedServletContainer) {
        return getManagerFromContainer((TomcatEmbeddedServletContainer) embeddedServletContainer);
    }
    return null;
}
项目:micrometer    文件:TomcatMetricsConfiguration.java   
private Manager getManagerFromContainer(TomcatEmbeddedServletContainer servletContainer) {
    for (Container container : servletContainer.getTomcat().getHost().findChildren()) {
        if (container instanceof Context) {
            return ((Context) container).getManager();
        }
    }
    return null;
}
项目:various_demos    文件:Application.java   
@Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
    return new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(
                Tomcat tomcat) {
            //tomcat.enableNaming();
            System.out.println("Enterring TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer()...");
            return super.getTomcatEmbeddedServletContainer(tomcat);
        }
    };
}
项目:various_demos    文件:EmbeddedTomcatConfig.java   
@Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
    return new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(
                Tomcat tomcat) {
            return super.getTomcatEmbeddedServletContainer(tomcat);
        }
    };
}
项目: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    文件:TomcatPublicMetrics.java   
private Manager getManager(TomcatEmbeddedServletContainer servletContainer) {
    for (Container container : servletContainer.getTomcat().getHost()
            .findChildren()) {
        if (container instanceof Context) {
            return ((Context) container).getManager();
        }
    }
    return null;
}
项目: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    文件:TomcatPublicMetrics.java   
private Manager getManager(TomcatEmbeddedServletContainer servletContainer) {
    for (Container container : servletContainer.getTomcat().getHost()
            .findChildren()) {
        if (container instanceof Context) {
            return ((Context) container).getManager();
        }
    }
    return null;
}
项目:contestparser    文件:TomcatPublicMetrics.java   
private Manager getManager(EmbeddedWebApplicationContext applicationContext) {
    EmbeddedServletContainer embeddedServletContainer = applicationContext
            .getEmbeddedServletContainer();
    if (embeddedServletContainer instanceof TomcatEmbeddedServletContainer) {
        return getManager((TomcatEmbeddedServletContainer) embeddedServletContainer);
    }
    return null;
}
项目:contestparser    文件:TomcatPublicMetrics.java   
private Manager getManager(TomcatEmbeddedServletContainer servletContainer) {
    for (Container container : servletContainer.getTomcat().getHost()
            .findChildren()) {
        if (container instanceof Context) {
            return ((Context) container).getManager();
        }
    }
    return null;
}
项目:kinota-server    文件:Application.java   
@Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
    return new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(
                Tomcat tomcat) {
            tomcat.enableNaming();
            return super.getTomcatEmbeddedServletContainer(tomcat);
        }

        @Override
        /**
         * Configure Tomcat connection pooling.  In the future other configuration parameters
         * could be added from https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html
         */
        protected void postProcessContext(Context context) {
            ContextResource r = new ContextResource();
            r.setName(env.getProperty("sta.datasource.name", "jdbc/sensorThings"));
            r.setAuth(env.getProperty("sta.datasource.auth", "Container"));
            r.setType(env.getProperty("sta.datasource.type", "javax.sql.DataSource"));
            r.setProperty("factory",
                    env.getProperty("sta.datasource.factory","org.apache.tomcat.jdbc.pool.DataSourceFactory"));
            r.setProperty("driverClassName",
                    env.getProperty("sta.datasource.driverClassName", "org.postgresql.Driver"));
            r.setProperty("url",
                    env.getProperty("sta.datasource.url", "jdbc:postgresql://localhost:5432/sensorthings"));
            r.setProperty("username",
                    env.getProperty("sta.datasource.username", "sensorthings"));
            r.setProperty("password",
                    env.getProperty("sta.datasource.password", "ChangeMe!"));
            r.setProperty("maxTotal",
                    env.getProperty("sta.datasource.maxTotal", "20"));
            r.setProperty("maxIdle",
                    env.getProperty("sta.datasource.maxIdle", "10"));
            r.setProperty("maxWaitMillis",
                    env.getProperty("sta.datasource.maxWaitMillis", "-1"));
            r.setProperty("defaultAutoCommit",
                    env.getProperty("sta.datasource.defaultAutoCommit", "false"));
            r.setProperty("testOnBorrow",
                    env.getProperty("sta.datasource.testOnBorrow", "true"));
            r.setProperty("validationQuery",
                    env.getProperty("sta.datasource.validationQuery", "SELECT 1;"));
            r.setProperty("validationInterval",
                    env.getProperty("sta.datasource.validationInterval", "5000"));

            context.getNamingResources().addResource(r);
        }
    };
}
项目:awesome-agile    文件:SslRedirectConfig.java   
@Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
    return new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(
                Tomcat tomcat) {
            Server server = tomcat.getServer();

            Service service = new StandardService();
            service.setName("ssl-redirect-service");
            Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
            connector.setPort(sslRedirectPort);
            service.addConnector(connector);
            server.addService(service);

            Engine engine = new StandardEngine();
            service.setContainer(engine);

            Host host = new StandardHost();
            host.setName("ssl-redirect-host");
            engine.addChild(host);
            engine.setDefaultHost(host.getName());

            Context context = new StandardContext();
            context.addLifecycleListener(new Tomcat.FixContextListener());
            context.setName("ssl-redirect-context");
            context.setPath("");
            host.addChild(context);

            Wrapper wrapper = context.createWrapper();
            wrapper.setServlet(new HttpServlet() {
                @Override
                public void service(HttpServletRequest req, HttpServletResponse res)
                        throws ServletException, IOException {
                    ServletServerHttpRequest r = new ServletServerHttpRequest(req);
                    UriComponentsBuilder b = UriComponentsBuilder.fromHttpRequest(r);
                    b.scheme("https");
                    b.port(null);
                    res.sendRedirect(b.toUriString());
                }
            });
            wrapper.setName("ssl-redirect-servlet");
            context.addChild(wrapper);
            context.addServletMapping("/", wrapper.getName());

            return super.getTomcatEmbeddedServletContainer(tomcat);
        }
    };
}