diff --git a/spring-boot-docs/src/main/asciidoc/getting-started.adoc b/spring-boot-docs/src/main/asciidoc/getting-started.adoc index 43874e6045..7104f05c37 100644 --- a/spring-boot-docs/src/main/asciidoc/getting-started.adoc +++ b/spring-boot-docs/src/main/asciidoc/getting-started.adoc @@ -54,18 +54,10 @@ The following embedded servlet containers are supported out of the box: |3.1 |Java 7+ -|Jetty 9.3 +|Jetty 9.4 |3.1 |Java 8+ -|Jetty 9.2 -|3.1 -|Java 7+ - -|Jetty 8 -|3.0 -|Java 6+ - |Undertow 1.3 |3.1 |Java 7+ diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index 5c52110a02..aca580ecfe 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -930,132 +930,6 @@ add a listener to the `Builder`: -[[howto-use-jetty-9.2]] -=== Use Jetty 9.2 -Jetty 9.2 works with Spring Boot, but the default is to use Jetty 9.3. If you cannot use -Jetty 9.3 (for example, because you are using Java 7) you will need to change your -classpath to reference Jetty 9.2. - - - -[[howto-use-jetty-9.2-maven]] -==== Use Jetty 9.2 with Maven - -If you are using the starters and parent you can just add the Jetty starter and override -the `jetty.version` property: - -[source,xml,indent=0,subs="verbatim,quotes,attributes"] ----- - - 9.2.17.v20160517 - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - - - - - org.springframework.boot - spring-boot-starter-jetty - - ----- - - - -[[howto-use-jetty-9.2-gradle]] -==== Use Jetty 9.2 with Gradle - -You can set the `jetty.version` property. For example, for a simple webapp or service: - -[source,groovy,indent=0,subs="verbatim,quotes,attributes"] ----- - ext['jetty.version'] = '9.2.17.v20160517' - dependencies { - compile ('org.springframework.boot:spring-boot-starter-web') { - exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' - } - compile ('org.springframework.boot:spring-boot-starter-jetty') - } ----- - - - -[[howto-use-jetty-8]] -=== Use Jetty 8 -Jetty 8 works with Spring Boot, but the default is to use Jetty 9.3. If you cannot use -Jetty 9.3 (for example, because you are using Java 1.6) you will need to change your -classpath to reference Jetty 8. You will also need to exclude Jetty's WebSocket-related -dependencies. - - - -[[howto-use-jetty-8-maven]] -==== Use Jetty 8 with Maven - -If you are using the starters and parent you can just add the Jetty starter with -the required WebSocket exclusion and change the version properties, e.g. for a simple -webapp or service: - -[source,xml,indent=0,subs="verbatim,quotes,attributes"] ----- - - 8.1.15.v20140411 - 2.2.0.v201112011158 - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - - - - - org.springframework.boot - spring-boot-starter-jetty - - - org.eclipse.jetty.websocket - * - - - - ----- - - - -[[howto-use-jetty-8-gradle]] -==== Use Jetty 8 with Gradle - -You can set the `jetty.version` property and exclude the WebSocket dependency, e.g. for a -simple webapp or service: - -[source,groovy,indent=0,subs="verbatim,quotes,attributes"] ----- - ext['jetty.version'] = '8.1.15.v20140411' - dependencies { - compile ('org.springframework.boot:spring-boot-starter-web') { - exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' - } - compile ('org.springframework.boot:spring-boot-starter-jetty') { - exclude group: 'org.eclipse.jetty.websocket' - } - } ----- - - - [[howto-create-websocket-endpoints-using-serverendpoint]] === Create WebSocket endpoints using @ServerEndpoint If you want to use `@ServerEndpoint` in a Spring Boot application that used an embedded diff --git a/spring-boot-samples/README.adoc b/spring-boot-samples/README.adoc index fbc9704a6b..ddf3ab1292 100644 --- a/spring-boot-samples/README.adoc +++ b/spring-boot-samples/README.adoc @@ -114,18 +114,6 @@ The following sample applications are provided: | link:spring-boot-sample-jetty-jsp[spring-boot-sample-jetty-jsp] | Web application that uses JSP templates with Jetty -| link:spring-boot-sample-jetty8[spring-boot-sample-jetty8] -| Embedded Jetty 8 - -| link:spring-boot-sample-jetty8-ssl[spring-boot-sample-jetty8-ssl] -| Embedded Jetty 8 SSL - -| link:spring-boot-sample-jetty92[spring-boot-sample-jetty92] -| Embedded Jetty 9.2 - -| link:spring-boot-sample-jetty93[spring-boot-sample-jetty93] -| Embedded Jetty 9.3 - | link:spring-boot-sample-jooq[spring-boot-sample-jooq] | Stores data using jOOQ @@ -264,9 +252,6 @@ The following sample applications are provided: | link:spring-boot-sample-websocket-jetty[spring-boot-sample-websocket-jetty] | WebSocket application that uses Jetty -| link:spring-boot-sample-websocket-jetty93[spring-boot-sample-websocket-jetty93] -| WebSocket application that uses Jetty 9.3 - | link:spring-boot-sample-websocket-tomcat[spring-boot-sample-websocket-tomcat] | WebSocket application that uses Tomcat diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index 478991b99f..e9cfc28b1a 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -57,10 +57,6 @@ spring-boot-sample-jetty spring-boot-sample-jetty-jsp spring-boot-sample-jetty-ssl - spring-boot-sample-jetty8 - spring-boot-sample-jetty8-ssl - spring-boot-sample-jetty92 - spring-boot-sample-jetty93 spring-boot-sample-jooq spring-boot-sample-jpa spring-boot-sample-jta-atomikos @@ -107,7 +103,6 @@ spring-boot-sample-web-thymeleaf3 spring-boot-sample-web-ui spring-boot-sample-websocket-jetty - spring-boot-sample-websocket-jetty93 spring-boot-sample-websocket-tomcat spring-boot-sample-websocket-undertow spring-boot-sample-webservices diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/pom.xml b/spring-boot-samples/spring-boot-sample-jetty8-ssl/pom.xml deleted file mode 100644 index 8ad9461d9c..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8-ssl/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-samples - 2.0.0.BUILD-SNAPSHOT - - spring-boot-sample-jetty8-ssl - Spring Boot Jetty 8 SSL Sample - Spring Boot Jetty 8 SSL Sample - http://projects.spring.io/spring-boot/ - - Pivotal Software, Inc. - http://www.spring.io - - - ${basedir}/../.. - 8.1.15.v20140411 - 2.2.0.v201112011158 - 3.0.1 - - - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-jetty - - - org.eclipse.jetty.websocket - * - - - - - org.springframework - spring-webmvc - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.apache.httpcomponents - httpclient - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty8/ssl/SampleJetty8SslApplication.java b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty8/ssl/SampleJetty8SslApplication.java deleted file mode 100644 index a032151291..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty8/ssl/SampleJetty8SslApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2015 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.jetty8.ssl; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJetty8SslApplication { - - public static void main(String[] args) throws Exception { - SpringApplication.run(SampleJetty8SslApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty8/ssl/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty8/ssl/service/HelloWorldService.java deleted file mode 100644 index 4a4685f677..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty8/ssl/service/HelloWorldService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2015 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.jetty8.ssl.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - @Value("${name:World}") - private String name; - - public String getHelloMessage() { - return "Hello " + this.name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty8/ssl/web/SampleController.java b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty8/ssl/web/SampleController.java deleted file mode 100644 index 56bdcefc8e..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty8/ssl/web/SampleController.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2016 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.jetty8.ssl.web; - -import sample.jetty8.ssl.service.HelloWorldService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class SampleController { - - @Autowired - private HelloWorldService helloWorldService; - - @GetMapping("/") - @ResponseBody - public String helloWorld() { - return this.helloWorldService.getHelloMessage(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/application.properties deleted file mode 100644 index 953abe0d6c..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -server.port = 8443 -server.ssl.key-store = classpath:sample.jks -server.ssl.key-store-password = secret -server.ssl.key-password = password \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/sample.jks b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/sample.jks deleted file mode 100644 index 6aa9a28053..0000000000 Binary files a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/sample.jks and /dev/null differ diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java deleted file mode 100644 index 60420899cc..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2012-2016 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.jetty8.ssl; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@DirtiesContext -public class SampleJetty8SslApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @LocalServerPort - private int port; - - @Test - public void testHome() throws Exception { - ResponseEntity entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello World"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty8/pom.xml b/spring-boot-samples/spring-boot-sample-jetty8/pom.xml deleted file mode 100644 index f4f7d5c720..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-samples - 2.0.0.BUILD-SNAPSHOT - - spring-boot-sample-jetty8 - Spring Boot Jetty 8 Sample - Spring Boot Jetty 8 Sample - http://projects.spring.io/spring-boot/ - - Pivotal Software, Inc. - http://www.spring.io - - - ${basedir}/../.. - 8.1.15.v20140411 - 2.2.0.v201112011158 - - - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-jetty - - - org.eclipse.jetty.websocket - * - - - - - org.springframework - spring-webmvc - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/spring-boot-samples/spring-boot-sample-jetty8/src/main/java/sample/jetty8/SampleJetty8Application.java b/spring-boot-samples/spring-boot-sample-jetty8/src/main/java/sample/jetty8/SampleJetty8Application.java deleted file mode 100644 index 1accb53c93..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8/src/main/java/sample/jetty8/SampleJetty8Application.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2015 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.jetty8; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJetty8Application { - - public static void main(String[] args) throws Exception { - SpringApplication.run(SampleJetty8Application.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty8/src/main/java/sample/jetty8/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-jetty8/src/main/java/sample/jetty8/service/HelloWorldService.java deleted file mode 100644 index 88fc636b58..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8/src/main/java/sample/jetty8/service/HelloWorldService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2015 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.jetty8.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - @Value("${name:World}") - private String name; - - public String getHelloMessage() { - return "Hello " + this.name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty8/src/main/java/sample/jetty8/web/SampleController.java b/spring-boot-samples/spring-boot-sample-jetty8/src/main/java/sample/jetty8/web/SampleController.java deleted file mode 100644 index 5d4edaf3c6..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8/src/main/java/sample/jetty8/web/SampleController.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2016 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.jetty8.web; - -import sample.jetty8.service.HelloWorldService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class SampleController { - - @Autowired - private HelloWorldService helloWorldService; - - @GetMapping("/") - @ResponseBody - public String helloWorld() { - return this.helloWorldService.getHelloMessage(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty8/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-jetty8/src/main/resources/application.properties deleted file mode 100644 index d919692f58..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -server.compression.enabled: true -server.compression.min-response-size: 1 -server.max-http-header-size: 4096 diff --git a/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java deleted file mode 100644 index 5165011db8..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2012-2016 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.jetty8; - -import java.io.ByteArrayInputStream; -import java.nio.charset.Charset; -import java.util.zip.GZIPInputStream; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.StreamUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - * @author Andy Wilkinson - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@DirtiesContext -public class SampleJetty8ApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - public void testHome() throws Exception { - ResponseEntity entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello World"); - } - - @Test - public void testCompression() throws Exception { - HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.set("Accept-Encoding", "gzip"); - HttpEntity requestEntity = new HttpEntity(requestHeaders); - ResponseEntity entity = this.restTemplate.exchange("/", HttpMethod.GET, - requestEntity, byte[].class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - GZIPInputStream inflater = new GZIPInputStream( - new ByteArrayInputStream(entity.getBody())); - try { - assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))) - .isEqualTo("Hello World"); - } - finally { - inflater.close(); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty92/pom.xml b/spring-boot-samples/spring-boot-sample-jetty92/pom.xml deleted file mode 100644 index a71d7137ee..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty92/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-samples - 2.0.0.BUILD-SNAPSHOT - - spring-boot-sample-jetty92 - Spring Boot Jetty 9.2 Sample - Spring Boot Jetty 9.2 Sample - http://projects.spring.io/spring-boot/ - - Pivotal Software, Inc. - http://www.spring.io - - - ${basedir}/../.. - 9.2.17.v20160517 - - - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-jetty - - - org.springframework - spring-webmvc - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/spring-boot-samples/spring-boot-sample-jetty92/src/main/java/sample/jetty92/SampleJetty92Application.java b/spring-boot-samples/spring-boot-sample-jetty92/src/main/java/sample/jetty92/SampleJetty92Application.java deleted file mode 100644 index 4295be16d8..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty92/src/main/java/sample/jetty92/SampleJetty92Application.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2016 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.jetty92; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJetty92Application { - - public static void main(String[] args) throws Exception { - SpringApplication.run(SampleJetty92Application.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty92/src/main/java/sample/jetty92/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-jetty92/src/main/java/sample/jetty92/service/HelloWorldService.java deleted file mode 100644 index e8e4bd9e83..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty92/src/main/java/sample/jetty92/service/HelloWorldService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2016 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.jetty92.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - @Value("${name:World}") - private String name; - - public String getHelloMessage() { - return "Hello " + this.name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty92/src/main/java/sample/jetty92/web/SampleController.java b/spring-boot-samples/spring-boot-sample-jetty92/src/main/java/sample/jetty92/web/SampleController.java deleted file mode 100644 index ce573c062b..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty92/src/main/java/sample/jetty92/web/SampleController.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2016 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.jetty92.web; - -import sample.jetty92.service.HelloWorldService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class SampleController { - - @Autowired - private HelloWorldService helloWorldService; - - @GetMapping("/") - @ResponseBody - public String helloWorld() { - return this.helloWorldService.getHelloMessage(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty92/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-jetty92/src/main/resources/application.properties deleted file mode 100644 index 09ab26becc..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty92/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -server.compression.enabled: true -server.compression.min-response-size: 1 diff --git a/spring-boot-samples/spring-boot-sample-jetty92/src/test/java/sample/jetty92/SampleJetty92ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty92/src/test/java/sample/jetty92/SampleJetty92ApplicationTests.java deleted file mode 100644 index 622317654b..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty92/src/test/java/sample/jetty92/SampleJetty92ApplicationTests.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2012-2016 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.jetty92; - -import java.io.ByteArrayInputStream; -import java.nio.charset.Charset; -import java.util.zip.GZIPInputStream; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.StreamUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - * @author Andy Wilkinson - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@DirtiesContext -public class SampleJetty92ApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - public void testHome() throws Exception { - ResponseEntity entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello World"); - } - - @Test - public void testCompression() throws Exception { - HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.set("Accept-Encoding", "gzip"); - HttpEntity requestEntity = new HttpEntity(requestHeaders); - ResponseEntity entity = this.restTemplate.exchange("/", HttpMethod.GET, - requestEntity, byte[].class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - GZIPInputStream inflater = new GZIPInputStream( - new ByteArrayInputStream(entity.getBody())); - try { - assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))) - .isEqualTo("Hello World"); - } - finally { - inflater.close(); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/pom.xml b/spring-boot-samples/spring-boot-sample-websocket-jetty93/pom.xml deleted file mode 100755 index 0eb97a65f3..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-samples - 2.0.0.BUILD-SNAPSHOT - - spring-boot-sample-websocket-jetty93 - Spring Boot WebSocket Jetty 9.3 Sample - Spring Boot WebSocket Jetty 9.3 Sample - http://projects.spring.io/spring-boot/ - - Pivotal Software, Inc. - http://www.spring.io - - - ${basedir}/../.. - 9.3.14.v20161028 - - - - - org.springframework.boot - spring-boot-starter-websocket - - - org.springframework.boot - spring-boot-starter-tomcat - - - - - org.springframework.boot - spring-boot-starter-jetty - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/SampleJetty93WebSocketsApplication.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/SampleJetty93WebSocketsApplication.java deleted file mode 100644 index 0a4557c1de..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/SampleJetty93WebSocketsApplication.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2012-2016 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 samples.websocket.jetty93; - -import samples.websocket.jetty93.client.GreetingService; -import samples.websocket.jetty93.client.SimpleGreetingService; -import samples.websocket.jetty93.echo.DefaultEchoService; -import samples.websocket.jetty93.echo.EchoService; -import samples.websocket.jetty93.echo.EchoWebSocketHandler; -import samples.websocket.jetty93.reverse.ReverseWebSocketEndpoint; -import samples.websocket.jetty93.snake.SnakeWebSocketHandler; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.WebSocketHandler; -import org.springframework.web.socket.config.annotation.EnableWebSocket; -import org.springframework.web.socket.config.annotation.WebSocketConfigurer; -import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; -import org.springframework.web.socket.handler.PerConnectionWebSocketHandler; -import org.springframework.web.socket.server.standard.ServerEndpointExporter; - -@Configuration -@EnableAutoConfiguration -@EnableWebSocket -public class SampleJetty93WebSocketsApplication extends SpringBootServletInitializer - implements WebSocketConfigurer { - - @Override - public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(echoWebSocketHandler(), "/echo").withSockJS(); - registry.addHandler(snakeWebSocketHandler(), "/snake").withSockJS(); - } - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleJetty93WebSocketsApplication.class); - } - - @Bean - public EchoService echoService() { - return new DefaultEchoService("Did you say \"%s\"?"); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - @Bean - public WebSocketHandler echoWebSocketHandler() { - return new EchoWebSocketHandler(echoService()); - } - - @Bean - public WebSocketHandler snakeWebSocketHandler() { - return new PerConnectionWebSocketHandler(SnakeWebSocketHandler.class); - } - - @Bean - public ReverseWebSocketEndpoint reverseWebSocketEndpoint() { - return new ReverseWebSocketEndpoint(); - } - - @Bean - public ServerEndpointExporter serverEndpointExporter() { - return new ServerEndpointExporter(); - } - - public static void main(String[] args) { - SpringApplication.run(SampleJetty93WebSocketsApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/client/GreetingService.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/client/GreetingService.java deleted file mode 100644 index 05b11380a8..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/client/GreetingService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2016 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 samples.websocket.jetty93.client; - -public interface GreetingService { - - String getGreeting(); - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/client/SimpleClientWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/client/SimpleClientWebSocketHandler.java deleted file mode 100644 index 33c28bba03..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/client/SimpleClientWebSocketHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2012-2016 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 samples.websocket.jetty93.client; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -public class SimpleClientWebSocketHandler extends TextWebSocketHandler { - - protected Log logger = LogFactory.getLog(SimpleClientWebSocketHandler.class); - - private final GreetingService greetingService; - - private final CountDownLatch latch; - - private final AtomicReference messagePayload; - - public SimpleClientWebSocketHandler(GreetingService greetingService, - CountDownLatch latch, AtomicReference message) { - this.greetingService = greetingService; - this.latch = latch; - this.messagePayload = message; - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) throws Exception { - TextMessage message = new TextMessage(this.greetingService.getGreeting()); - session.sendMessage(message); - } - - @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { - this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")"); - session.close(); - this.messagePayload.set(message.getPayload()); - this.latch.countDown(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/client/SimpleGreetingService.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/client/SimpleGreetingService.java deleted file mode 100644 index d394bb5a2f..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/client/SimpleGreetingService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2012-2016 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 samples.websocket.jetty93.client; - -public class SimpleGreetingService implements GreetingService { - - @Override - public String getGreeting() { - return "Hello world!"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/echo/DefaultEchoService.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/echo/DefaultEchoService.java deleted file mode 100644 index 547154572c..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/echo/DefaultEchoService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2016 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 samples.websocket.jetty93.echo; - -public class DefaultEchoService implements EchoService { - - private final String echoFormat; - - public DefaultEchoService(String echoFormat) { - this.echoFormat = (echoFormat != null) ? echoFormat : "%s"; - } - - @Override - public String getMessage(String message) { - return String.format(this.echoFormat, message); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/echo/EchoService.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/echo/EchoService.java deleted file mode 100644 index c7d6bb852d..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/echo/EchoService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2016 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 samples.websocket.jetty93.echo; - -public interface EchoService { - - String getMessage(String message); - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/echo/EchoWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/echo/EchoWebSocketHandler.java deleted file mode 100644 index f7dfaabcbb..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/echo/EchoWebSocketHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2016 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 samples.websocket.jetty93.echo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.web.socket.CloseStatus; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketHandler; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -/** - * Echo messages by implementing a Spring {@link WebSocketHandler} abstraction. - */ -public class EchoWebSocketHandler extends TextWebSocketHandler { - - private static Logger logger = LoggerFactory.getLogger(EchoWebSocketHandler.class); - - private final EchoService echoService; - - public EchoWebSocketHandler(EchoService echoService) { - this.echoService = echoService; - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) { - logger.debug("Opened new session in instance " + this); - } - - @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { - String echoMessage = this.echoService.getMessage(message.getPayload()); - logger.debug(echoMessage); - session.sendMessage(new TextMessage(echoMessage)); - } - - @Override - public void handleTransportError(WebSocketSession session, Throwable exception) - throws Exception { - session.close(CloseStatus.SERVER_ERROR); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/reverse/ReverseWebSocketEndpoint.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/reverse/ReverseWebSocketEndpoint.java deleted file mode 100644 index cd032aa70b..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/reverse/ReverseWebSocketEndpoint.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2016 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 samples.websocket.jetty93.reverse; - -import java.io.IOException; - -import javax.websocket.OnMessage; -import javax.websocket.Session; -import javax.websocket.server.ServerEndpoint; - -@ServerEndpoint("/reverse") -public class ReverseWebSocketEndpoint { - - @OnMessage - public void handleMessage(Session session, String message) throws IOException { - session.getBasicRemote() - .sendText("Reversed: " + new StringBuilder(message).reverse()); - } -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Direction.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Direction.java deleted file mode 100644 index 5b416b780b..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Direction.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 samples.websocket.jetty93.snake; - -public enum Direction { - NONE, NORTH, SOUTH, EAST, WEST -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Location.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Location.java deleted file mode 100644 index 4f56cbe7be..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Location.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 samples.websocket.jetty93.snake; - -public class Location { - - public int x; - public int y; - public static final int GRID_SIZE = 10; - public static final int PLAYFIELD_HEIGHT = 480; - public static final int PLAYFIELD_WIDTH = 640; - - public Location(int x, int y) { - this.x = x; - this.y = y; - } - - public Location getAdjacentLocation(Direction direction) { - switch (direction) { - case NORTH: - return new Location(this.x, this.y - Location.GRID_SIZE); - case SOUTH: - return new Location(this.x, this.y + Location.GRID_SIZE); - case EAST: - return new Location(this.x + Location.GRID_SIZE, this.y); - case WEST: - return new Location(this.x - Location.GRID_SIZE, this.y); - case NONE: - // fall through - default: - return this; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - Location location = (Location) o; - - if (this.x != location.x) { - return false; - } - if (this.y != location.y) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result = this.x; - result = 31 * result + this.y; - return result; - } -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Snake.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Snake.java deleted file mode 100644 index af9ad2033f..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Snake.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 samples.websocket.jetty93.snake; - -import java.util.ArrayDeque; -import java.util.Collection; -import java.util.Deque; - -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; - -public class Snake { - - private static final int DEFAULT_LENGTH = 5; - - private final Deque tail = new ArrayDeque(); - - private final Object monitor = new Object(); - - private final int id; - - private final WebSocketSession session; - - private final String hexColor; - - private Direction direction; - - private int length = DEFAULT_LENGTH; - - private Location head; - - public Snake(int id, WebSocketSession session) { - this.id = id; - this.session = session; - this.hexColor = SnakeUtils.getRandomHexColor(); - resetState(); - } - - private void resetState() { - this.direction = Direction.NONE; - this.head = SnakeUtils.getRandomLocation(); - this.tail.clear(); - this.length = DEFAULT_LENGTH; - } - - private void kill() throws Exception { - synchronized (this.monitor) { - resetState(); - sendMessage("{'type': 'dead'}"); - } - } - - private void reward() throws Exception { - synchronized (this.monitor) { - this.length++; - sendMessage("{'type': 'kill'}"); - } - } - - protected void sendMessage(String msg) throws Exception { - this.session.sendMessage(new TextMessage(msg)); - } - - public void update(Collection snakes) throws Exception { - synchronized (this.monitor) { - Location nextLocation = this.head.getAdjacentLocation(this.direction); - if (nextLocation.x >= SnakeUtils.PLAYFIELD_WIDTH) { - nextLocation.x = 0; - } - if (nextLocation.y >= SnakeUtils.PLAYFIELD_HEIGHT) { - nextLocation.y = 0; - } - if (nextLocation.x < 0) { - nextLocation.x = SnakeUtils.PLAYFIELD_WIDTH; - } - if (nextLocation.y < 0) { - nextLocation.y = SnakeUtils.PLAYFIELD_HEIGHT; - } - if (this.direction != Direction.NONE) { - this.tail.addFirst(this.head); - if (this.tail.size() > this.length) { - this.tail.removeLast(); - } - this.head = nextLocation; - } - - handleCollisions(snakes); - } - } - - private void handleCollisions(Collection snakes) throws Exception { - for (Snake snake : snakes) { - boolean headCollision = this.id != snake.id - && snake.getHead().equals(this.head); - boolean tailCollision = snake.getTail().contains(this.head); - if (headCollision || tailCollision) { - kill(); - if (this.id != snake.id) { - snake.reward(); - } - } - } - } - - public Location getHead() { - synchronized (this.monitor) { - return this.head; - } - } - - public Collection getTail() { - synchronized (this.monitor) { - return this.tail; - } - } - - public void setDirection(Direction direction) { - synchronized (this.monitor) { - this.direction = direction; - } - } - - public String getLocationsJson() { - synchronized (this.monitor) { - StringBuilder sb = new StringBuilder(); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), - Integer.valueOf(this.head.y))); - for (Location location : this.tail) { - sb.append(','); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), - Integer.valueOf(location.y))); - } - return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), - sb.toString()); - } - } - - public int getId() { - return this.id; - } - - public String getHexColor() { - return this.hexColor; - } -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeTimer.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeTimer.java deleted file mode 100644 index 962dfea0e9..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeTimer.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 samples.websocket.jetty93.snake; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Sets up the timer for the multi-player snake game WebSocket example. - */ -public class SnakeTimer { - - private static final long TICK_DELAY = 100; - - private static final Object MONITOR = new Object(); - - private static final Logger log = LoggerFactory.getLogger(SnakeTimer.class); - - private static final ConcurrentHashMap snakes = new ConcurrentHashMap(); - - private static Timer gameTimer = null; - - public static void addSnake(Snake snake) { - synchronized (MONITOR) { - if (snakes.isEmpty()) { - startTimer(); - } - snakes.put(Integer.valueOf(snake.getId()), snake); - } - } - - public static Collection getSnakes() { - return Collections.unmodifiableCollection(snakes.values()); - } - - public static void removeSnake(Snake snake) { - synchronized (MONITOR) { - snakes.remove(Integer.valueOf(snake.getId())); - if (snakes.isEmpty()) { - stopTimer(); - } - } - } - - public static void tick() throws Exception { - StringBuilder sb = new StringBuilder(); - for (Iterator iterator = SnakeTimer.getSnakes().iterator(); iterator - .hasNext();) { - Snake snake = iterator.next(); - snake.update(SnakeTimer.getSnakes()); - sb.append(snake.getLocationsJson()); - if (iterator.hasNext()) { - sb.append(','); - } - } - broadcast(String.format("{'type': 'update', 'data' : [%s]}", sb.toString())); - } - - public static void broadcast(String message) throws Exception { - Collection snakes = new CopyOnWriteArrayList<>(SnakeTimer.getSnakes()); - for (Snake snake : snakes) { - try { - snake.sendMessage(message); - } - catch (Throwable ex) { - // if Snake#sendMessage fails the client is removed - removeSnake(snake); - } - } - } - - public static void startTimer() { - gameTimer = new Timer(SnakeTimer.class.getSimpleName() + " Timer"); - gameTimer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - try { - tick(); - } - catch (Throwable ex) { - log.error("Caught to prevent timer from shutting down", ex); - } - } - }, TICK_DELAY, TICK_DELAY); - } - - public static void stopTimer() { - if (gameTimer != null) { - gameTimer.cancel(); - } - } -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeUtils.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeUtils.java deleted file mode 100644 index 7c25906128..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 samples.websocket.jetty93.snake; - -import java.awt.Color; -import java.util.Random; - -public class SnakeUtils { - - public static final int PLAYFIELD_WIDTH = 640; - public static final int PLAYFIELD_HEIGHT = 480; - public static final int GRID_SIZE = 10; - - private static final Random random = new Random(); - - public static String getRandomHexColor() { - float hue = random.nextFloat(); - // sat between 0.1 and 0.3 - float saturation = (random.nextInt(2000) + 1000) / 10000f; - float luminance = 0.9f; - Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000) - .substring(1); - } - - public static Location getRandomLocation() { - int x = roundByGridSize(random.nextInt(PLAYFIELD_WIDTH)); - int y = roundByGridSize(random.nextInt(PLAYFIELD_HEIGHT)); - return new Location(x, y); - } - - private static int roundByGridSize(int value) { - value = value + (GRID_SIZE / 2); - value = value / GRID_SIZE; - value = value * GRID_SIZE; - return value; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeWebSocketHandler.java deleted file mode 100644 index 3630947367..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeWebSocketHandler.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 samples.websocket.jetty93.snake; - -import java.awt.Color; -import java.util.Iterator; -import java.util.Random; -import java.util.concurrent.atomic.AtomicInteger; - -import org.springframework.web.socket.CloseStatus; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -public class SnakeWebSocketHandler extends TextWebSocketHandler { - - public static final int PLAYFIELD_WIDTH = 640; - public static final int PLAYFIELD_HEIGHT = 480; - public static final int GRID_SIZE = 10; - - private static final AtomicInteger snakeIds = new AtomicInteger(0); - private static final Random random = new Random(); - - private final int id; - private Snake snake; - - public static String getRandomHexColor() { - float hue = random.nextFloat(); - // sat between 0.1 and 0.3 - float saturation = (random.nextInt(2000) + 1000) / 10000f; - float luminance = 0.9f; - Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000) - .substring(1); - } - - public static Location getRandomLocation() { - int x = roundByGridSize(random.nextInt(PLAYFIELD_WIDTH)); - int y = roundByGridSize(random.nextInt(PLAYFIELD_HEIGHT)); - return new Location(x, y); - } - - private static int roundByGridSize(int value) { - value = value + (GRID_SIZE / 2); - value = value / GRID_SIZE; - value = value * GRID_SIZE; - return value; - } - - public SnakeWebSocketHandler() { - this.id = snakeIds.getAndIncrement(); - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) throws Exception { - this.snake = new Snake(this.id, session); - SnakeTimer.addSnake(this.snake); - StringBuilder sb = new StringBuilder(); - for (Iterator iterator = SnakeTimer.getSnakes().iterator(); iterator - .hasNext();) { - Snake snake = iterator.next(); - sb.append(String.format("{id: %d, color: '%s'}", - Integer.valueOf(snake.getId()), snake.getHexColor())); - if (iterator.hasNext()) { - sb.append(','); - } - } - SnakeTimer - .broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); - } - - @Override - protected void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { - String payload = message.getPayload(); - if ("west".equals(payload)) { - this.snake.setDirection(Direction.WEST); - } - else if ("north".equals(payload)) { - this.snake.setDirection(Direction.NORTH); - } - else if ("east".equals(payload)) { - this.snake.setDirection(Direction.EAST); - } - else if ("south".equals(payload)) { - this.snake.setDirection(Direction.SOUTH); - } - } - - @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus status) - throws Exception { - SnakeTimer.removeSnake(this.snake); - SnakeTimer.broadcast( - String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); - } -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/echo.html b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/echo.html deleted file mode 100644 index 9a0a7650bf..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/echo.html +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - Apache Tomcat WebSocket Examples: Echo - - - - - - -
-
-
- -
-
- - -
-
- -
-
- -
-
-
-
-
-
- - diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/index.html b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/index.html deleted file mode 100644 index e9585067a3..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/index.html +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - Apache Tomcat WebSocket Examples: Index - - - -

Please select the sample you would like to try.

- - - diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/reverse.html b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/reverse.html deleted file mode 100644 index be2c043930..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/reverse.html +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - WebSocket Examples: Reverse - - - - - -
-
-
- -
-
- - -
-
- -
-
- -
-
-
-
-
-
- - diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/snake.html b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/snake.html deleted file mode 100644 index d305381069..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/resources/static/snake.html +++ /dev/null @@ -1,250 +0,0 @@ - - - - - - - Apache Tomcat WebSocket Examples: Multiplayer Snake - - - - - - -
- -
-
-
-
- - - diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/SampleWebSocketsApplicationTests.java deleted file mode 100644 index da4364c7d7..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/SampleWebSocketsApplicationTests.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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 samples.websocket.jetty93; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Test; -import org.junit.runner.RunWith; -import samples.websocket.jetty93.SampleJetty93WebSocketsApplication; -import samples.websocket.jetty93.client.GreetingService; -import samples.websocket.jetty93.client.SimpleClientWebSocketHandler; -import samples.websocket.jetty93.client.SimpleGreetingService; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.LocalServerPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = SampleJetty93WebSocketsApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) -@DirtiesContext -public class SampleWebSocketsApplicationTests { - - private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); - - @LocalServerPort - private int port = 1234; - - @Test - public void echoEndpoint() throws Exception { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port - + "/echo/websocket") - .run("--spring.main.web_environment=false"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()) - .isEqualTo("Did you say \"Hello world!\"?"); - } - - @Test - public void reverseEndpoint() throws Exception { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties( - "websocket.uri:ws://localhost:" + this.port + "/reverse") - .run("--spring.main.web_environment=false"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); - } - - @Configuration - static class ClientConfiguration implements CommandLineRunner { - - @Value("${websocket.uri}") - private String webSocketUri; - - private final CountDownLatch latch = new CountDownLatch(1); - - private final AtomicReference messagePayload = new AtomicReference(); - - @Override - public void run(String... args) throws Exception { - logger.info("Waiting for response: latch=" + this.latch.getCount()); - if (this.latch.await(10, TimeUnit.SECONDS)) { - logger.info("Got response: " + this.messagePayload.get()); - } - else { - logger.info("Response not received: latch=" + this.latch.getCount()); - } - } - - @Bean - public WebSocketConnectionManager wsConnectionManager() { - - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), - handler(), this.webSocketUri); - manager.setAutoStartup(true); - - return manager; - } - - @Bean - public StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } - - @Bean - public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, - this.messagePayload); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/echo/CustomContainerWebSocketsApplicationTests.java deleted file mode 100644 index 6a86898922..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/echo/CustomContainerWebSocketsApplicationTests.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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 samples.websocket.jetty93.echo; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Test; -import org.junit.runner.RunWith; -import samples.websocket.jetty93.SampleJetty93WebSocketsApplication; -import samples.websocket.jetty93.client.GreetingService; -import samples.websocket.jetty93.client.SimpleClientWebSocketHandler; -import samples.websocket.jetty93.client.SimpleGreetingService; -import samples.websocket.jetty93.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.SocketUtils; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = { SampleJetty93WebSocketsApplication.class, - CustomContainerConfiguration.class }, webEnvironment = WebEnvironment.DEFINED_PORT) -@DirtiesContext -public class CustomContainerWebSocketsApplicationTests { - - private static Log logger = LogFactory - .getLog(CustomContainerWebSocketsApplicationTests.class); - - private static int PORT = SocketUtils.findAvailableTcpPort(); - - @Test - public void echoEndpoint() throws Exception { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + PORT - + "/ws/echo/websocket") - .run("--spring.main.web_environment=false"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()) - .isEqualTo("Did you say \"Hello world!\"?"); - } - - @Test - public void reverseEndpoint() throws Exception { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties( - "websocket.uri:ws://localhost:" + PORT + "/ws/reverse") - .run("--spring.main.web_environment=false"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); - } - - @Configuration - protected static class CustomContainerConfiguration { - - @Bean - public EmbeddedServletContainerFactory embeddedServletContainerFactory() { - return new JettyEmbeddedServletContainerFactory("/ws", PORT); - } - - } - - @Configuration - static class ClientConfiguration implements CommandLineRunner { - - @Value("${websocket.uri}") - private String webSocketUri; - - private final CountDownLatch latch = new CountDownLatch(1); - - private final AtomicReference messagePayload = new AtomicReference(); - - @Override - public void run(String... args) throws Exception { - logger.info("Waiting for response: latch=" + this.latch.getCount()); - if (this.latch.await(10, TimeUnit.SECONDS)) { - logger.info("Got response: " + this.messagePayload.get()); - } - else { - logger.info("Response not received: latch=" + this.latch.getCount()); - } - } - - @Bean - public WebSocketConnectionManager wsConnectionManager() { - - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), - handler(), this.webSocketUri); - manager.setAutoStartup(true); - - return manager; - } - - @Bean - public StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } - - @Bean - public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, - this.messagePayload); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/snake/SnakeTimerTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/snake/SnakeTimerTests.java deleted file mode 100644 index 21b97dd5ac..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/snake/SnakeTimerTests.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2016 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 samples.websocket.jetty93.snake; - -import java.io.IOException; - -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Mockito.mock; - -public class SnakeTimerTests { - - @Test - public void removeDysfunctionalSnakes() throws Exception { - Snake snake = mock(Snake.class); - willThrow(new IOException()).given(snake).sendMessage(anyString()); - SnakeTimer.addSnake(snake); - - SnakeTimer.broadcast(""); - assertThat(SnakeTimer.getSnakes()).hasSize(0); - } - -} diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java index dd6845ccbd..b7fbd037a5 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * 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. @@ -18,18 +18,15 @@ package org.springframework.boot.context.embedded.jetty; import java.io.File; import java.io.IOException; -import java.lang.reflect.Method; import java.net.InetSocketAddress; import java.net.URL; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Set; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -79,9 +76,7 @@ import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; -import org.springframework.util.ReflectionUtils; import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; @@ -107,16 +102,6 @@ import org.springframework.util.StringUtils; public class JettyEmbeddedServletContainerFactory extends AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware { - private static final String GZIP_HANDLER_JETTY_9_2 = "org.eclipse.jetty.servlets.gzip.GzipHandler"; - - private static final String GZIP_HANDLER_JETTY_8 = "org.eclipse.jetty.server.handler.GzipHandler"; - - private static final String GZIP_HANDLER_JETTY_9_3 = "org.eclipse.jetty.server.handler.gzip.GzipHandler"; - - private static final String CONNECTOR_JETTY_8 = "org.eclipse.jetty.server.nio.SelectChannelConnector"; - - private static final String SESSION_JETTY_9_3 = "org.eclipse.jetty.server.session.HashSessionManager"; - private List configurations = new ArrayList(); private boolean useForwardHeaders; @@ -176,8 +161,8 @@ public class JettyEmbeddedServletContainerFactory if (getSsl() != null && getSsl().isEnabled()) { SslContextFactory sslContextFactory = new SslContextFactory(); configureSsl(sslContextFactory, getSsl()); - AbstractConnector connector = getSslServerConnectorFactory() - .getConnector(server, sslContextFactory, port); + AbstractConnector connector = createSslConnector(server, sslContextFactory, + port); server.setConnectors(new Connector[] { connector }); } for (JettyServerCustomizer customizer : getServerCustomizers()) { @@ -190,24 +175,37 @@ public class JettyEmbeddedServletContainerFactory } private Server createServer(InetSocketAddress address) { - Server server; - if (ClassUtils.hasConstructor(Server.class, ThreadPool.class)) { - server = new Jetty9ServerFactory().createServer(getThreadPool()); - } - else { - server = new Jetty8ServerFactory().createServer(getThreadPool()); - } + Server server = new Server(getThreadPool()); server.setConnectors(new Connector[] { createConnector(address, server) }); return server; } private AbstractConnector createConnector(InetSocketAddress address, Server server) { - if (ClassUtils.isPresent(CONNECTOR_JETTY_8, getClass().getClassLoader())) { - return new Jetty8ConnectorFactory().createConnector(server, address, - this.acceptors, this.selectors); + ServerConnector connector = new ServerConnector(server, this.acceptors, + this.selectors); + connector.setHost(address.getHostName()); + connector.setPort(address.getPort()); + for (ConnectionFactory connectionFactory : connector.getConnectionFactories()) { + if (connectionFactory instanceof HttpConfiguration.ConnectionFactory) { + ((HttpConfiguration.ConnectionFactory) connectionFactory) + .getHttpConfiguration().setSendServerVersion(false); + } } - return new Jetty9ConnectorFactory().createConnector(server, address, - this.acceptors, this.selectors); + return connector; + } + + private AbstractConnector createSslConnector(Server server, + SslContextFactory sslContextFactory, int port) { + HttpConfiguration config = new HttpConfiguration(); + config.setSendServerVersion(false); + config.addCustomizer(new SecureRequestCustomizer()); + HttpConnectionFactory connectionFactory = new HttpConnectionFactory(config); + SslConnectionFactory sslConnectionFactory = new SslConnectionFactory( + sslContextFactory, HttpVersion.HTTP_1_1.asString()); + ServerConnector serverConnector = new ServerConnector(server, + sslConnectionFactory, connectionFactory); + serverConnector.setPort(port); + return serverConnector; } private Handler addHandlerWrappers(Handler handler) { @@ -226,26 +224,14 @@ public class JettyEmbeddedServletContainerFactory } private HandlerWrapper createGzipHandler() { - ClassLoader classLoader = getClass().getClassLoader(); - if (ClassUtils.isPresent(GZIP_HANDLER_JETTY_9_2, classLoader)) { - return new Jetty92GzipHandlerFactory().createGzipHandler(getCompression()); + GzipHandler handler = new GzipHandler(); + Compression compression = getCompression(); + handler.setMinGzipSize(compression.getMinResponseSize()); + handler.setIncludedMimeTypes(compression.getMimeTypes()); + if (compression.getExcludedUserAgents() != null) { + handler.setExcludedAgentPatterns(compression.getExcludedUserAgents()); } - if (ClassUtils.isPresent(GZIP_HANDLER_JETTY_8, getClass().getClassLoader())) { - return new Jetty8GzipHandlerFactory().createGzipHandler(getCompression()); - } - if (ClassUtils.isPresent(GZIP_HANDLER_JETTY_9_3, getClass().getClassLoader())) { - return new Jetty93GzipHandlerFactory().createGzipHandler(getCompression()); - } - throw new IllegalStateException( - "Compression is enabled, but GzipHandler is not on the classpath"); - } - - private SslServerConnectorFactory getSslServerConnectorFactory() { - if (ClassUtils.isPresent("org.eclipse.jetty.server.ssl.SslSocketConnector", - null)) { - return new Jetty8SslServerConnectorFactory(); - } - return new Jetty9SslServerConnectorFactory(); + return handler; } /** @@ -371,17 +357,16 @@ public class JettyEmbeddedServletContainerFactory } private void configureSession(WebAppContext context) { - SessionConfigurer configurer = getSessionConfigurer(); - configurer.configure(context, getSessionTimeout(), isPersistSession(), - new SessionDirectory() { - - @Override - public File get() { - return JettyEmbeddedServletContainerFactory.this - .getValidSessionStoreDir(); - } - - }); + SessionHandler handler = context.getSessionHandler(); + handler.setMaxInactiveInterval( + getSessionTimeout() > 0 ? getSessionTimeout() : -1); + if (isPersistSession()) { + DefaultSessionCache cache = new DefaultSessionCache(handler); + FileSessionDataStore store = new FileSessionDataStore(); + store.setStoreDir(getValidSessionStoreDir()); + cache.setSessionDataStore(store); + handler.setSessionCache(cache); + } } private void addLocaleMappings(WebAppContext context) { @@ -392,13 +377,6 @@ public class JettyEmbeddedServletContainerFactory } } - private SessionConfigurer getSessionConfigurer() { - if (ClassUtils.isPresent(SESSION_JETTY_9_3, getClass().getClassLoader())) { - return new Jetty93SessionConfigurer(); - } - return new Jetty94SessionConfigurer(); - } - private File getTempDirectory() { String temp = System.getProperty("java.io.tmpdir"); return (temp == null ? null : new File(temp)); @@ -676,142 +654,6 @@ public class JettyEmbeddedServletContainerFactory } } - /** - * Factory to create the SSL {@link ServerConnector}. - */ - private interface SslServerConnectorFactory { - - AbstractConnector getConnector(Server server, SslContextFactory sslContextFactory, - int port); - - } - - /** - * {@link SslServerConnectorFactory} for Jetty 9. - */ - private static class Jetty9SslServerConnectorFactory - implements SslServerConnectorFactory { - - @Override - public ServerConnector getConnector(Server server, - SslContextFactory sslContextFactory, int port) { - HttpConfiguration config = new HttpConfiguration(); - config.setSendServerVersion(false); - config.addCustomizer(new SecureRequestCustomizer()); - HttpConnectionFactory connectionFactory = new HttpConnectionFactory(config); - SslConnectionFactory sslConnectionFactory = new SslConnectionFactory( - sslContextFactory, HttpVersion.HTTP_1_1.asString()); - ServerConnector serverConnector = new ServerConnector(server, - sslConnectionFactory, connectionFactory); - serverConnector.setPort(port); - return serverConnector; - } - - } - - /** - * {@link SslServerConnectorFactory} for Jetty 8. - */ - private static class Jetty8SslServerConnectorFactory - implements SslServerConnectorFactory { - - @Override - public AbstractConnector getConnector(Server server, - SslContextFactory sslContextFactory, int port) { - try { - Class connectorClass = Class - .forName("org.eclipse.jetty.server.ssl.SslSocketConnector"); - AbstractConnector connector = (AbstractConnector) connectorClass - .getConstructor(SslContextFactory.class) - .newInstance(sslContextFactory); - connector.getClass().getMethod("setPort", int.class).invoke(connector, - port); - return connector; - } - catch (Exception ex) { - throw new IllegalStateException(ex); - } - } - - } - - private interface GzipHandlerFactory { - - HandlerWrapper createGzipHandler(Compression compression); - - } - - private static class Jetty8GzipHandlerFactory implements GzipHandlerFactory { - - @Override - public HandlerWrapper createGzipHandler(Compression compression) { - try { - Class handlerClass = ClassUtils.forName(GZIP_HANDLER_JETTY_8, - getClass().getClassLoader()); - HandlerWrapper handler = (HandlerWrapper) handlerClass.newInstance(); - ReflectionUtils.findMethod(handlerClass, "setMinGzipSize", int.class) - .invoke(handler, compression.getMinResponseSize()); - ReflectionUtils.findMethod(handlerClass, "setMimeTypes", Set.class) - .invoke(handler, new HashSet( - Arrays.asList(compression.getMimeTypes()))); - if (compression.getExcludedUserAgents() != null) { - ReflectionUtils.findMethod(handlerClass, "setExcluded", Set.class) - .invoke(handler, new HashSet( - Arrays.asList(compression.getExcludedUserAgents()))); - } - return handler; - } - catch (Exception ex) { - throw new RuntimeException("Failed to configure Jetty 8 gzip handler", - ex); - } - } - - } - - private static class Jetty92GzipHandlerFactory implements GzipHandlerFactory { - - @Override - public HandlerWrapper createGzipHandler(Compression compression) { - try { - Class handlerClass = ClassUtils.forName(GZIP_HANDLER_JETTY_9_2, - getClass().getClassLoader()); - HandlerWrapper gzipHandler = (HandlerWrapper) handlerClass.newInstance(); - ReflectionUtils.findMethod(handlerClass, "setMinGzipSize", int.class) - .invoke(gzipHandler, compression.getMinResponseSize()); - ReflectionUtils - .findMethod(handlerClass, "addIncludedMimeTypes", String[].class) - .invoke(gzipHandler, new Object[] { compression.getMimeTypes() }); - if (compression.getExcludedUserAgents() != null) { - ReflectionUtils.findMethod(handlerClass, "setExcluded", Set.class) - .invoke(gzipHandler, new HashSet( - Arrays.asList(compression.getExcludedUserAgents()))); - } - return gzipHandler; - } - catch (Exception ex) { - throw new RuntimeException("Failed to configure Jetty 9.2 gzip handler", - ex); - } - } - - } - - private static class Jetty93GzipHandlerFactory implements GzipHandlerFactory { - - @Override - public HandlerWrapper createGzipHandler(Compression compression) { - GzipHandler handler = new GzipHandler(); - handler.setMinGzipSize(compression.getMinResponseSize()); - handler.setIncludedMimeTypes(compression.getMimeTypes()); - if (compression.getExcludedUserAgents() != null) { - handler.setExcludedAgentPatterns(compression.getExcludedUserAgents()); - } - return handler; - } - - } - /** * {@link JettyServerCustomizer} to add {@link ForwardedRequestCustomizer}. Only * supported with Jetty 9 (hence the inner class) @@ -858,199 +700,4 @@ public class JettyEmbeddedServletContainerFactory } - private interface ConnectorFactory { - - AbstractConnector createConnector(Server server, InetSocketAddress address, - int acceptors, int selectors); - - } - - private static class Jetty8ConnectorFactory implements ConnectorFactory { - - @Override - public AbstractConnector createConnector(Server server, InetSocketAddress address, - int acceptors, int selectors) { - try { - Class connectorClass = ClassUtils.forName(CONNECTOR_JETTY_8, - getClass().getClassLoader()); - AbstractConnector connector = (AbstractConnector) connectorClass - .newInstance(); - ReflectionUtils.findMethod(connectorClass, "setPort", int.class) - .invoke(connector, address.getPort()); - ReflectionUtils.findMethod(connectorClass, "setHost", String.class) - .invoke(connector, address.getHostName()); - if (acceptors > 0) { - ReflectionUtils.findMethod(connectorClass, "setAcceptors", int.class) - .invoke(connector, acceptors); - } - if (selectors > 0) { - Object selectorManager = ReflectionUtils - .findMethod(connectorClass, "getSelectorManager") - .invoke(connector); - ReflectionUtils.findMethod(selectorManager.getClass(), - "setSelectSets", int.class) - .invoke(selectorManager, selectors); - } - - return connector; - } - catch (Exception ex) { - throw new RuntimeException("Failed to configure Jetty 8 connector", ex); - } - } - - } - - private static class Jetty9ConnectorFactory implements ConnectorFactory { - - @Override - public AbstractConnector createConnector(Server server, InetSocketAddress address, - int acceptors, int selectors) { - ServerConnector connector = new ServerConnector(server, acceptors, selectors); - connector.setHost(address.getHostName()); - connector.setPort(address.getPort()); - for (ConnectionFactory connectionFactory : connector - .getConnectionFactories()) { - if (connectionFactory instanceof HttpConfiguration.ConnectionFactory) { - ((HttpConfiguration.ConnectionFactory) connectionFactory) - .getHttpConfiguration().setSendServerVersion(false); - } - } - return connector; - } - - } - - private interface ServerFactory { - - Server createServer(ThreadPool threadPool); - - } - - private static class Jetty8ServerFactory implements ServerFactory { - - @Override - public Server createServer(ThreadPool threadPool) { - Server server = new Server(); - try { - ReflectionUtils - .findMethod(Server.class, "setThreadPool", ThreadPool.class) - .invoke(server, threadPool); - } - catch (Exception ex) { - throw new RuntimeException("Failed to configure Jetty 8 ThreadPool", ex); - } - try { - ReflectionUtils - .findMethod(Server.class, "setSendServerVersion", boolean.class) - .invoke(server, false); - } - catch (Exception ex) { - throw new RuntimeException("Failed to disable Server header", ex); - } - return server; - } - - } - - private static class Jetty9ServerFactory implements ServerFactory { - - @Override - public Server createServer(ThreadPool threadPool) { - return new Server(threadPool); - } - - } - - /** - * Provides access to the session directory. - */ - private interface SessionDirectory { - - File get(); - - } - - /** - * Strategy used to configure Jetty sessions. - */ - private interface SessionConfigurer { - - void configure(WebAppContext context, int timeout, boolean persist, - SessionDirectory sessionDirectory); - - } - - /** - * SessionConfigurer for Jetty 9.3 and earlier. - */ - private static class Jetty93SessionConfigurer implements SessionConfigurer { - - @Override - public void configure(WebAppContext context, int timeout, boolean persist, - SessionDirectory sessionDirectory) { - SessionHandler handler = context.getSessionHandler(); - Object manager = getSessionManager(handler); - setMaxInactiveInterval(manager, timeout > 0 ? timeout : -1); - if (persist) { - Class hashSessionManagerClass = ClassUtils.resolveClassName( - "org.eclipse.jetty.server.session.HashSessionManager", - handler.getClass().getClassLoader()); - Assert.isInstanceOf(hashSessionManagerClass, manager, - "Unable to use persistent sessions"); - configurePersistSession(manager, sessionDirectory); - } - } - - private Object getSessionManager(SessionHandler handler) { - Method method = ReflectionUtils.findMethod(SessionHandler.class, - "getSessionManager"); - return ReflectionUtils.invokeMethod(method, handler); - } - - private void setMaxInactiveInterval(Object manager, int interval) { - Method method = ReflectionUtils.findMethod(manager.getClass(), - "setMaxInactiveInterval", Integer.TYPE); - ReflectionUtils.invokeMethod(method, manager, interval); - } - - private void configurePersistSession(Object manager, - SessionDirectory sessionDirectory) { - try { - setStoreDirectory(manager, sessionDirectory.get()); - } - catch (IOException ex) { - throw new IllegalStateException(ex); - } - } - - private void setStoreDirectory(Object manager, File file) throws IOException { - Method method = ReflectionUtils.findMethod(manager.getClass(), - "setStoreDirectory", File.class); - ReflectionUtils.invokeMethod(method, manager, file); - } - - } - - /** - * SessionConfigurer for Jetty 9.4 and earlier. - */ - private static class Jetty94SessionConfigurer implements SessionConfigurer { - - @Override - public void configure(WebAppContext context, int timeout, boolean persist, - SessionDirectory sessionDirectory) { - SessionHandler handler = context.getSessionHandler(); - handler.setMaxInactiveInterval(timeout > 0 ? timeout : -1); - if (persist) { - DefaultSessionCache cache = new DefaultSessionCache(handler); - FileSessionDataStore store = new FileSessionDataStore(); - store.setStoreDir(sessionDirectory.get()); - cache.setSessionDataStore(store); - handler.setSessionCache(cache); - } - } - - } - }