Java 类org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory 实例源码

项目:secrets-proxy    文件:EmbeddedServerConfig.java   
/**
 * 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;
}
项目:jetty-server-request-logger    文件:JettyServerCustomizer.java   
@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;
}
项目:Robocode    文件:AppConfig.java   
@Bean
@Autowired
public EmbeddedServletContainerCustomizer servletContainerCustomizer(ServerProperties properties) {
    return container -> {
        if (container instanceof JettyEmbeddedServletContainerFactory) {
            JettyEmbeddedServletContainerFactory jettyContainer = (JettyEmbeddedServletContainerFactory) container;
            jettyContainer.addConfigurations(new AbstractConfiguration() {

                @Override
                public void configure(WebAppContext context) throws Exception {
                    properties.getContextParameters().forEach((k, v) -> context.setInitParameter(k, v));
                }
            });
        }
    };
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServerProperties.java   
void customizeJetty(final ServerProperties serverProperties,
        JettyEmbeddedServletContainerFactory factory) {
    factory.setUseForwardHeaders(serverProperties.getOrDeduceUseForwardHeaders());
    if (this.acceptors != null) {
        factory.setAcceptors(this.acceptors);
    }
    if (this.selectors != null) {
        factory.setSelectors(this.selectors);
    }
    if (serverProperties.getMaxHttpHeaderSize() > 0) {
        customizeMaxHttpHeaderSize(factory,
                serverProperties.getMaxHttpHeaderSize());
    }
    if (serverProperties.getMaxHttpPostSize() > 0) {
        customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize());
    }

    if (serverProperties.getConnectionTimeout() != null) {
        customizeConnectionTimeout(factory,
                serverProperties.getConnectionTimeout());
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServerProperties.java   
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);
                }
            }
        }
    });
}
项目:spring-boot-concourse    文件:ServerProperties.java   
void customizeJetty(ServerProperties serverProperties,
        JettyEmbeddedServletContainerFactory factory) {
    factory.setUseForwardHeaders(serverProperties.getOrDeduceUseForwardHeaders());
    if (this.acceptors != null) {
        factory.setAcceptors(this.acceptors);
    }
    if (this.selectors != null) {
        factory.setSelectors(this.selectors);
    }
    if (serverProperties.getMaxHttpHeaderSize() > 0) {
        customizeMaxHttpHeaderSize(factory,
                serverProperties.getMaxHttpHeaderSize());
    }
    if (serverProperties.getMaxHttpPostSize() > 0) {
        customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize());
    }
}
项目:citizenship-appointment-server    文件:AppConfig.java   
@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);
                        }
                    }
                }
            });
        }
    };
}
项目:nakadi    文件:JettyConfig.java   
@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;
}
项目:amv-access-api-poc    文件:JettyMetricsCustomizer.java   
private void addStatisticHandler(JettyEmbeddedServletContainerFactory jetty) {
    jetty.addServerCustomizers(server -> {
        HandlerCollection handlerCollection = new HandlerCollection(server.getHandlers());
        statisticsHandler.setHandler(handlerCollection);
        server.setHandler(statisticsHandler);
    });
}
项目:amv-access-api-poc    文件:JettyAccessLogCustomizer.java   
@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);
    });
}
项目:amv-access-api-poc    文件:JettyConfiguration.java   
@Bean
public JettyCustomizer jettyCustomizer() {
    return new JettyCustomizer() {
        @Override
        void customizeJetty(JettyEmbeddedServletContainerFactory container) {
            String serverName = "jetty";
            container.setServerHeader(serverName);
            container.setDisplayName(serverName);
            container.setUseForwardHeaders(true);
        }
    };
}
项目:amv-access-api-poc    文件:JettyJmxCustomizer.java   
@Override
void customizeJetty(JettyEmbeddedServletContainerFactory container) {
    container.addServerCustomizers(server -> {
        MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
        server.addEventListener(mbContainer);
        server.addBean(mbContainer);
    });
}
项目:scoold    文件:ScooldServer.java   
/**
 * @return Jetty config bean
 */
