本文整理汇总了Java中org.springframework.boot.context.embedded.jetty.JettyServerCustomizer类的典型用法代码示例。如果您正苦于以下问题:Java JettyServerCustomizer类的具体用法?Java JettyServerCustomizer怎么用?Java JettyServerCustomizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JettyServerCustomizer类属于org.springframework.boot.context.embedded.jetty包,在下文中一共展示了JettyServerCustomizer类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: customizeConnectionTimeout
import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; //导入依赖的package包/类
private void customizeConnectionTimeout(
JettyEmbeddedServletContainerFactory factory,
final int connectionTimeout) {
factory.addServerCustomizers(new JettyServerCustomizer() {
@Override
public void customize(Server server) {
for (org.eclipse.jetty.server.Connector connector : server
.getConnectors()) {
if (connector instanceof AbstractConnector) {
((AbstractConnector) connector)
.setIdleTimeout(connectionTimeout);
}
}
}
});
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:ServerProperties.java
示例2: disableServerHeader
import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerCustomizer disableServerHeader() {
return container -> {
if (container instanceof JettyEmbeddedServletContainerFactory) {
((JettyEmbeddedServletContainerFactory) container).addServerCustomizers(new JettyServerCustomizer() {
@Override
public void customize(Server server) {
for (Connector connector : server.getConnectors()) {
if (connector instanceof ServerConnector) {
HttpConnectionFactory connectionFactory = connector.getConnectionFactory(HttpConnectionFactory.class);
connectionFactory.getHttpConfiguration().setSendServerVersion(false);
}
}
}
});
}
};
}
示例3: jettyEmbeddedServletContainerFactory
import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; //导入依赖的package包/类
@Bean
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory(
@Value("${server.port:8080}") final String port,
@Value("${jetty.threadPool.maxThreads:200}") final String maxThreads,
@Value("${jetty.threadPool.minThreads:8}") final String minThreads,
@Value("${jetty.threadPool.idleTimeout:60000}") final String idleTimeout) {
final JettyEmbeddedServletContainerFactory factory =
new JettyEmbeddedServletContainerFactory(Integer.valueOf(port));
factory.addServerCustomizers((JettyServerCustomizer) server -> {
final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
threadPool.setMaxThreads(Integer.valueOf(maxThreads));
threadPool.setMinThreads(Integer.valueOf(minThreads));
threadPool.setIdleTimeout(Integer.valueOf(idleTimeout));
final GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setHandler(server.getHandler());
gzipHandler.setSyncFlush(true);
server.setHandler(gzipHandler);
});
return factory;
}
示例4: getServerCustomizers
import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; //导入依赖的package包/类
@Override
public Collection<JettyServerCustomizer> getServerCustomizers() {
Collection<JettyServerCustomizer> jettyServerCustomizers = super.getServerCustomizers();
jettyServerCustomizers.add(server -> {
// Customize the connection pool used by Jetty for very large dataset
// which takes more than 30s to be rendered
QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
threadPool.setMaxThreads(Integer.valueOf(maxThreads));
threadPool.setMinThreads(Integer.valueOf(minThreads));
threadPool.setIdleTimeout(Integer.valueOf(idleTimeout));
for (Connector connector : server.getConnectors()) {
if (connector instanceof ServerConnector) {
((ServerConnector) connector).setIdleTimeout(Long.parseLong(idleTimeout));
}
}
});
return jettyServerCustomizers;
}
示例5: servletContainer
import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerFactory servletContainer() {
JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();
factory.addServerCustomizers(new JettyServerCustomizer() {
public void customize(final Server server) {
// Tweak the connection pool used by Jetty to handle incoming
// HTTP connections
Integer localServerMaxThreads = deriveValue(serverMaxThreads,
DEFAULT_SERVER_MAX_THREADS);
Integer localServerMinThreads = deriveValue(serverMinThreads,
DEFAULT_SERVER_MIN_THREADS);
Integer localServerIdleTimeout = deriveValue(serverIdleTimeout,
DEFAULT_SERVER_IDLE_TIMEOUT);
logger.info("Container Max Threads={}", localServerMaxThreads);
logger.info("Container Min Threads={}", localServerMinThreads);
logger.info("Container Idle Timeout={}", localServerIdleTimeout);
final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
threadPool.setMaxThreads(Integer.valueOf(localServerMaxThreads));
threadPool.setMinThreads(Integer.valueOf(localServerMinThreads));
threadPool.setIdleTimeout(Integer.valueOf(localServerIdleTimeout));
}
});
return factory;
}
示例6: servletContainer
import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerFactory servletContainer(SslProperties properties) {
JettyEmbeddedServletContainerFactory jetty = new JettyEmbeddedServletContainerFactory() {
@Override
protected void postProcessWebAppContext(WebAppContext webAppContext) {
// 所有请求都必须为 Https 协议
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
ConstraintMapping mapping = new ConstraintMapping();
Constraint constraint = new Constraint();
constraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);
mapping.setConstraint(constraint);
mapping.setPathSpec("/*");
securityHandler.addConstraintMapping(mapping);
webAppContext.setSecurityHandler(securityHandler);
}
};
jetty.addServerCustomizers(new JettyServerCustomizer() {
@Override
public void customize(Server server) {
// 移除Spring Boot 生成的 Connector
int httpPort = 80;
Connector[] connectors = server.getConnectors();
for (Connector connector : connectors) {
if (connector instanceof ServerConnector) {
httpPort = ((ServerConnector) connector).getPort();
}
server.removeConnector(connector);
}
// 配置 Http 协议的 Connector
HttpConfiguration httpConfig = new HttpConfiguration();
// 重定向
httpConfig.setSecureScheme(properties.getScheme());
httpConfig.setSecurePort(properties.getPort());
httpConfig.addCustomizer(new SecureRequestCustomizer());
ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
httpConnector.setPort(httpPort);
server.addConnector(httpConnector);
// 配置 Https 协议的 Connector
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
HttpConnectionFactory connectionFactory = new HttpConnectionFactory(httpsConfig);
SslContextFactory sslContextFactory = new SslContextFactory();
File keystoreFile = new File(properties.getKeystore());
if (keystoreFile.exists()) {
sslContextFactory.setKeyStorePath(properties.getKeystore());
sslContextFactory.setKeyStorePassword(properties.getKeystorePassword());
}
SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory,
HttpVersion.HTTP_1_1.asString());
ServerConnector serverConnector = new ServerConnector(server, sslConnectionFactory, connectionFactory);
serverConnector.setPort(properties.getPort());
server.addConnector(serverConnector);
}
});
return jetty;
}
示例7: jettyConfigBean
import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; //导入依赖的package包/类
/**
* @return Jetty config bean
*/
@Bean
public EmbeddedServletContainerFactory jettyConfigBean() {
JettyEmbeddedServletContainerFactory jef = new JettyEmbeddedServletContainerFactory();
jef.addServerCustomizers(new JettyServerCustomizer() {
public void customize(Server server) {
if (Config.getConfigBoolean("access_log_enabled", true)) {
// enable access log via Logback
HandlerCollection handlers = new HandlerCollection();
for (Handler handler : server.getHandlers()) {
handlers.addHandler(handler);
}
RequestLogHandler reqLogs = new RequestLogHandler();
reqLogs.setServer(server);
RequestLogImpl rli = new RequestLogImpl();
rli.setResource("/logback-access.xml");
rli.setQuiet(true);
rli.start();
reqLogs.setRequestLog(rli);
handlers.addHandler(reqLogs);
server.setHandler(handlers);
}
for (Connector y : server.getConnectors()) {
for (ConnectionFactory cf : y.getConnectionFactories()) {
if (cf instanceof HttpConnectionFactory) {
HttpConnectionFactory dcf = (HttpConnectionFactory) cf;
// support for X-Forwarded-Proto
// redirect back to https if original request uses it
if (Config.IN_PRODUCTION) {
HttpConfiguration httpConfiguration = dcf.getHttpConfiguration();
httpConfiguration.addCustomizer(new ForwardedRequestCustomizer());
}
// Disable Jetty version header
dcf.getHttpConfiguration().setSendServerVersion(false);
}
}
}
}
});
int defaultPort = NumberUtils.toInt(System.getProperty("jetty.http.port", "8080"));
jef.setPort(NumberUtils.toInt(System.getProperty("server.port"), defaultPort));
logger.info("Listening on port {}...", jef.getPort());
return jef;
}