Skip to content

Commit a2dfda9

Browse files
committed
Provide working sample for Undertow using HTTP/2
1 parent f965f38 commit a2dfda9

File tree

6 files changed

+151
-0
lines changed

6 files changed

+151
-0
lines changed

spring-boot-samples/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
<module>spring-boot-sample-traditional</module>
8787
<module>spring-boot-sample-undertow</module>
8888
<module>spring-boot-sample-undertow-ssl</module>
89+
<module>spring-boot-sample-undertow-http2</module>
8990
<module>spring-boot-sample-war</module>
9091
<module>spring-boot-sample-web-freemarker</module>
9192
<module>spring-boot-sample-web-groovy-templates</module>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<!-- Your own application should inherit from spring-boot-starter-parent -->
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-samples</artifactId>
8+
<version>2.0.0.BUILD-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>spring-boot-sample-undertow-http2</artifactId>
11+
<name>Spring Boot Undertow HTTP/2 Sample</name>
12+
<description>Spring Boot Undertow HTTP/2 Sample</description>
13+
<url>http://projects.spring.io/spring-boot/</url>
14+
<organization>
15+
<name>Pivotal Software, Inc.</name>
16+
<url>http://www.spring.io</url>
17+
</organization>
18+
<properties>
19+
<main.basedir>${basedir}/../..</main.basedir>
20+
</properties>
21+
<dependencies>
22+
<!-- Compile -->
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-undertow</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework</groupId>
33+
<artifactId>spring-webmvc</artifactId>
34+
</dependency>
35+
<!-- Test -->
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-test</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.httpcomponents</groupId>
43+
<artifactId>httpclient</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
<build>
48+
<plugins>
49+
<plugin>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-maven-plugin</artifactId>
52+
</plugin>
53+
</plugins>
54+
</build>
55+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sample.undertow.http2;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
import org.springframework.web.bind.annotation.GetMapping;
22+
import org.springframework.web.bind.annotation.RestController;
23+
24+
@SpringBootApplication
25+
@RestController
26+
public class SampleUndertowHttp2Application {
27+
28+
public static void main(String[] args) throws Exception {
29+
SpringApplication.run(SampleUndertowHttp2Application.class, args);
30+
}
31+
32+
@GetMapping("/")
33+
public String helloWorld() {
34+
return "Hello, World";
35+
}
36+
37+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
server.port = 8443
2+
server.http2.enabled = true
3+
server.ssl.key-store = classpath:sample.jks
4+
server.ssl.key-store-password = secret
5+
server.ssl.key-password = password
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2012-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sample.undertow.http2;
18+
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
25+
import org.springframework.boot.test.web.client.TestRestTemplate;
26+
import org.springframework.http.HttpStatus;
27+
import org.springframework.http.ResponseEntity;
28+
import org.springframework.test.annotation.DirtiesContext;
29+
import org.springframework.test.context.junit4.SpringRunner;
30+
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
33+
/**
34+
* Basic integration tests for demo application.
35+
*
36+
* @author Ivan Sopov
37+
*/
38+
@RunWith(SpringRunner.class)
39+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
40+
@DirtiesContext
41+
public class SampleUndertowHttp2ApplicationTests {
42+
43+
@Autowired
44+
private TestRestTemplate restTemplate;
45+
46+
@Test
47+
public void testHome() throws Exception {
48+
ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class);
49+
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
50+
assertThat(entity.getBody()).isEqualTo("Hello World");
51+
}
52+
53+
}

0 commit comments

Comments
 (0)