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

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

下面列出了怎么用org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: youkefu   文件: WebServerConfiguration.java
@Bean  
public EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() throws IOException, NoSuchAlgorithmException  
{  
    TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();  
    tomcatFactory.addConnectorCustomizers(new UKeFuTomcatConnectorCustomizer(maxthread, maxconnections));  
    File sslFile = new File(path , "ssl/https.properties") ;
    if(sslFile.exists()){
    	Properties sslProperties = new Properties();
    	FileInputStream in = new FileInputStream(sslFile);
    	sslProperties.load(in);
    	in.close();
    	if(!StringUtils.isBlank(sslProperties.getProperty("key-store")) && !StringUtils.isBlank(sslProperties.getProperty("key-store-password"))){
      Ssl ssl = new Ssl();
      ssl.setKeyStore(new File(path , "ssl/"+sslProperties.getProperty("key-store")).getAbsolutePath());
      ssl.setKeyStorePassword(UKTools.decryption(sslProperties.getProperty("key-store-password")));
      tomcatFactory.setSsl(ssl);
    	}
    }
    return tomcatFactory;  
}
 
/**
 * 
 * Customization servlet container configuring. </br>
 * 
 * @see {@link EmbeddedServletContainerAutoConfiguration}
 * 
 * @return
 */
@Bean
public EmbeddedServletContainerCustomizer customEmbeddedServletContainerCustomizer() {
	return container -> {
		// Tomcat container customization
		if (container instanceof TomcatEmbeddedServletContainerFactory) {
			TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
			tomcat.addConnectorCustomizers(connector -> {
				ProtocolHandler handler = connector.getProtocolHandler();
				if (handler instanceof AbstractProtocol) {
					AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
					/**
					 * {@link org.apache.tomcat.util.net.NioEndpoint#startInternal()}
					 * {@link org.apache.tomcat.util.net.NioEndpoint#createExecutor()}
					 */
					protocol.setExecutor(customTomcatExecutor(protocol));
				}
			});
		} else {
			log.warn("Skip using custom servlet container, EmbeddedServletContainer: {}", container);
		}
	};

}
 
源代码3 项目: NoteBlog   文件: SSLConfig.java
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected void postProcessContext(Context context) {
            if (environment.getProperty("server.ssl.enabled", Boolean.class, Boolean.FALSE)) {
                SecurityConstraint constraint = new SecurityConstraint();
                constraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                constraint.addCollection(collection);
                context.addConstraint(constraint);
            } else {
                super.postProcessContext(context);
            }
        }
    };
    if (environment.getProperty("server.ssl.enabled", Boolean.class, Boolean.FALSE)) {
        tomcat.addAdditionalTomcatConnectors(httpConnector());
    }
    return tomcat;
}
 
源代码4 项目: spring-boot-inside   文件: TomcatConfiguration.java
@Bean
public EmbeddedServletContainerCustomizer staticResourceCustomizer() {
	return new EmbeddedServletContainerCustomizer() {
		@Override
		public void customize(ConfigurableEmbeddedServletContainer container) {
			if (container instanceof TomcatEmbeddedServletContainerFactory) {
				((TomcatEmbeddedServletContainerFactory) container)
						.addContextCustomizers(new TomcatContextCustomizer() {
							@Override
							public void customize(Context context) {
								context.addLifecycleListener(new StaticResourceConfigurer(context));
							}
						});
			}
		}

	};
}
 
源代码5 项目: 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());
                    }                        
                });
            }
        }

    };
}
 
@Bean
public EmbeddedServletContainerCustomizer staticResourceCustomizer() {
	return new EmbeddedServletContainerCustomizer() {
		@Override
		public void customize(ConfigurableEmbeddedServletContainer container) {
			if (container instanceof TomcatEmbeddedServletContainerFactory) {
				((TomcatEmbeddedServletContainerFactory) container)
						.addContextCustomizers(new TomcatContextCustomizer() {
							@Override
							public void customize(Context context) {
								context.addLifecycleListener(new StaticResourceConfigurer(context));
							}
						});
			}
		}

	};
}
 
源代码7 项目: spring-boot-cookbook   文件: SslConfig.java
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            // SecurityConstraint必须存在,可以通过其为不同的URL设置不同的重定向策略。
            SecurityConstraint constraint = new SecurityConstraint();
            constraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            constraint.addCollection(collection);
            context.addConstraint(constraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(httpConnector());
    return tomcat;
}
 
