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

项目:mxhsd    文件:MxhsdFederationApp.java   
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();

    tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
        connector.setScheme("https");
        connector.setPort(cfg.getPort());
        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
        protocol.setSSLEnabled(true);
        protocol.setSSLCertificateKeyFile(cfg.getKey());
        protocol.setSSLCertificateFile(cfg.getCert());
        cfg.getChain().ifPresent(protocol::setSSLCertificateChainFile);
    });

    return tomcat;
}
项目:cas-5.1.0    文件:CasEmbeddedContainerTomcatConfiguration.java   
private void configureRewriteValve(final TomcatEmbeddedServletContainerFactory tomcat) {
    final Resource res = casProperties.getServer().getRewriteValveConfigLocation();
    if (ResourceUtils.doesResourceExist(res)) {
        final RewriteValve valve = new RewriteValve() {
            @Override
            protected synchronized void startInternal() throws LifecycleException {
                super.startInternal();
                try (InputStream is = res.getInputStream();
                     InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
                     BufferedReader buffer = new BufferedReader(isr)) {
                    parse(buffer);
                } catch (final Exception e) {
                    throw Throwables.propagate(e);
                }
            }
        };
        valve.setAsyncSupported(true);
        valve.setEnabled(true);

        LOGGER.debug("Creating Rewrite valve configuration for the embedded tomcat container...");
        tomcat.addContextValves(valve);
    }
}
项目:cas-5.1.0    文件:CasEmbeddedContainerTomcatConfiguration.java   
private void configureExtendedAccessLogValve(final TomcatEmbeddedServletContainerFactory tomcat) {
    final CasServerProperties.ExtendedAccessLog ext = casProperties.getServer().getExtAccessLog();

    if (ext.isEnabled() && StringUtils.isNotBlank(ext.getPattern())) {
        LOGGER.debug("Creating extended access log valve configuration for the embedded tomcat container...");
        final ExtendedAccessLogValve valve = new ExtendedAccessLogValve();
        valve.setPattern(ext.getPattern());

        if (StringUtils.isBlank(ext.getDirectory())) {
            valve.setDirectory(serverProperties.getTomcat().getAccesslog().getDirectory());
        } else {
            valve.setDirectory(ext.getDirectory());
        }
        valve.setPrefix(ext.getPrefix());
        valve.setSuffix(ext.getSuffix());
        valve.setAsyncSupported(true);
        valve.setEnabled(true);
        valve.setRotatable(true);
        valve.setBuffered(true);
        tomcat.addContextValves(valve);
        tomcat.addEngineValves(valve);
    }
}
项目:cas-5.1.0    文件:CasEmbeddedContainerTomcatConfiguration.java   
private void configureHttp(final TomcatEmbeddedServletContainerFactory tomcat) {
    final CasServerProperties.Http http = casProperties.getServer().getHttp();
    if (http.isEnabled()) {
        LOGGER.debug("Creating HTTP configuration for the embedded tomcat container...");
        final Connector connector = new Connector(http.getProtocol());
        int port = http.getPort();
        if (port <= 0) {
            LOGGER.warn("No explicit port configuration is provided to CAS. Scanning for available ports...");
            port = SocketUtils.findAvailableTcpPort();
        }
        LOGGER.info("Activated embedded tomcat container HTTP port to [{}]", port);
        connector.setPort(port);

        LOGGER.debug("Configuring embedded tomcat container for HTTP2 protocol support");
        connector.addUpgradeProtocol(new Http2Protocol());

        http.getAttributes().forEach(connector::setAttribute);
        tomcat.addAdditionalTomcatConnectors(connector);
    }
}
项目:spring-boot-starter-purge-accesslog    文件:PurgeAccessLogAutoConfiguration.java   
/**
 * Purge access log customizer embedded servlet container customizer.
 *
 * @param serverProperties the server properties
 * @param purgeProperties  the purge properties
 * @return the embedded servlet container customizer
 */
