org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer Java Examples

The following examples show how to use org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProxiesAutoConfiguration.java    From booties with Apache License 2.0 6 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer() {

    return new EmbeddedServletContainerCustomizer() {

        @Override
        public void customize(final ConfigurableEmbeddedServletContainer container) {
            if (container instanceof TomcatEmbeddedServletContainerFactory) {
                TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
                for (TomcatConnectorCustomizer customizer : tomcatConnectorCustomizers) {
                    tomcat.addConnectorCustomizers(customizer);
                }
            }
        }
    };
}
 
Example #2
Source File: TomcatContainerCustomizer.java    From radar with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
	MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
	mappings.add("woff", "application/x-font-woff");
	mappings.add("eot", "application/vnd.ms-fontobject");
	mappings.add("ttf", "application/x-font-ttf");
	container.setMimeMappings(mappings);

	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;
				acceptCount = soaConfig.getTomcatAcceptCount();
				soaConfig.registerChanged(() -> {
					if (acceptCount != soaConfig.getTomcatAcceptCount()) {
						acceptCount = soaConfig.getTomcatAcceptCount();
						http.setBacklog(acceptCount);
					}
				});
				http.setBacklog(acceptCount);
				logger.info("Setting tomcat accept count to {}", acceptCount);
			}
		}
	});
}
 
Example #3
Source File: WebConfig.java    From yfs with Apache License 2.0 5 votes vote down vote up
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
        // configure maxSwallowSize
        if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
            // -1 means unlimited, accept bytes
            ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
        }
    });
    return tomcat;
}
 
Example #4
Source File: OAuth2SecurityConfiguration.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
@Bean
  EmbeddedServletContainerCustomizer containerCustomizer(
          @Value("${keystore.file:src/main/resources/private/keystore}") String keystoreFile,
          @Value("${keystore.pass:changeit}") final String keystorePass) throws Exception {

// If you were going to reuse this class in another
// application, this is one of the key sections that you
// would want to change
  	
      final String absoluteKeystoreFile = new File(keystoreFile).getAbsolutePath();

      return new EmbeddedServletContainerCustomizer () {

	@Override
	public void customize(ConfigurableEmbeddedServletContainer container) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addConnectorCustomizers(
                    new TomcatConnectorCustomizer() {
						@Override
						public void customize(Connector connector) {
							connector.setPort(8443);
	                        connector.setSecure(true);
	                        connector.setScheme("https");

	                        Http11NioProtocol proto = (Http11NioProtocol) connector.getProtocolHandler();
	                        proto.setSSLEnabled(true);
	                        proto.setKeystoreFile(absoluteKeystoreFile);
	                        proto.setKeystorePass(keystorePass);
	                        proto.setKeystoreType("JKS");
	                        proto.setKeyAlias("tomcat");
						}
                    });
    
	}
      };
  }
 
Example #5
Source File: Port80ServletContainerCustomizer.java    From JSF-on-Spring-Boot with GNU General Public License v3.0 5 votes vote down vote up
public void customizeTomcat(TomcatEmbeddedServletContainerFactory factory) {
    factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
      @Override
      public void customize(Connector connector) {
    	  connector.setPort(80);
//        Object defaultMaxThreads = connector.getAttribute("maxThreads");
//        connector.getAttribute("javax.faces.CLIENT_WINDOW_MODE")
        connector.setAttribute("maxThreads", MAX_THREADS);
      }
    });
  }
 
Example #6
Source File: MyEmbeddedServletContainerCustomizer.java    From blog-non-blocking-rest-service-with-spring-mvc with Apache License 2.0 5 votes vote down vote up
public void customizeTomcat(TomcatEmbeddedServletContainerFactory factory) {
    factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
        @Override
        public void customize(Connector connector) {
            Object defaultMaxThreads = connector.getAttribute("maxThreads");
            connector.setAttribute("maxThreads", MAX_THREADS);
            LOG.info("Changed Tomcat connector maxThreads from " + defaultMaxThreads + " to " + MAX_THREADS);
        }
    });
}
 