@Bean
public EmbeddedServletContainerFactory jettyConfigBean() {
    JettyEmbeddedServletContainerFactory jef = new JettyEmbeddedServletContainerFactory();
    jef.setPort(getServerPort());
    logger.info("Listening on port {}...", jef.getPort());
    return jef;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EmbeddedServletContainerMvcIntegrationTests.java   
@Bean
public EmbeddedServletContainerFactory containerFactory() {
    JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(
            0);
    factory.setContextPath(this.env.getProperty("context"));
    return factory;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JettyWebSocketContainerCustomizer.java   
@Override
protected void doCustomize(JettyEmbeddedServletContainerFactory container) {
    container.addConfigurations(new AbstractConfiguration() {

        @Override
        public void configure(WebAppContext context) throws Exception {
            ServerContainer serverContainer = WebSocketServerContainerInitializer
                    .configureContext(context);
            ShutdownThread.deregister(serverContainer);
        }

    });
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServerPropertiesTests.java   
@Test
public void defaultUseForwardHeadersJetty() throws Exception {
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setUseForwardHeaders(false);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServerPropertiesTests.java   
@Test
public void setUseForwardHeadersJetty() throws Exception {
    this.properties.setUseForwardHeaders(true);
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setUseForwardHeaders(true);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServerPropertiesTests.java   
@Test
public void deduceUseForwardHeadersJetty() throws Exception {
    this.properties.setEnvironment(new MockEnvironment().withProperty("DYNO", "-"));
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setUseForwardHeaders(true);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServerPropertiesTests.java   
@Test
public void sessionStoreDir() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("server.session.store-dir", "myfolder");
    bindProperties(map);
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setSessionStoreDir(new File("myfolder"));
}
项目:spring-boot-concourse    文件:EmbeddedServletContainerMvcIntegrationTests.java   
@Bean
public EmbeddedServletContainerFactory containerFactory() {
    JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(
            0);
    factory.setContextPath(this.env.getProperty("context"));
    return factory;
}
项目:spring-boot-concourse    文件:JettyWebSocketContainerCustomizer.java   
@Override
protected void doCustomize(JettyEmbeddedServletContainerFactory container) {
    container.addConfigurations(new AbstractConfiguration() {

        @Override
        public void configure(WebAppContext context) throws Exception {
            ServerContainer serverContainer = WebSocketServerContainerInitializer
                    .configureContext(context);
            ShutdownThread.deregister(serverContainer);
        }

    });
}
项目:spring-boot-concourse    文件:ServerPropertiesTests.java   
@Test
public void defaultUseForwardHeadersJetty() throws Exception {
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setUseForwardHeaders(false);
}
项目:spring-boot-concourse    文件:ServerPropertiesTests.java   
@Test
public void setUseForwardHeadersJetty() throws Exception {
    this.properties.setUseForwardHeaders(true);
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setUseForwardHeaders(true);
}
项目:spring-boot-concourse    文件:ServerPropertiesTests.java   
@Test
public void deduceUseForwardHeadersJetty() throws Exception {
    this.properties.setEnvironment(new MockEnvironment().withProperty("DYNO", "-"));
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setUseForwardHeaders(true);
}
项目:spring-boot-concourse    文件:ServerPropertiesTests.java   
@Test
public void sessionStoreDir() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("server.session.store-dir", "myfolder");
    bindProperties(map);
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setSessionStoreDir(new File("myfolder"));
}
项目:xlator    文件:JettyConfig.java   
@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;
}
项目:moneta    文件:MonetaSpringBootApplication.java   
@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;
}
项目:contestparser    文件:EmbeddedServletContainerMvcIntegrationTests.java   
@Bean
public EmbeddedServletContainerFactory containerFactory() {
    JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(
            0);
    factory.setContextPath(this.env.getProperty("context"));
    return factory;
}
项目:contestparser    文件:JettyWebSocketContainerCustomizer.java   
@Override
protected void doCustomize(JettyEmbeddedServletContainerFactory container) {
    container.addConfigurations(new AbstractConfiguration() {

        @Override
        public void configure(WebAppContext context) throws Exception {
            ServerContainer serverContainer = WebSocketServerContainerInitializer
                    .configureContext(context);
            ShutdownThread.deregister(serverContainer);
        }

    });
}
项目:contestparser    文件:ServerPropertiesTests.java   
@Test
public void defaultUseForwardHeadersJetty() throws Exception {
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setUseForwardHeaders(false);
}
项目:contestparser    文件:ServerPropertiesTests.java   
@Test
public void setUseForwardHeadersJetty() throws Exception {
    this.properties.setUseForwardHeaders(true);
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setUseForwardHeaders(true);
}
项目:contestparser    文件:ServerPropertiesTests.java   
@Test
public void deduceUseForwardHeadersJetty() throws Exception {
    this.properties.setEnvironment(new MockEnvironment().withProperty("DYNO", "-"));
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setUseForwardHeaders(true);
}
项目:contestparser    文件:ServerPropertiesTests.java   
@Test
public void sessionStoreDir() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("server.session.store-dir", "myfolder");
    bindProperties(map);
    JettyEmbeddedServletContainerFactory container = spy(
            new JettyEmbeddedServletContainerFactory());
    this.properties.customize(container);
    verify(container).setSessionStoreDir(new File("myfolder"));
}
项目:agate    文件:WebConfiguration.java   
@Bean
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
  return (ConfigurableEmbeddedServletContainer container) -> {
    JettyEmbeddedServletContainerFactory jetty = (JettyEmbeddedServletContainerFactory) container;
    jetty.setServerCustomizers(Collections.singleton(this));
  };
}
项目:data-prep    文件:JettyConfiguration.java   
@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:-1}") final String idleTimeout) {
    return new JettyContainerConfiguration(port, maxThreads, minThreads, idleTimeout);
}
项目:mica2    文件:WebConfiguration.java   
@Bean
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
  return (ConfigurableEmbeddedServletContainer container) -> {
    JettyEmbeddedServletContainerFactory jetty = (JettyEmbeddedServletContainerFactory) container;
    jetty.setServerCustomizers(Collections.singleton(this));
  };
}
项目:alf.io    文件:SpringBootInitializer.java   
@Bean
public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer(Environment environment) {
    return (container) -> {
        container.addInitializers(SERVLET_CONTEXT_INITIALIZER);
        //container.setRegisterJspServlet(false);
        Map<String, String> mimeMappings = new HashMap<>();
        mimeMappings.put("eot", "application/vnd.ms-fontobject");
        mimeMappings.put("otf", "font/opentype");
        mimeMappings.put("ttf", "application/x-font-ttf");
        mimeMappings.put("woff", "application/x-font-woff");
        mimeMappings.put("svg", "image/svg+xml");
        container.setSessionTimeout(2, TimeUnit.HOURS);
        container.setMimeMappings(new MimeMappings(mimeMappings));
        if(!environment.acceptsProfiles("dev")) {
            container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404-not-found"), new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500-internal-server-error"), new ErrorPage("/session-expired"));
        }

        Optional.ofNullable(System.getProperty("alfio.worker.name")).ifPresent(workerName -> {
            ((JettyEmbeddedServletContainerFactory)container).addServerCustomizers(server -> {
                log.info("Configuring session manager using worker name {}", workerName);
                DefaultSessionIdManager sessionIdManager = new DefaultSessionIdManager(server);
                sessionIdManager.setWorkerName(workerName);
                server.setSessionIdManager(sessionIdManager);
            });
        });


    };
}
项目:SpringBoot-AngularJS-Bootstrap    文件:CoreConfig.java   
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();
    // Port number that server will run.
    factory.setPort(8888);
    return factory;
}
项目:amv-access-api-poc    文件:JettyMetricsCustomizer.java   
@Override
void customizeJetty(JettyEmbeddedServletContainerFactory jetty) {
    addStatisticHandler(jetty);
}
项目:amv-access-api-poc    文件:JettyCustomizer.java   
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    if (container instanceof JettyEmbeddedServletContainerFactory) {
        customizeJetty((JettyEmbeddedServletContainerFactory) container);
    }
}