@Bean
public EmbeddedServletContainerCustomizer purgeAccessLogCustomizer(
        final ServerProperties serverProperties,
        final PurgeProperties purgeProperties) {
    return container -> {
        final TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory) container;
        final Accesslog accesslog = serverProperties.getTomcat().getAccesslog();
        factory.getEngineValves().stream()
                .filter(valve -> valve instanceof AccessLogValve)
                .map(valve -> (AccessLogValve) valve).findFirst()
                .ifPresent(valve -> {
                    final TomcatPurgeAccessLogHolder accessLogHolder = new TomcatPurgeAccessLogHolder(
                            purgeProperties, Paths.get(accesslog.getDirectory()),
                            accesslog.getPrefix(), accesslog.getSuffix(), valve);
                    factory.addContextCustomizers(accessLogHolder);
                });
    };
}
项目:karate    文件:TomcatConfig.java   
@Bean
public EmbeddedServletContainerCustomizer cookieProcessorCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            if (container instanceof TomcatEmbeddedServletContainerFactory) {
                TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory) container;
                factory.addContextCustomizers(new TomcatContextCustomizer() {
                    @Override
                    public void customize(Context context) {
                        context.setCookieProcessor(new LegacyCookieProcessor());
                    }                        
                });
            }
        }

    };
}
项目:hungrydragon    文件:TomcatConfig.java   
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };

    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    return tomcat;
}
项目:MicroServiceDemo    文件:WebMvcConfig.java   
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };

    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    return tomcat;
}
项目:smarti    文件:TomcatConfiguration.java   
@Bean
public EmbeddedServletContainerFactory servletContainer() {

    final TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    if (isEnabled()) {
        final Connector ajpConnector = new Connector(getProtocol());
        ajpConnector.setPort(getPort());
        ajpConnector.setSecure(isSecure());
        ajpConnector.setAllowTrace(isAllowTrace());
        ajpConnector.setScheme(getScheme());

        tomcat.addAdditionalTomcatConnectors(ajpConnector);
    }

    return tomcat;
}
项目:apollo-custom    文件:TomcatContainerCustomizer.java   
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
  if (!(container instanceof TomcatEmbeddedServletContainerFactory)) {
    return;
  }
  if (!environment.containsProperty(TOMCAT_ACCEPTOR_COUNT)) {
    return;
  }
  TomcatEmbeddedServletContainerFactory tomcat =
      (TomcatEmbeddedServletContainerFactory) container;
  tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {
    @Override
    public void customize(Connector connector) {
      ProtocolHandler handler = connector.getProtocolHandler();
      if (handler instanceof Http11NioProtocol) {
        Http11NioProtocol http = (Http11NioProtocol) handler;
        int acceptCount = Integer.parseInt(environment.getProperty(TOMCAT_ACCEPTOR_COUNT));
        http.setBacklog(acceptCount);
        logger.info("Setting tomcat accept count to {}", acceptCount);
      }

    }
  });
}
项目:tip    文件:TomcatWebConfig.java   
@Bean
public EmbeddedServletContainerFactory servletContainer(SslProperties properties) {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    return tomcat;
}
项目:various_demos    文件:Application.java   
@Bean
public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            if (container instanceof TomcatEmbeddedServletContainerFactory) {
                TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = (TomcatEmbeddedServletContainerFactory) container;


                RedisSessionHandlerValve valve = new RedisSessionHandlerValve();
                List<RedisSessionHandlerValve> valves = 
                        new ArrayList<RedisSessionHandlerValve>();
                valves.add(0, valve);
                tomcatEmbeddedServletContainerFactory.setContextValves(valves);
                tomcatEmbeddedServletContainerFactory.setPort(28080);    // Set the port of embeded tomcat as 28080 for default. 

                System.out.println("Enterring EmbeddedServletContainerCustomizer.customize()...");
                tomcatEmbeddedServletContainerFactory.addContextCustomizers(
                        new ServletContainerCustomizer());
            }
        }
    };
}
项目:various_demos    文件:EmbeddedTomcatConfig.java   
@Bean
public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        @Value("${application.port}")
        private int embeddedServletContainerListenPort;

        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            if (container instanceof TomcatEmbeddedServletContainerFactory) {
                TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = 
                        (TomcatEmbeddedServletContainerFactory) container;
                if (embeddedServletContainerListenPort <= 1024 ||  embeddedServletContainerListenPort > 65535) {
                    throw new IllegalArgumentException("The value of \"application.port\" in the properties file is invalid.");
                }

                tomcatEmbeddedServletContainerFactory.setPort(embeddedServletContainerListenPort);
            }
        }
    };
}
项目:apollo    文件:TomcatContainerCustomizer.java   
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
  if (!(container instanceof TomcatEmbeddedServletContainerFactory)) {
    return;
  }
  if (!environment.containsProperty(TOMCAT_ACCEPTOR_COUNT)) {
    return;
  }
  TomcatEmbeddedServletContainerFactory tomcat =
      (TomcatEmbeddedServletContainerFactory) container;
  tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {
    @Override
    public void customize(Connector connector) {
      ProtocolHandler handler = connector.getProtocolHandler();
      if (handler instanceof Http11NioProtocol) {
        Http11NioProtocol http = (Http11NioProtocol) handler;
        int acceptCount = Integer.parseInt(environment.getProperty(TOMCAT_ACCEPTOR_COUNT));
        http.setBacklog(acceptCount);
        logger.info("Setting tomcat accept count to {}", acceptCount);
      }

    }
  });
}
项目:interview-preparation    文件:DispatchServletConfig.java   
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    final TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
    // tomcatFactory.setAddress(InetAddress.getLocalHost());// you can restrict localhost access
    tomcatFactory.setPort(8080);
    // ServletContainerInitializer

    final Connector connector = new Connector();
    connector.setPort(8443);
    connector.setSecure(true);
    connector.setScheme("https");
    connector.setProperty("SSLEnabled", "true");
    connector.setProperty("keystorePass", "spring");
    try {
        final ClassPathResource classPathResource = new ClassPathResource("keystore");
        System.err.println(classPathResource.getFile().getAbsolutePath());
        connector.setProperty("keystoreFile", classPathResource.getFile().getAbsolutePath());
    } catch (final Exception e) {
        System.err.println("Error while loading classpath resource " + e.getMessage());
    }

    tomcatFactory.addAdditionalTomcatConnectors(connector);
    return tomcatFactory;
}
项目:metasfresh-webui-api    文件:WebRestApiApplication.java   
@Bean
public EmbeddedServletContainerCustomizer servletContainerCustomizer()
{
    return new EmbeddedServletContainerCustomizer()
    {
        @Override
        public void customize(final ConfigurableEmbeddedServletContainer servletContainer)
        {
            final TomcatEmbeddedServletContainerFactory tomcatContainerFactory = (TomcatEmbeddedServletContainerFactory)servletContainer;
            tomcatContainerFactory.addConnectorCustomizers(new TomcatConnectorCustomizer()
            {
                @Override
                public void customize(final Connector connector)
                {
                    final AbstractHttp11Protocol<?> httpProtocol = (AbstractHttp11Protocol<?>)connector.getProtocolHandler();
                    httpProtocol.setCompression("on");
                    httpProtocol.setCompressionMinSize(256);
                    final String mimeTypes = httpProtocol.getCompressibleMimeType();
                    final String mimeTypesWithJson = mimeTypes + "," + MediaType.APPLICATION_JSON_VALUE + ",application/javascript";
                    httpProtocol.setCompressibleMimeType(mimeTypesWithJson);
                }
            });
        }
    };
}
项目:springsecuredthymeleafapp    文件:WebConfiguration.java   
/**
 * <p>servletContainer.</p>
 *
 * @return a {@link org.springframework.boot.context.embedded.EmbeddedServletContainerFactory} object.
 */
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };

    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    return tomcat;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServerProperties.java   
