本文整理汇总了Java中org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory.addServerCustomizers方法的典型用法代码示例。如果您正苦于以下问题:Java JettyEmbeddedServletContainerFactory.addServerCustomizers方法的具体用法?Java JettyEmbeddedServletContainerFactory.addServerCustomizers怎么用?Java JettyEmbeddedServletContainerFactory.addServerCustomizers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory
的用法示例。
在下文中一共展示了JettyEmbeddedServletContainerFactory.addServerCustomizers方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jettyEmbeddedServletContainerFactory
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的package包/类
/**
* Configures the embedded jetty server. The values are configured in
* <b>application.yaml</b> file.
*
* @param port jetty server port
* @param maxThreads thread pool min thread
* @param minThreads thread pool max thread
* @param idleTimeout maximum thread idle time
* @param jmxEnabled true, if jetty jmx is enabled.
* @return {@link JettyEmbeddedServletContainerFactory}
*/
@Bean
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory(@Value("${server.port:8443}") final int port,
@Value("${jetty.thread-pool.max-threads:200}") final int maxThreads,
@Value("${jetty.thread-pool.min-threads:8}") final int minThreads,
@Value("${jetty.thread-pool.idle-timeout:60000}") final int idleTimeout,
@Value("${jetty.jmx.enabled:true}") final boolean jmxEnabled) {
log.info("Configuring Jetty server.");
final JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(port);
factory.addServerCustomizers(server -> {
final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
threadPool.setMinThreads(minThreads);
threadPool.setMaxThreads(maxThreads);
threadPool.setIdleTimeout(idleTimeout);
log.info("Server thread pool config: " + server.getThreadPool());
// Jetty JMX config.
if (jmxEnabled) {
log.info("Exposing Jetty managed beans to the JMX platform server.");
server.addBean(new MBeanContainer(ManagementFactory.getPlatformMBeanServer()));
}
});
return factory;
}
示例2: jettyConfigBean
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的package包/类
@Bean
public EmbeddedServletContainerFactory jettyConfigBean() {
DynamicPropertyFactory propertyFactory = DynamicPropertyFactory.getInstance();
String accessLogFilePath = propertyFactory.getStringProperty("server.accessLog.config.file", ACCESS_LOG_FILE_PATH).getValue();
JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory
= new JettyEmbeddedServletContainerFactory();
jettyEmbeddedServletContainerFactory.addServerCustomizers(new org.springframework.boot.context.embedded.jetty.JettyServerCustomizer() {
public void customize(Server server) {
HandlerCollection handlers = new HandlerCollection();
for (Handler handler : server.getHandlers()) {
handlers.addHandler(handler);
}
RequestLogHandler requestLogHandler = new RequestLogHandler();
RequestLogImpl requestLogImpl = new RequestLogImpl();
requestLogImpl.setFileName(accessLogFilePath);
requestLogHandler.setRequestLog(requestLogImpl);
handlers.addHandler(requestLogHandler);
server.setHandler(handlers);
LOGGER.info("Jetty Server Customized. Access Log Configuration File - {}", accessLogFilePath);
}
});
return jettyEmbeddedServletContainerFactory;
}
示例3: customizeConnectionTimeout
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的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
示例4: jettyEmbeddedServletContainerFactory
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的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;
}
示例5: addStatisticHandler
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的package包/类
private void addStatisticHandler(JettyEmbeddedServletContainerFactory jetty) {
jetty.addServerCustomizers(server -> {
HandlerCollection handlerCollection = new HandlerCollection(server.getHandlers());
statisticsHandler.setHandler(handlerCollection);
server.setHandler(statisticsHandler);
});
}
示例6: customizeJetty
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的package包/类
@Override
void customizeJetty(JettyEmbeddedServletContainerFactory container) {
container.addServerCustomizers(server -> {
RequestLogHandler requestLogsHandler = new RequestLogHandler();
requestLogsHandler.setServer(server);
Slf4jRequestLog log = new Slf4jRequestLog();
requestLogsHandler.setRequestLog(log);
HandlerCollection handlers = new HandlerCollection(server.getHandlers());
handlers.prependHandler(requestLogsHandler);
server.setHandler(handlers);
});
}
示例7: customizeJetty
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的package包/类
@Override
void customizeJetty(JettyEmbeddedServletContainerFactory container) {
container.addServerCustomizers(server -> {
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addEventListener(mbContainer);
server.addBean(mbContainer);
});
}
示例8: jettyEmbeddedServletContainerFactory
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的package包/类
@Primary
@Bean
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory(MetricRegistry metricRegistry,
JettyThreadPoolSettings jettyThreadPoolSettings,
JettyLowResourceMonitorSettings jettyLowResourceMonitorSettings,
@Value("${server.port:8080}") final int port) {
final JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(port);
factory.addServerCustomizers(
new InstrumentedJettyServer(metricRegistry, jettyThreadPoolSettings, jettyLowResourceMonitorSettings));
return factory;
}
示例9: servletContainer
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的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;
}
示例10: servletContainer
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的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;
}
示例11: customize
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的package包/类
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
JettyEmbeddedServletContainerFactory factory = (JettyEmbeddedServletContainerFactory) container;
factory.addServerCustomizers(new JettyHttp2ServerCustomize());
}
示例12: servletContainer
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的package包/类
@Bean
public EmbeddedServletContainerFactory servletContainer() {
JettyEmbeddedServletContainerFactory jetty = new JettyEmbeddedServletContainerFactory("", 9000);
jetty.addServerCustomizers(server -> {
// WebAppContext amqWebConsoleWebAppContext = new WebAppContext(
// "/datadisk/Dropbox/git/EndreHome/mats/mats-amq-monitor/build-eclipse/activemq-web-console.war",
// "/webconsole");
String warFileMagicStringReference = "CLASSPATH AMQ WEB CONSOLE WAR FILE";
// Override WebAppContext to be able to load AMQ Web Console war file from classpath.
WebAppContext amqWebConsoleWebAppContext = new WebAppContext(warFileMagicStringReference, "/webconsole") {
/**
* Hack-override the Resource creation if it is the AMQ Web Console War that is requested. Very strange
* that I couldn't find a more natural way to stick in a specific Jetty Resource as war file to load
* (the "classpath:" URL prefix is not standard Java, and the hacks available to fix this are way more
* intrusive that this hack. At the same time Jetty does have both a URLResource and ClassPath
* implementation, but which is out of reach when we can only specify a String as the "war" argument).
*/
@Override
public Resource newResource(String urlOrPath) throws IOException {
if (urlOrPath == warFileMagicStringReference) {
return Resource.newClassPathResource("activemq-web-console.war");
}
return Resource.newResource(urlOrPath);
}
};
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.addHandler(amqWebConsoleWebAppContext);
handlerCollection.addHandler(server.getHandler());
server.setHandler(handlerCollection);
// Let the Web Console's classloader use parent first loading, to share e.g. SLFJ4 and Logback..
amqWebConsoleWebAppContext.setParentLoaderPriority(true);
/*
* Since the Servlet Container is initialized by Spring Boot (JettyEmbeddedServletContainerFactory), the
* JasperInitializer (which is a ServletContainerInitializer) won't be run. Therefore we force it to be run
* via Jetty's DI-container.
*/
amqWebConsoleWebAppContext.addManaged(new MatsJasperInitializer(amqWebConsoleWebAppContext));
});
return jetty;
}
示例13: jettyConfigBean
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; //导入方法依赖的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;
}