源代码8 项目: find   文件: AppConfiguration.java
@SuppressWarnings("ReturnOfInnerClass")
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer(
    @Value("${server.tomcat.accesslog.pattern:combined}") final String pattern
) {

    return container -> {
        final ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, DispatcherServletConfiguration.AUTHENTICATION_ERROR_PATH);
        final ErrorPage error403Page = new ErrorPage(HttpStatus.FORBIDDEN, DispatcherServletConfiguration.AUTHENTICATION_ERROR_PATH);
        final ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, DispatcherServletConfiguration.NOT_FOUND_ERROR_PATH);
        final ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, DispatcherServletConfiguration.SERVER_ERROR_PATH);

        container.addErrorPages(error401Page, error403Page, error404Page, error500Page);

        if (StringUtils.isNotEmpty(pattern) && container instanceof TomcatEmbeddedServletContainerFactory) {
            final TomcatAccessLogValve accessLogValve = new TomcatAccessLogValve();
            accessLogValve.setPattern(pattern);
            ((TomcatEmbeddedServletContainerFactory) container).addEngineValves(accessLogValve);
        }
    };
}
 
源代码9 项目: find   文件: TomcatConfig.java
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    final TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();

    if(useReverseProxy) {
        tomcat.addAdditionalTomcatConnectors(createAjpConnector());
    }

    // Set the web resources cache size (this defaults to 10MB but that is too small for Find)
    tomcat.addContextCustomizers(context -> {
        final WebResourceRoot resources = new StandardRoot(context);
        resources.setCacheMaxSize(webResourcesCacheSize);
        context.setResources(resources);
    });

    tomcat.addConnectorCustomizers(connector -> {
        connector.setMaxPostSize(connectorMaxPostSize);
    });

    return tomcat;
}
 
@Bean
public EmbeddedServletContainerCustomizer servletContainerCustomizer() {
    return servletContainer -> {
        addMimeMappingsForFonts(servletContainer);

        TomcatEmbeddedServletContainerFactory container = (TomcatEmbeddedServletContainerFactory) servletContainer;

        container.setRegisterJspServlet(false);

        container.addContextCustomizers(customizer -> customizer.addWelcomeFile("index.html"));
        container.addConnectorCustomizers(
                connector -> {
                    AbstractHttp11Protocol httpProtocol = (AbstractHttp11Protocol) connector.getProtocolHandler();
                    httpProtocol.setCompression("on");
                    httpProtocol.setCompressionMinSize(256);
                    httpProtocol.setCompressableMimeTypes(COMPRESSIBLE_MEDIA_TYPES);
                }
        );
    };
}
 
源代码11 项目: NFVO   文件: SystemConfiguration.java
@Bean
public EmbeddedServletContainerFactory servletContainer() {
  if (https) {
    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;
  }
  return new TomcatEmbeddedServletContainerFactory();
}
 
源代码12 项目: jcart   文件: 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;
}
 
源代码13 项目: jcart   文件: 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;
}
 
源代码14 项目: booties   文件: ProxiesAutoConfiguration.java
@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);
                }
            }
        }
    };
}
 
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return factory -> {
        TomcatEmbeddedServletContainerFactory containerFactory = (TomcatEmbeddedServletContainerFactory) factory;
        containerFactory.setTomcatContextCustomizers(Arrays.asList(context -> {
            final PersistentManager persistentManager = new PersistentManager();
            final FileStore store = new FileStore();

            final String sessionDirectory = makeSessionDirectory();
            log.info("Writing sessions to " + sessionDirectory);
            store.setDirectory(sessionDirectory);

            persistentManager.setStore(store);
            context.setManager(persistentManager);
        }));
    };
}
 
源代码16 项目: WeBASE-Front   文件: TomcatConfig.java
@Bean
public EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() {
    TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
        tomcatFactory.addConnectorCustomizers(connector -> {
        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
        protocol.setKeepAliveTimeout(constantProperties.getKeepAliveTimeout()* 1000);
        protocol.setMaxKeepAliveRequests(constantProperties.getKeepAliveRequests());
    });
    return tomcatFactory;
}
 
源代码17 项目: WeBASE-Sign   文件: TomcatConfig.java
@Bean
public EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() {
    TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
    tomcatFactory.addConnectorCustomizers(connector -> {
        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
        protocol.setKeepAliveTimeout(10 * 1000);
        protocol.setMaxKeepAliveRequests(constantProperties.getKeepAliveRequests());
    });
    return tomcatFactory;
}
 
源代码18 项目: binance-marketmaker   文件: Application.java
@Bean
public EmbeddedServletContainerFactory servletContainer() {
 
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
 
    Connector ajpConnector = new Connector("AJP/1.3");
    ajpConnector.setPort(9090);
    ajpConnector.setSecure(false);
    ajpConnector.setAllowTrace(false);
    ajpConnector.setScheme("http");
    tomcat.addAdditionalTomcatConnectors(ajpConnector);
 
    return tomcat;
}
 