private void customizeRemoteIpValve(ServerProperties properties,
        TomcatEmbeddedServletContainerFactory factory) {
    String protocolHeader = getProtocolHeader();
    String remoteIpHeader = getRemoteIpHeader();
    // For back compatibility the valve is also enabled if protocol-header is set
    if (StringUtils.hasText(protocolHeader) || StringUtils.hasText(remoteIpHeader)
            || properties.getOrDeduceUseForwardHeaders()) {
        RemoteIpValve valve = new RemoteIpValve();
        valve.setProtocolHeader(StringUtils.hasLength(protocolHeader)
                ? protocolHeader : "X-Forwarded-Proto");
        if (StringUtils.hasLength(remoteIpHeader)) {
            valve.setRemoteIpHeader(remoteIpHeader);
        }
        // The internal proxies default to a white list of "safe" internal IP
        // addresses
        valve.setInternalProxies(getInternalProxies());
        valve.setPortHeader(getPortHeader());
        valve.setProtocolHeaderHttpsValue(getProtocolHeaderHttpsValue());
        // ... so it's safe to add this valve by default.
        factory.addEngineValves(valve);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServerProperties.java   
@SuppressWarnings("rawtypes")
private void customizeMaxHttpHeaderSize(
        TomcatEmbeddedServletContainerFactory factory,
        final int maxHttpHeaderSize) {
    factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {

        @Override
        public void customize(Connector connector) {
            ProtocolHandler handler = connector.getProtocolHandler();
            if (handler instanceof AbstractHttp11Protocol) {
                AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
                protocol.setMaxHttpHeaderSize(maxHttpHeaderSize);
            }
        }

    });
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServerPropertiesTests.java   
@Test
public void redirectContextRootCanBeConfigured() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("server.tomcat.redirect-context-root", "false");
    bindProperties(map);
    ServerProperties.Tomcat tomcat = this.properties.getTomcat();
    assertThat(tomcat.getRedirectContextRoot()).isEqualTo(false);
    TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
    this.properties.customize(container);
    Context context = mock(Context.class);
    for (TomcatContextCustomizer customizer : container
            .getTomcatContextCustomizers()) {
        customizer.customize(context);
    }
    verify(context).setMapperContextRootRedirectEnabled(false);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServerPropertiesTests.java   
private void testRemoteIpValveConfigured() {
    TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
    this.properties.customize(container);
    assertThat(container.getEngineValves()).hasSize(1);
    Valve valve = container.getEngineValves().iterator().next();
    assertThat(valve).isInstanceOf(RemoteIpValve.class);
    RemoteIpValve remoteIpValve = (RemoteIpValve) valve;
    assertThat(remoteIpValve.getProtocolHeader()).isEqualTo("X-Forwarded-Proto");
    assertThat(remoteIpValve.getProtocolHeaderHttpsValue()).isEqualTo("https");
    assertThat(remoteIpValve.getRemoteIpHeader()).isEqualTo("X-Forwarded-For");
    String expectedInternalProxies = "10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" // 10/8
            + "192\\.168\\.\\d{1,3}\\.\\d{1,3}|" // 192.168/16
            + "169\\.254\\.\\d{1,3}\\.\\d{1,3}|" // 169.254/16
            + "127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" // 127/8
            + "172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|" // 172.16/12
            + "172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|"
            + "172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3}";
    assertThat(remoteIpValve.getInternalProxies()).isEqualTo(expectedInternalProxies);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServerPropertiesTests.java   
@Test
public void customTomcatRemoteIpValve() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("server.tomcat.remote_ip_header", "x-my-remote-ip-header");
    map.put("server.tomcat.protocol_header", "x-my-protocol-header");
    map.put("server.tomcat.internal_proxies", "192.168.0.1");
    map.put("server.tomcat.port-header", "x-my-forward-port");
    map.put("server.tomcat.protocol-header-https-value", "On");
    bindProperties(map);

    TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
    this.properties.customize(container);

    assertThat(container.getEngineValves()).hasSize(1);
    Valve valve = container.getEngineValves().iterator().next();
    assertThat(valve).isInstanceOf(RemoteIpValve.class);
    RemoteIpValve remoteIpValve = (RemoteIpValve) valve;
    assertThat(remoteIpValve.getProtocolHeader()).isEqualTo("x-my-protocol-header");
    assertThat(remoteIpValve.getProtocolHeaderHttpsValue()).isEqualTo("On");
    assertThat(remoteIpValve.getRemoteIpHeader()).isEqualTo("x-my-remote-ip-header");
    assertThat(remoteIpValve.getPortHeader()).isEqualTo("x-my-forward-port");
    assertThat(remoteIpValve.getInternalProxies()).isEqualTo("192.168.0.1");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JerseyAutoConfigurationServletContainerTests.java   
@Bean
public TomcatEmbeddedServletContainerFactory tomcat() {
    return new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected void postProcessContext(Context context) {
            Wrapper jerseyServlet = context.createWrapper();
            String servletName = Application.class.getName();
            jerseyServlet.setName(servletName);
            jerseyServlet.setServletClass(ServletContainer.class.getName());
            jerseyServlet.setServlet(new ServletContainer());
            jerseyServlet.setOverridable(false);
            context.addChild(jerseyServlet);
            context.addServletMapping("/*", servletName);
        }

    };
}
项目:findlunch    文件:Beans.java   
/**
 * Container customizer. Configures the embedded tomcat (e.g. post size)
 *
 * @return the embedded servlet container customizer
 * @throws Exception the exception
 */
@Bean 
public EmbeddedServletContainerCustomizer containerCustomizer(
        ) throws Exception {


      return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {

              if (container instanceof TomcatEmbeddedServletContainerFactory) {

                  TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
                  tomcat.addConnectorCustomizers(
                          new TomcatConnectorCustomizer() {
                            @Override
                            public void customize(Connector connector) {
                                  connector.setMaxPostSize(20000000);//20MB
                              }
                        }
                  );
              }
          }
    };
  }
项目:edge-server    文件:WebConfig.java   
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    return tomcat;
}
项目:mdw    文件:SpringBootApplication.java   
/**
 * TODO: support Jetty as well
 */
