Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@
<artifactId>jetty-webapp</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-server</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-server</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.boot.web.server.Compression;
import org.springframework.boot.web.server.Http2;
import org.springframework.boot.web.server.Ssl;
import org.springframework.boot.web.servlet.server.Jsp;
import org.springframework.util.Assert;
Expand All @@ -50,6 +51,7 @@
* @author Aurélien Leboulanger
* @author Brian Clozel
* @author Olivier Lamy
* @author Paul Vorbach
*/
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
public class ServerProperties {
Expand Down Expand Up @@ -102,6 +104,9 @@ public class ServerProperties {
@NestedConfigurationProperty
private Compression compression = new Compression();

@NestedConfigurationProperty
private Http2 http2 = new Http2();

private Servlet servlet = new Servlet();

private final Tomcat tomcat = new Tomcat();
Expand Down Expand Up @@ -190,6 +195,14 @@ public Compression getCompression() {
return this.compression;
}

public Http2 getHttp2() {
return this.http2;
}

public void setHttp2(Http2 http2) {
this.http2 = http2;
}

public Servlet getServlet() {
return this.servlet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import javax.servlet.SessionCookieConfig;

import io.undertow.UndertowOptions;
import org.apache.catalina.core.AprLifecycleListener;
import org.apache.catalina.valves.AccessLogValve;
import org.apache.catalina.valves.RemoteIpValve;
import org.apache.coyote.AbstractProtocol;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.apache.coyote.http2.Http2Protocol;
import org.eclipse.jetty.server.AbstractConnector;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.Handler;
Expand All @@ -45,7 +47,9 @@
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.boot.web.server.Http2;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
Expand Down Expand Up @@ -112,6 +116,9 @@ public void customize(ConfigurableServletWebServerFactory factory) {
if (this.serverProperties.getSsl() != null) {
factory.setSsl(this.serverProperties.getSsl());
}
if (this.serverProperties.getHttp2() != null) {
factory.setHttp2(this.serverProperties.getHttp2());
}
if (this.serverProperties.getServlet() != null) {
factory.setJsp(this.serverProperties.getServlet().getJsp());
}
Expand Down Expand Up @@ -213,6 +220,8 @@ private static class TomcatCustomizer {
public static void customizeTomcat(ServerProperties serverProperties,
Environment environment, TomcatServletWebServerFactory factory) {

customizeTomcatHttp2(factory, serverProperties);

ServerProperties.Tomcat tomcatProperties = serverProperties.getTomcat();
if (tomcatProperties.getBasedir() != null) {
factory.setBaseDirectory(tomcatProperties.getBasedir());
Expand Down Expand Up @@ -261,6 +270,25 @@ public static void customizeTomcat(ServerProperties serverProperties,
}
}

private static void customizeTomcatHttp2(TomcatServletWebServerFactory factory,
ServerProperties serverProperties) {

Http2 http2Properties = serverProperties.getHttp2();

if (http2Properties.isEnabled()) {
enableHttp2ForTomcat(factory);
}
}

private static void enableHttp2ForTomcat(TomcatServletWebServerFactory factory) {

factory.addContextCustomizers((context) ->
context.addLifecycleListener(new AprLifecycleListener()));

factory.addConnectorCustomizers((connector) ->
connector.addUpgradeProtocol(new Http2Protocol()));
}

private static void customizeAcceptCount(TomcatServletWebServerFactory factory,
final int acceptCount) {
factory.addConnectorCustomizers((connector) -> {
Expand Down Expand Up @@ -391,6 +419,8 @@ private static class UndertowCustomizer {
protected static void customizeUndertow(final ServerProperties serverProperties,
Environment environment, UndertowServletWebServerFactory factory) {

customizeUndertowHttp2(factory, serverProperties);

ServerProperties.Undertow undertowProperties = serverProperties.getUndertow();
ServerProperties.Undertow.Accesslog accesslogProperties = undertowProperties
.getAccesslog();
Expand Down Expand Up @@ -432,6 +462,15 @@ protected static void customizeUndertow(final ServerProperties serverProperties,
.setEagerFilterInit(undertowProperties.isEagerFilterInit()));
}

private static void customizeUndertowHttp2(UndertowServletWebServerFactory factory,
ServerProperties serverProperties) {

Http2 http2Properties = serverProperties.getHttp2();
factory.addBuilderCustomizers((UndertowBuilderCustomizer) builder -> {
builder.setServerOption(UndertowOptions.ENABLE_HTTP2, http2Properties.isEnabled());
});
}

private static void customizeConnectionTimeout(
UndertowServletWebServerFactory factory, final int connectionTimeout) {
factory.addBuilderCustomizers((builder) -> builder.setSocketOption(
Expand Down
18 changes: 17 additions & 1 deletion spring-boot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
<jedis.version>2.9.0</jedis.version>
<jersey.version>2.26</jersey.version>
<jest.version>5.3.2</jest.version>
<jetty.version>9.4.6.v20170531</jetty.version>
<jetty.version>9.4.7.v20170914</jetty.version>
<jetty-alpn-api.version>1.1.3.v20160715</jetty-alpn-api.version>
<jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
<jetty-el.version>8.5.9.1</jetty-el.version>
<jmustache.version>1.13</jmustache.version>
Expand Down Expand Up @@ -1645,6 +1646,21 @@
<artifactId>jetty-xml</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.alpn</groupId>
<artifactId>alpn-api</artifactId>
<version>${jetty-alpn-api.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-java-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ content into your application; rather pick only the properties that you need.
server.error.include-stacktrace=never # When to include a "stacktrace" attribute.
server.error.path=/error # Path of the error controller.
server.error.whitelabel.enabled=true # Enable the default error page displayed in browsers in case of a server error.
server.http2.enabled=false # If HTTP/2 is enabled.
server.jetty.acceptors= # Number of acceptor threads to use.
server.jetty.accesslog.append=false # Append to log.
server.jetty.accesslog.date-format=dd/MMM/yyyy:HH:mm:ss Z # Timestamp format of the request log.
Expand Down
3 changes: 3 additions & 0 deletions spring-boot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<module>spring-boot-sample-jetty</module>
<module>spring-boot-sample-jetty-jsp</module>
<module>spring-boot-sample-jetty-ssl</module>
<module>spring-boot-sample-jetty-http2</module>
<module>spring-boot-sample-jooq</module>
<module>spring-boot-sample-jpa</module>
<module>spring-boot-sample-jta-atomikos</module>
Expand All @@ -76,10 +77,12 @@
<module>spring-boot-sample-tomcat</module>
<module>spring-boot-sample-tomcat-jsp</module>
<module>spring-boot-sample-tomcat-ssl</module>
<module>spring-boot-sample-tomcat-http2</module>
<module>spring-boot-sample-tomcat-multi-connectors</module>
<module>spring-boot-sample-traditional</module>
<module>spring-boot-sample-undertow</module>
<module>spring-boot-sample-undertow-ssl</module>
<module>spring-boot-sample-undertow-http2</module>
<module>spring-boot-sample-war</module>
<module>spring-boot-sample-web-freemarker</module>
<module>spring-boot-sample-web-groovy-templates</module>
Expand Down
76 changes: 76 additions & 0 deletions spring-boot-samples/spring-boot-sample-jetty-http2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-samples</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-jetty-http2</artifactId>
<name>Spring Boot Jetty HTTP/2 Sample</name>
<description>Spring Boot Jetty HTTP/2 Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<!-- Compile -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-common</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.alpn</groupId>
<artifactId>alpn-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-java-server</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package sample.jetty.http2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class SampleJettyHttp2Application {

public static void main(String[] args) throws Exception {
SpringApplication.run(SampleJettyHttp2Application.class, args);
}

@GetMapping("/")
public String helloWorld() {
return "Hello, world";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
server.port = 8443
server.http2.enabled = true
server.ssl.key-store = classpath:sample.jks
server.ssl.key-store-password = secret
server.ssl.key-password = password
Binary file not shown.
Loading