源代码19 项目: Spring   文件: Application.java
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    final TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
    factory.setPort(appSettings.getPort());
    factory.setSessionTimeout(appSettings.getSessionTimeout(), TimeUnit.MINUTES);
    factory.setContextPath(appSettings.getContext());
    return factory;
}
 
源代码20 项目: radar   文件: TomcatContainerCustomizer.java
@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);
			}
		}
	});
}
 
源代码21 项目: goods-seckill   文件: WebServerConfiguration.java
@Bean
public EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() {
	TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
	tomcatFactory.setPort(8080);
	tomcatFactory.addConnectorCustomizers(new MyTomcatConnectorCustomizer());
	return tomcatFactory;
}
 
源代码22 项目: yfs   文件: WebConfig.java
@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;
}
 
源代码23 项目: 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
                    }
            );
        }
    };
}
 
源代码24 项目: spring-boot   文件: HttpsConfiguration.java
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    tomcat.setUriEncoding(Charset.forName("UTF-8"));
    tomcat.addAdditionalTomcatConnectors(createSslConnector());
    log.info("\n*** Tomcat SSL setting successful." + properties.getPort());
    return tomcat;
}
 
源代码25 项目: springboot-learn   文件: ShutdownConfig.java
/**
 * 用于注入 connector
 *
 * @return
 */
@Bean
public EmbeddedServletContainerCustomizer tomcatCustomizer() {
    return container -> {
        if (container instanceof TomcatEmbeddedServletContainerFactory) {
            ((TomcatEmbeddedServletContainerFactory) container).addConnectorCustomizers(gracefulShutdown());
        }
    };
}
 
@Bean
public EmbeddedServletContainerCustomizer servletContainerCustomizer()
{
	return servletContainer -> {
		final TomcatEmbeddedServletContainerFactory tomcatContainerFactory = (TomcatEmbeddedServletContainerFactory)servletContainer;
		tomcatContainerFactory.addConnectorCustomizers(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);
		});
	};
}
 
/**
 * adds SSL connector to Tomcat
 *
 * @return
 */
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    if (StringUtils.hasText(keystoreFile)) {
        tomcat.addAdditionalTomcatConnectors(createSslConnector());
    }
    return tomcat;
}
 
源代码28 项目: onetwo   文件: BootServletContainerCustomizer.java
@Override
	public void customize(ConfigurableEmbeddedServletContainer container) {
		if (container instanceof TomcatEmbeddedServletContainerFactory) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addConnectorCustomizers(
                (connector) -> {
                	//connector 本身默认是 2 mb
                	connector.setMaxPostSize(FileUtils.parseSize(multipartProperties.getMaxRequestSize()));
                	Http11NioProtocol handler = (Http11NioProtocol)connector.getProtocolHandler();
                	if(tomcatProperties.getBacklog()!=-1){
                		//socket 连接队列大小
//                		handler.setBacklog(tomcatProperties.getBacklog());
                		handler.setAcceptCount(tomcatProperties.getAcceptCount());
                	}
                	if(tomcatProperties.getMaxConnections()!=-1){
                		//最大连接数,默认10000
                		handler.setMaxConnections(tomcatProperties.getMaxConnections());
                	}
                	if(tomcatProperties.getConnectionTimeout()!=-1){
                		handler.setConnectionTimeout(tomcatProperties.getConnectionTimeout());
                	}
                	if(tomcatProperties.getConnectionUploadTimeout()>0){
                		//为true,则上传文件时使用connectionTimeout, 为false,则使用connectionUploadTimeout
                		handler.setDisableUploadTimeout(false);
                		handler.setConnectionUploadTimeout(tomcatProperties.getConnectionUploadTimeout());
                	}
                	connector.setAsyncTimeout(tomcatProperties.getAsyncTimeout());
                }
            );
        }
		/*if(container instanceof TomcatEmbeddedServletContainerFactory){
			TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
			tomcat.addContextCustomizers(context->{
				context.setReloadable(true);
			});
		}*/
	}
 
源代码29 项目: osiam   文件: AjpConfiguration.java
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    if (container instanceof TomcatEmbeddedServletContainerFactory) {
        TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
        Connector ajpConnector = new Connector("AJP/1.3");
        ajpConnector.setAttribute("address", bindAddress);
        ajpConnector.setPort(port);
        ajpConnector.setSecure(false);
        ajpConnector.setAllowTrace(false);
        ajpConnector.setScheme("http");
        tomcat.addAdditionalTomcatConnectors(ajpConnector);
    }
}
 
源代码30 项目: Cerberus   文件: TestContext.java
@Bean
public EmbeddedServletContainerFactory servletContainer() {
  TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
  factory.setPort(TestApiConfig.PORT);
  factory.setSessionTimeout(10, TimeUnit.MINUTES);
  return factory;
}
 
点击广告?(赏赐笔者)
 类所在包
 类方法
 同包方法