@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory(ApplicationContext ctx) {
    String portProp = System.getProperty("mdw.server.port");
    if (portProp == null)
        portProp = System.getProperty("server.port");
    if (portProp == null)
        portProp = "8080";
    String contextProp = System.getProperty("mdw.server.contextPath");
    if (contextProp == null)
        contextProp = System.getProperty("server.contextPath");
    if (contextProp == null)
        contextProp = "/mdw";
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory(
            contextProp, Integer.parseInt(portProp));
    factory.addContextCustomizers(tomcatContextCustomizer());
    factory.setDocumentRoot(new File(getBootDir() + "/web"));
    return factory;
}
项目:spring-boot-concourse    文件:ServerProperties.java   
private void customizeRemoteIpValve(ServerProperties properties,
        TomcatEmbeddedServletContainerFactory factory) {
    String protocolHeader = getProtocolHeader();
    String remoteIpHeader = getRemoteIpHeader();
    // For back compatibility the valve is also enabled if protocol-header is set
    if (StringUtils.hasText(protocolHeader) || StringUtils.hasText(remoteIpHeader)
            || properties.getOrDeduceUseForwardHeaders()) {
        RemoteIpValve valve = new RemoteIpValve();
        valve.setProtocolHeader(StringUtils.hasLength(protocolHeader)
                ? protocolHeader : "X-Forwarded-Proto");
        if (StringUtils.hasLength(remoteIpHeader)) {
            valve.setRemoteIpHeader(remoteIpHeader);
        }
        // The internal proxies default to a white list of "safe" internal IP
        // addresses
        valve.setInternalProxies(getInternalProxies());
        valve.setPortHeader(getPortHeader());
        valve.setProtocolHeaderHttpsValue(getProtocolHeaderHttpsValue());
        // ... so it's safe to add this valve by default.
        factory.addContextValves(valve);
    }
}
项目:spring-boot-concourse    文件:ServerProperties.java   
@SuppressWarnings("rawtypes")
private void customizeMaxHttpHeaderSize(
        TomcatEmbeddedServletContainerFactory factory,
        final int maxHttpHeaderSize) {
    factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {

        @Override
        public void customize(Connector connector) {
            ProtocolHandler handler = connector.getProtocolHandler();
            if (handler instanceof AbstractHttp11Protocol) {
                AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
                protocol.setMaxHttpHeaderSize(maxHttpHeaderSize);
            }
        }

    });
}
项目:spring-boot-concourse    文件:ServerPropertiesTests.java   
private void testRemoteIpValveConfigured() {
    TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
    this.properties.customize(container);
    assertThat(container.getValves()).hasSize(1);
    Valve valve = container.getValves().iterator().next();
    assertThat(valve).isInstanceOf(RemoteIpValve.class);
    RemoteIpValve remoteIpValve = (RemoteIpValve) valve;
    assertThat(remoteIpValve.getProtocolHeader()).isEqualTo("X-Forwarded-Proto");
    assertThat(remoteIpValve.getProtocolHeaderHttpsValue()).isEqualTo("https");
    assertThat(remoteIpValve.getRemoteIpHeader()).isEqualTo("X-Forwarded-For");
    String expectedInternalProxies = "10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" // 10/8
            + "192\\.168\\.\\d{1,3}\\.\\d{1,3}|" // 192.168/16
            + "169\\.254\\.\\d{1,3}\\.\\d{1,3}|" // 169.254/16
            + "127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" // 127/8
            + "172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|" // 172.16/12
            + "172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|"
            + "172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3}";
    assertThat(remoteIpValve.getInternalProxies()).isEqualTo(expectedInternalProxies);
}
项目:spring-boot-concourse    文件:ServerPropertiesTests.java   
@Test
public void customTomcatRemoteIpValve() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("server.tomcat.remote_ip_header", "x-my-remote-ip-header");
    map.put("server.tomcat.protocol_header", "x-my-protocol-header");
    map.put("server.tomcat.internal_proxies", "192.168.0.1");
    map.put("server.tomcat.port-header", "x-my-forward-port");
    map.put("server.tomcat.protocol-header-https-value", "On");
    bindProperties(map);

    TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
    this.properties.customize(container);

    assertThat(container.getValves()).hasSize(1);
    Valve valve = container.getValves().iterator().next();
    assertThat(valve).isInstanceOf(RemoteIpValve.class);
    RemoteIpValve remoteIpValve = (RemoteIpValve) valve;
    assertThat(remoteIpValve.getProtocolHeader()).isEqualTo("x-my-protocol-header");
    assertThat(remoteIpValve.getProtocolHeaderHttpsValue()).isEqualTo("On");
    assertThat(remoteIpValve.getRemoteIpHeader()).isEqualTo("x-my-remote-ip-header");
    assertThat(remoteIpValve.getPortHeader()).isEqualTo("x-my-forward-port");
    assertThat(remoteIpValve.getInternalProxies()).isEqualTo("192.168.0.1");
}
项目:spring-boot-concourse    文件:JerseyAutoConfigurationServletContainerTests.java   
@Bean
public TomcatEmbeddedServletContainerFactory tomcat() {
    return new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected void postProcessContext(Context context) {
            Wrapper jerseyServlet = context.createWrapper();
            String servletName = Application.class.getName();
            jerseyServlet.setName(servletName);
            jerseyServlet.setServletClass(ServletContainer.class.getName());
            jerseyServlet.setServlet(new ServletContainer());
            jerseyServlet.setOverridable(false);
            context.addChild(jerseyServlet);
            context.addServletMapping("/*", servletName);
        }

    };
}
项目:danyuan-application    文件:App.java   
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint constraint = new SecurityConstraint();
            constraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            constraint.addCollection(collection);
            context.addConstraint(constraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(httpConnector());
    return tomcat;
}
项目:springboot-shiro-cas-mybatis    文件:CustomizationBean.java   
/**
 * 定制方法二:注入EmbeddedServletContainerFactory
 * @return
 */
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
    factory.setPort(8083);
    factory.setSessionTimeout(10, TimeUnit.MINUTES);
    //优先级高于配置在/static/error文件夹里面的404.html页面
    factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/403.html"));
    return factory;
}
项目:cas-5.1.0    文件:CasEmbeddedContainerTomcatConfiguration.java   
@ConditionalOnClass(value = {Tomcat.class, Http2Protocol.class})
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    final TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();

    configureAjp(tomcat);
    configureHttp(tomcat);
    configureHttpProxy(tomcat);
    configureExtendedAccessLogValve(tomcat);
    configureRewriteValve(tomcat);
    configureSSLValve(tomcat);

    return tomcat;
}
项目:cas-5.1.0    文件:CasEmbeddedContainerTomcatConfiguration.java   
private void configureHttpProxy(final TomcatEmbeddedServletContainerFactory tomcat) {
    final CasServerProperties.HttpProxy proxy = casProperties.getServer().getHttpProxy();
    if (proxy.isEnabled()) {
        LOGGER.debug("Customizing HTTP proxying for connector listening on port [{}]", tomcat.getPort());
        tomcat.getTomcatConnectorCustomizers().add(connector -> {
            connector.setSecure(proxy.isSecure());
            connector.setScheme(proxy.getScheme());

            if (StringUtils.isNotBlank(proxy.getProtocol())) {
                LOGGER.debug("Setting HTTP proxying protocol to [{}]", proxy.getProtocol());
                connector.setProtocol(proxy.getProtocol());
            }
            if (proxy.getRedirectPort() > 0) {
                LOGGER.debug("Setting HTTP proxying redirect port to [{}]", proxy.getRedirectPort());
                connector.setRedirectPort(proxy.getRedirectPort());
            }
            if (proxy.getProxyPort() > 0) {
                LOGGER.debug("Setting HTTP proxying proxy port to [{}]", proxy.getProxyPort());
                connector.setProxyPort(proxy.getProxyPort());
            }

            proxy.getAttributes().forEach(connector::setAttribute);
            LOGGER.info("Configured connector listening on port [{}]", tomcat.getPort());
        });
    } else {
        LOGGER.debug("HTTP proxying is not enabled for CAS; Connector configuration for port [{}] is not modified.", tomcat.getPort());
    }
}
项目:cas-5.1.0    文件:CasEmbeddedContainerTomcatConfiguration.java   
private void configureAjp(final TomcatEmbeddedServletContainerFactory tomcat) {
    final CasServerProperties.Ajp ajp = casProperties.getServer().getAjp();
    if (ajp.isEnabled() && ajp.getPort() > 0) {
        LOGGER.debug("Creating AJP configuration for the embedded tomcat container...");
        final Connector ajpConnector = new Connector(ajp.getProtocol());
        ajpConnector.setProtocol(ajp.getProtocol());
        ajpConnector.setPort(ajp.getPort());
        ajpConnector.setSecure(ajp.isSecure());
        ajpConnector.setAllowTrace(ajp.isAllowTrace());
        ajpConnector.setScheme(ajp.getScheme());
        if (ajp.getAsyncTimeout() > 0) {
            ajpConnector.setAsyncTimeout(ajp.getAsyncTimeout());
        }
        ajpConnector.setEnableLookups(ajp.isEnableLookups());
        if (ajp.getMaxPostSize() > 0) {
            ajpConnector.setMaxPostSize(ajp.getMaxPostSize());
        }
        ajpConnector.addUpgradeProtocol(new Http2Protocol());

        if (ajp.getProxyPort() > 0) {
            LOGGER.debug("Set AJP proxy port to [{}]", ajp.getProxyPort());
            ajpConnector.setProxyPort(ajp.getProxyPort());
        }

        if (ajp.getRedirectPort() > 0) {
            LOGGER.debug("Set AJP redirect port to [{}]", ajp.getRedirectPort());
            ajpConnector.setRedirectPort(ajp.getRedirectPort());
        }

        ajp.getAttributes().forEach(ajpConnector::setAttribute);

        tomcat.addAdditionalTomcatConnectors(ajpConnector);
    }
}
项目:cas-5.1.0    文件:CasEmbeddedContainerTomcatConfiguration.java   
private void configureSSLValve(final TomcatEmbeddedServletContainerFactory tomcat) {
    final CasServerProperties.SslValve valveConfig = casProperties.getServer().getSslValve();

    if (valveConfig.isEnabled()) {
        LOGGER.debug("Adding SSLValve to engine of the embedded tomcat container...");
        final SSLValve valve = new SSLValve();
        valve.setSslCipherHeader(valveConfig.getSslCipherHeader());
        valve.setSslCipherUserKeySizeHeader(valveConfig.getSslCipherUserKeySizeHeader());
        valve.setSslClientCertHeader(valveConfig.getSslClientCertHeader());
        valve.setSslSessionIdHeader(valveConfig.getSslSessionIdHeader());
        tomcat.addEngineValves(valve);
    }
}
项目:fiery    文件:RagnarApplication.java   
@Bean
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
    return (ConfigurableEmbeddedServletContainer container) -> {
        if (container instanceof TomcatEmbeddedServletContainerFactory) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addConnectorCustomizers(
                    (connector) -> {
                        connector.setMaxPostSize(1000000000); // 1000 MB
                    }
            );
        }
    };
}
项目:airsonic    文件:TomcatApplication.java   
public static void configure(TomcatEmbeddedServletContainerFactory tomcatFactory) {

            tomcatFactory.addContextCustomizers((TomcatContextCustomizer) context -> {

                boolean development = (System.getProperty("airsonic.development") != null);

                // Increase the size and time before eviction of the Tomcat
                // cache so that resources aren't uncompressed too often.
                // See https://github.com/jhipster/generator-jhipster/issues/3995

                StandardRoot resources = new StandardRoot();
                if (development) {
                    resources.setCachingAllowed(false);
                } else {
                    resources.setCacheMaxSize(100000);
                    resources.setCacheObjectMaxSize(4000);
                    resources.setCacheTtl(24 * 3600 * 1000);  // 1 day, in milliseconds
                }
                context.setResources(resources);

                // Put Jasper in production mode so that JSP aren't recompiled
                // on each request.
                // See http://stackoverflow.com/questions/29653326/spring-boot-application-slow-because-of-jsp-compilation
                Container jsp = context.findChild("jsp");
                if (jsp instanceof Wrapper) {
                    ((Wrapper) jsp).addInitParameter("development", Boolean.toString(development));
                }
            });
    }
项目:mxhsd    文件:MxhsdClientApp.java   
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();

    tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
        connector.setScheme("http");
        connector.setPort(cfg.getPort());
    });

    return tomcat;
}