Example #7
Source File: MyEmbeddedServletContainerCustomizer.java    From blog-non-blocking-rest-service-with-spring-mvc with Apache License 2.0 5 votes vote down vote up
public void customizeTomcat(TomcatEmbeddedServletContainerFactory factory) {
    factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
        @Override
        public void customize(Connector connector) {
            Object defaultMaxThreads = connector.getAttribute("maxThreads");
            connector.setAttribute("maxThreads", MAX_THREADS);
            LOG.info("Changed Tomcat connector maxThreads from " + defaultMaxThreads + " to " + MAX_THREADS);
        }
    });
}
 
Example #8
Source File: TomcatContainerCustomizer.java    From pmq with Apache License 2.0 4 votes vote down vote up
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
	MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
	mappings.add("woff", "application/x-font-woff");
	mappings.add("eot", "application/vnd.ms-fontobject");
	mappings.add("ttf", "application/x-font-ttf");
	container.setMimeMappings(mappings);

	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;
				acceptCount = soaConfig.getTomcatAcceptCount();
				maxThreads = soaConfig.getTomcatMaxThreads();
				minThreads = soaConfig.getTomcatMinThreads();
				soaConfig.registerChanged(() -> {						
					if (maxThreads != soaConfig.getTomcatMaxThreads()) {
						maxThreads = soaConfig.getTomcatMaxThreads();
						if (maxThreads > 0) {
							http.setMaxThreads(maxThreads);
						} else {
							http.setMaxThreads(200);
						}
					}
					if (minThreads != soaConfig.getTomcatMinThreads()) {
						minThreads = soaConfig.getTomcatMinThreads();
						if (minThreads > 0) {
							http.setMinSpareThreads(minThreads);
						} else {
							http.setMinSpareThreads(10);
						}
					}


				});
				http.setBacklog(acceptCount);
				http.setMaxThreads(maxThreads);
				http.setMinSpareThreads(minThreads);
				logger.info("Setting tomcat accept count to {}", acceptCount);
			}
		}
	});
}
 
Example #9
Source File: Application.java    From mobilecloud-15 with Apache License 2.0 4 votes vote down vote up
@Bean
EmbeddedServletContainerCustomizer containerCustomizer(
		@Value("${keystore.file}") String keystoreFile,
		@Value("${keystore.pass}") final String keystorePass)
		throws Exception {

	
	// This is boiler plate code to setup https on embedded Tomcat
	// with Spring Boot:
	
	final String absoluteKeystoreFile = new File(keystoreFile)
			.getAbsolutePath();

	return new EmbeddedServletContainerCustomizer() {
		@Override
		public void customize(ConfigurableEmbeddedServletContainer container) {
			TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
			tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {

				@Override
				public void customize(Connector connector) {
					connector.setPort(8443);
					connector.setSecure(true);
					connector.setScheme("https");

					Http11NioProtocol proto = (Http11NioProtocol) connector
							.getProtocolHandler();
					proto.setSSLEnabled(true);
					
					// If you update the keystore, you need to change
					// these parameters to match the keystore that you generate
					proto.setKeystoreFile(absoluteKeystoreFile);
					proto.setKeystorePass(keystorePass);
					proto.setKeystoreType("JKS");
					proto.setKeyAlias("tomcat");

				}
			});
		}

	};
}
 
Example #10
Source File: Application.java    From mobilecloud-15 with Apache License 2.0 4 votes vote down vote up
@Bean
EmbeddedServletContainerCustomizer containerCustomizer(
		@Value("${keystore.file}") String keystoreFile,
		@Value("${keystore.pass}") final String keystorePass)
		throws Exception {

	
	// This is boiler plate code to setup https on embedded Tomcat
	// with Spring Boot:
	
	final String absoluteKeystoreFile = new File(keystoreFile)
			.getAbsolutePath();

	return new EmbeddedServletContainerCustomizer() {
		@Override
		public void customize(ConfigurableEmbeddedServletContainer container) {
			TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
			tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {

				@Override
				public void customize(Connector connector) {
					connector.setPort(8443);
					connector.setSecure(true);
					connector.setScheme("https");

					Http11NioProtocol proto = (Http11NioProtocol) connector
							.getProtocolHandler();
					proto.setSSLEnabled(true);
					
					// If you update the keystore, you need to change
					// these parameters to match the keystore that you generate
					proto.setKeystoreFile(absoluteKeystoreFile);
					proto.setKeystorePass(keystorePass);
					proto.setKeystoreType("JKS");
					proto.setKeyAlias("tomcat");

				}
			});
		}

	};
}