From c22aee9817cb00f3d681ba276ce64b1573302a20 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 3 Dec 2014 15:46:52 -0800 Subject: [PATCH] Polish WebSocket samples --- spring-boot-samples/pom.xml | 2 +- ... => SampleJettyWebSocketsApplication.java} | 22 +- .../src/main/resources/static/echo.html | 223 ++++---- .../src/main/resources/static/index.html | 37 +- .../src/main/resources/static/reverse.html | 235 ++++----- .../src/main/resources/static/snake.html | 481 +++++++++--------- .../SampleWebSocketsApplicationTests.java | 3 +- ...omContainerWebSocketsApplicationTests.java | 23 +- .../websocket/snake/SnakeTimerTests.java | 1 + .../pom.xml | 6 +- .../SampleTomcatWebSocketApplication.java} | 22 +- .../websocket/client/GreetingService.java | 0 .../client/SimpleClientWebSocketHandler.java | 0 .../client/SimpleGreetingService.java | 0 .../websocket/echo/DefaultEchoService.java | 0 .../samples/websocket/echo/EchoService.java | 0 .../websocket/echo/EchoWebSocketHandler.java | 0 .../reverse/ReverseWebSocketEndpoint.java | 0 .../samples/websocket/snake/Direction.java | 0 .../samples/websocket/snake/Location.java | 0 .../java/samples/websocket/snake/Snake.java | 0 .../samples/websocket/snake/SnakeTimer.java | 0 .../samples/websocket/snake/SnakeUtils.java | 0 .../snake/SnakeWebSocketHandler.java | 0 .../src/main/resources/static/echo.html | 134 +++++ .../src/main/resources/static/index.html | 33 ++ .../src/main/resources/static/reverse.html | 141 +++++ .../src/main/resources/static/snake.html | 250 +++++++++ .../SampleWebSocketsApplicationTests.java | 4 +- ...omContainerWebSocketsApplicationTests.java | 23 +- .../websocket/snake/SnakeTimerTests.java | 0 .../SampleUndertowWebSocketsApplication.java | 8 +- .../src/main/resources/static/echo.html | 223 ++++---- .../src/main/resources/static/index.html | 37 +- .../src/main/resources/static/reverse.html | 235 ++++----- .../src/main/resources/static/snake.html | 481 +++++++++--------- .../SampleWebSocketsApplicationTests.java | 2 +- ...omContainerWebSocketsApplicationTests.java | 21 +- .../src/main/resources/static/echo.html | 133 ----- .../src/main/resources/static/index.html | 32 -- .../src/main/resources/static/reverse.html | 140 ----- .../src/main/resources/static/snake.html | 249 --------- 42 files changed, 1614 insertions(+), 1587 deletions(-) rename spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/{config/SampleWebSocketsApplication.java => SampleJettyWebSocketsApplication.java} (85%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/pom.xml (88%) rename spring-boot-samples/{spring-boot-sample-websocket/src/main/java/samples/websocket/config/SampleWebSocketsApplication.java => spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/SampleTomcatWebSocketApplication.java} (85%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/client/GreetingService.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/client/SimpleClientWebSocketHandler.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/client/SimpleGreetingService.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/echo/DefaultEchoService.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/echo/EchoService.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/echo/EchoWebSocketHandler.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/reverse/ReverseWebSocketEndpoint.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/snake/Direction.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/snake/Location.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/snake/Snake.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/snake/SnakeTimer.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/snake/SnakeUtils.java (100%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/main/java/samples/websocket/snake/SnakeWebSocketHandler.java (100%) create mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/echo.html create mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/index.html create mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/reverse.html create mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/snake.html rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java (97%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java (97%) rename spring-boot-samples/{spring-boot-sample-websocket => spring-boot-sample-websocket-tomcat}/src/test/java/samples/websocket/snake/SnakeTimerTests.java (100%) rename spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/{config => }/SampleUndertowWebSocketsApplication.java (93%) delete mode 100644 spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/echo.html delete mode 100644 spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/index.html delete mode 100644 spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/reverse.html delete mode 100644 spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/snake.html diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index e5e51659e2..b77a27ef09 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -73,8 +73,8 @@ spring-boot-sample-web-jsp spring-boot-sample-web-ui spring-boot-sample-web-velocity - spring-boot-sample-websocket spring-boot-sample-websocket-jetty + spring-boot-sample-websocket-tomcat spring-boot-sample-websocket-undertow spring-boot-sample-ws spring-boot-sample-xml diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/config/SampleWebSocketsApplication.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/SampleJettyWebSocketsApplication.java similarity index 85% rename from spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/config/SampleWebSocketsApplication.java rename to spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/SampleJettyWebSocketsApplication.java index 963ea166e3..b347d96e31 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/config/SampleWebSocketsApplication.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/SampleJettyWebSocketsApplication.java @@ -14,13 +14,14 @@ * limitations under the License. */ -package samples.websocket.config; +package samples.websocket; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.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; @@ -36,10 +37,11 @@ import samples.websocket.echo.EchoWebSocketHandler; import samples.websocket.reverse.ReverseWebSocketEndpoint; import samples.websocket.snake.SnakeWebSocketHandler; -@SpringBootApplication +@Configuration +@EnableAutoConfiguration @EnableWebSocket -public class SampleWebSocketsApplication extends SpringBootServletInitializer implements - WebSocketConfigurer { +public class SampleJettyWebSocketsApplication extends SpringBootServletInitializer + implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { @@ -49,11 +51,7 @@ public class SampleWebSocketsApplication extends SpringBootServletInitializer im @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleWebSocketsApplication.class); - } - - public static void main(String[] args) { - SpringApplication.run(SampleWebSocketsApplication.class, args); + return application.sources(SampleJettyWebSocketsApplication.class); } @Bean @@ -86,4 +84,8 @@ public class SampleWebSocketsApplication extends SpringBootServletInitializer im return new ServerEndpointExporter(); } + public static void main(String[] args) { + SpringApplication.run(SampleJettyWebSocketsApplication.class, args); + } + } diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/echo.html b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/echo.html index 0ffca05b4d..9a0a7650bf 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/echo.html +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/echo.html @@ -1,133 +1,134 @@ + - Apache Tomcat WebSocket Examples: Echo - - - + + function log(message) { + var console = document.getElementById('console'); + var p = document.createElement('p'); + p.style.wordWrap = 'break-word'; + p.appendChild(document.createTextNode(message)); + console.appendChild(p); + while (console.childNodes.length > 25) { + console.removeChild(console.firstChild); + } + console.scrollTop = console.scrollHeight; + } + + Javascript and reload this page!
-
-
- -
-
- - -
-
- -
-
- -
-
-
-
-
+
+
+ +
+
+ + +
+
+ +
+
+ +
+
+
+
+
- \ No newline at end of file + diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/index.html b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/index.html index e2b76b6e44..e9585067a3 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/index.html +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/index.html @@ -1,32 +1,33 @@ + - Apache Tomcat WebSocket Examples: Index + Apache Tomcat WebSocket Examples: Index + Javascript and reload this page!

Please select the sample you would like to try.

- \ No newline at end of file + diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/reverse.html b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/reverse.html index 96aaf25de7..be2c043930 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/reverse.html +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/reverse.html @@ -1,140 +1,141 @@ + - WebSocket Examples: Reverse - - + function log(message) { + var console = document.getElementById('console'); + var p = document.createElement('p'); + p.style.wordWrap = 'break-word'; + p.appendChild(document.createTextNode(message)); + console.appendChild(p); + while (console.childNodes.length > 25) { + console.removeChild(console.firstChild); + } + console.scrollTop = console.scrollHeight; + } + + Javascript and reload this page!
-
-
- -
-
- - -
-
- -
-
- -
-
-
-
-
+
+
+ +
+
+ + +
+
+ +
+
+ +
+
+
+
+
- \ No newline at end of file + diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/snake.html b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/snake.html index 5728fc0144..d305381069 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/snake.html +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/snake.html @@ -1,249 +1,250 @@ + + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> - - Apache Tomcat WebSocket Examples: Multiplayer Snake - - + + Apache Tomcat WebSocket Examples: Multiplayer Snake + + - - -
- -
-
-
-
- + + +
+ +
+
+
+
+ diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java index cff0db5490..c12b3109f8 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java @@ -42,12 +42,11 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient; import samples.websocket.client.GreetingService; import samples.websocket.client.SimpleClientWebSocketHandler; import samples.websocket.client.SimpleGreetingService; -import samples.websocket.config.SampleWebSocketsApplication; import static org.junit.Assert.assertEquals; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = SampleWebSocketsApplication.class) +@SpringApplicationConfiguration(classes = SampleJettyWebSocketsApplication.class) @WebAppConfiguration @IntegrationTest("server.port:0") @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java index bcc020e646..0a204fbc7f 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java @@ -42,16 +42,16 @@ import org.springframework.util.SocketUtils; import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.standard.StandardWebSocketClient; +import samples.websocket.SampleJettyWebSocketsApplication; import samples.websocket.client.GreetingService; import samples.websocket.client.SimpleClientWebSocketHandler; import samples.websocket.client.SimpleGreetingService; -import samples.websocket.config.SampleWebSocketsApplication; import samples.websocket.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; import static org.junit.Assert.assertEquals; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = { SampleWebSocketsApplication.class, +@SpringApplicationConfiguration(classes = { SampleJettyWebSocketsApplication.class, CustomContainerConfiguration.class }) @WebAppConfiguration @IntegrationTest @@ -63,14 +63,6 @@ public class CustomContainerWebSocketsApplicationTests { private static int PORT = SocketUtils.findAvailableTcpPort(); - @Configuration - protected static class CustomContainerConfiguration { - @Bean - public EmbeddedServletContainerFactory embeddedServletContainerFactory() { - return new JettyEmbeddedServletContainerFactory("/ws", PORT); - } - } - @Test public void echoEndpoint() throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder( @@ -99,6 +91,16 @@ public class CustomContainerWebSocketsApplicationTests { assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); } + @Configuration + protected static class CustomContainerConfiguration { + + @Bean + public EmbeddedServletContainerFactory embeddedServletContainerFactory() { + return new JettyEmbeddedServletContainerFactory("/ws", PORT); + } + + } + @Configuration static class ClientConfiguration implements CommandLineRunner { @@ -145,6 +147,7 @@ public class CustomContainerWebSocketsApplicationTests { public GreetingService greetingService() { return new SimpleGreetingService(); } + } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/snake/SnakeTimerTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/snake/SnakeTimerTests.java index 9a8305e46b..298afbd807 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/snake/SnakeTimerTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/snake/SnakeTimerTests.java @@ -37,4 +37,5 @@ public class SnakeTimerTests { SnakeTimer.broadcast(""); assertThat(SnakeTimer.getSnakes().size(), is(0)); } + } diff --git a/spring-boot-samples/spring-boot-sample-websocket/pom.xml b/spring-boot-samples/spring-boot-sample-websocket-tomcat/pom.xml similarity index 88% rename from spring-boot-samples/spring-boot-sample-websocket/pom.xml rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/pom.xml index 450765bde4..3ddf75026f 100755 --- a/spring-boot-samples/spring-boot-sample-websocket/pom.xml +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/pom.xml @@ -7,9 +7,9 @@ spring-boot-samples 1.2.0.BUILD-SNAPSHOT - spring-boot-sample-websocket - Spring Boot WebSocket Sample - Spring Boot WebSocket Sample + spring-boot-sample-websocket-tomcat + Spring Boot WebSocket Tomcat Sample + Spring Boot WebSocket Tomcat Sample http://projects.spring.io/spring-boot/ Pivotal Software, Inc. diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/config/SampleWebSocketsApplication.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/SampleTomcatWebSocketApplication.java similarity index 85% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/config/SampleWebSocketsApplication.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/SampleTomcatWebSocketApplication.java index 2ae2ddfb56..b0d48a9f12 100644 --- a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/config/SampleWebSocketsApplication.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/SampleTomcatWebSocketApplication.java @@ -14,13 +14,14 @@ * limitations under the License. */ -package samples.websocket.config; +package samples.websocket; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.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; @@ -36,10 +37,11 @@ import samples.websocket.echo.EchoWebSocketHandler; import samples.websocket.reverse.ReverseWebSocketEndpoint; import samples.websocket.snake.SnakeWebSocketHandler; -@SpringBootApplication +@Configuration +@EnableAutoConfiguration @EnableWebSocket -public class SampleWebSocketsApplication extends SpringBootServletInitializer implements - WebSocketConfigurer { +public class SampleTomcatWebSocketApplication extends SpringBootServletInitializer + implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { @@ -49,11 +51,7 @@ public class SampleWebSocketsApplication extends SpringBootServletInitializer im @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleWebSocketsApplication.class); - } - - public static void main(String[] args) { - SpringApplication.run(SampleWebSocketsApplication.class, args); + return application.sources(SampleTomcatWebSocketApplication.class); } @Bean @@ -86,4 +84,8 @@ public class SampleWebSocketsApplication extends SpringBootServletInitializer im return new ServerEndpointExporter(); } + public static void main(String[] args) { + SpringApplication.run(SampleTomcatWebSocketApplication.class, args); + } + } diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/client/GreetingService.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/client/GreetingService.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/client/GreetingService.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/client/GreetingService.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/client/SimpleClientWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/client/SimpleClientWebSocketHandler.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/client/SimpleClientWebSocketHandler.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/client/SimpleClientWebSocketHandler.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/client/SimpleGreetingService.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/client/SimpleGreetingService.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/client/SimpleGreetingService.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/client/SimpleGreetingService.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/echo/DefaultEchoService.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/echo/DefaultEchoService.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/echo/DefaultEchoService.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/echo/DefaultEchoService.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/echo/EchoService.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/echo/EchoService.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/echo/EchoService.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/echo/EchoService.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/echo/EchoWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/echo/EchoWebSocketHandler.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/echo/EchoWebSocketHandler.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/echo/EchoWebSocketHandler.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/reverse/ReverseWebSocketEndpoint.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/reverse/ReverseWebSocketEndpoint.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/reverse/ReverseWebSocketEndpoint.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/reverse/ReverseWebSocketEndpoint.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/Direction.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/Direction.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/Direction.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/Direction.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/Location.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/Location.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/Location.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/Location.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/Snake.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/Snake.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/Snake.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/Snake.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/SnakeTimer.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/SnakeTimer.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/SnakeTimer.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/SnakeTimer.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/SnakeUtils.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/SnakeUtils.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/SnakeUtils.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/SnakeUtils.java diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/SnakeWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/SnakeWebSocketHandler.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/main/java/samples/websocket/snake/SnakeWebSocketHandler.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/snake/SnakeWebSocketHandler.java diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/echo.html b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/echo.html new file mode 100644 index 0000000000..9a0a7650bf --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/echo.html @@ -0,0 +1,134 @@ + + + + + + Apache Tomcat WebSocket Examples: Echo + + + + + + +
+
+
+ +
+
+ + +
+
+ +
+
+ +
+
+
+
+
+
+ + diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/index.html b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/index.html new file mode 100644 index 0000000000..e9585067a3 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/index.html @@ -0,0 +1,33 @@ + + + + + + Apache Tomcat WebSocket Examples: Index + + + +

Please select the sample you would like to try.

+ + + diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/reverse.html b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/reverse.html new file mode 100644 index 0000000000..be2c043930 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/reverse.html @@ -0,0 +1,141 @@ + + + + + + WebSocket Examples: Reverse + + + + + +
+
+
+ +
+
+ + +
+
+ +
+
+ +
+
+
+
+
+
+ + diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/snake.html b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/snake.html new file mode 100644 index 0000000000..d305381069 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/snake.html @@ -0,0 +1,250 @@ + + + + + + + Apache Tomcat WebSocket Examples: Multiplayer Snake + + + + + + +
+ +
+
+
+
+ + + diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java similarity index 97% rename from spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java index cff0db5490..bd25281692 100644 --- a/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java @@ -42,12 +42,11 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient; import samples.websocket.client.GreetingService; import samples.websocket.client.SimpleClientWebSocketHandler; import samples.websocket.client.SimpleGreetingService; -import samples.websocket.config.SampleWebSocketsApplication; import static org.junit.Assert.assertEquals; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = SampleWebSocketsApplication.class) +@SpringApplicationConfiguration(classes = SampleTomcatWebSocketApplication.class) @WebAppConfiguration @IntegrationTest("server.port:0") @DirtiesContext @@ -133,6 +132,7 @@ public class SampleWebSocketsApplicationTests { public GreetingService greetingService() { return new SimpleGreetingService(); } + } } diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java similarity index 97% rename from spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java index 1df5822890..1844e4142f 100644 --- a/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java @@ -42,16 +42,16 @@ import org.springframework.util.SocketUtils; import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.standard.StandardWebSocketClient; +import samples.websocket.SampleTomcatWebSocketApplication; import samples.websocket.client.GreetingService; import samples.websocket.client.SimpleClientWebSocketHandler; import samples.websocket.client.SimpleGreetingService; -import samples.websocket.config.SampleWebSocketsApplication; import samples.websocket.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; import static org.junit.Assert.assertEquals; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = { SampleWebSocketsApplication.class, +@SpringApplicationConfiguration(classes = { SampleTomcatWebSocketApplication.class, CustomContainerConfiguration.class }) @WebAppConfiguration @IntegrationTest @@ -63,14 +63,6 @@ public class CustomContainerWebSocketsApplicationTests { private static int PORT = SocketUtils.findAvailableTcpPort(); - @Configuration - protected static class CustomContainerConfiguration { - @Bean - public EmbeddedServletContainerFactory embeddedServletContainerFactory() { - return new TomcatEmbeddedServletContainerFactory("/ws", PORT); - } - } - @Test public void echoEndpoint() throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder( @@ -99,6 +91,16 @@ public class CustomContainerWebSocketsApplicationTests { assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); } + @Configuration + protected static class CustomContainerConfiguration { + + @Bean + public EmbeddedServletContainerFactory embeddedServletContainerFactory() { + return new TomcatEmbeddedServletContainerFactory("/ws", PORT); + } + + } + @Configuration static class ClientConfiguration implements CommandLineRunner { @@ -145,6 +147,7 @@ public class CustomContainerWebSocketsApplicationTests { public GreetingService greetingService() { return new SimpleGreetingService(); } + } } diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/snake/SnakeTimerTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/snake/SnakeTimerTests.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/snake/SnakeTimerTests.java rename to spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/snake/SnakeTimerTests.java diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/config/SampleUndertowWebSocketsApplication.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/SampleUndertowWebSocketsApplication.java similarity index 93% rename from spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/config/SampleUndertowWebSocketsApplication.java rename to spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/SampleUndertowWebSocketsApplication.java index 054a5eb3b0..938fc1d4f5 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/config/SampleUndertowWebSocketsApplication.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/SampleUndertowWebSocketsApplication.java @@ -14,13 +14,14 @@ * limitations under the License. */ -package samples.websocket.config; +package samples.websocket; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.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; @@ -36,7 +37,8 @@ import samples.websocket.echo.EchoWebSocketHandler; import samples.websocket.reverse.ReverseWebSocketEndpoint; import samples.websocket.snake.SnakeWebSocketHandler; -@SpringBootApplication +@Configuration +@EnableAutoConfiguration @EnableWebSocket public class SampleUndertowWebSocketsApplication extends SpringBootServletInitializer implements WebSocketConfigurer { diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/echo.html b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/echo.html index 0ffca05b4d..9a0a7650bf 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/echo.html +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/echo.html @@ -1,133 +1,134 @@ + - Apache Tomcat WebSocket Examples: Echo - - - + + function log(message) { + var console = document.getElementById('console'); + var p = document.createElement('p'); + p.style.wordWrap = 'break-word'; + p.appendChild(document.createTextNode(message)); + console.appendChild(p); + while (console.childNodes.length > 25) { + console.removeChild(console.firstChild); + } + console.scrollTop = console.scrollHeight; + } + + Javascript and reload this page!
-
-
- -
-
- - -
-
- -
-
- -
-
-
-
-
+
+
+ +
+
+ + +
+
+ +
+
+ +
+
+
+
+
- \ No newline at end of file + diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/index.html b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/index.html index e2b76b6e44..e9585067a3 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/index.html +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/index.html @@ -1,32 +1,33 @@ + - Apache Tomcat WebSocket Examples: Index + Apache Tomcat WebSocket Examples: Index + Javascript and reload this page!

Please select the sample you would like to try.

- \ No newline at end of file + diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/reverse.html b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/reverse.html index 96aaf25de7..be2c043930 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/reverse.html +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/reverse.html @@ -1,140 +1,141 @@ + - WebSocket Examples: Reverse - - + function log(message) { + var console = document.getElementById('console'); + var p = document.createElement('p'); + p.style.wordWrap = 'break-word'; + p.appendChild(document.createTextNode(message)); + console.appendChild(p); + while (console.childNodes.length > 25) { + console.removeChild(console.firstChild); + } + console.scrollTop = console.scrollHeight; + } + + Javascript and reload this page!
-
-
- -
-
- - -
-
- -
-
- -
-
-
-
-
+
+
+ +
+
+ + +
+
+ +
+
+ +
+
+
+
+
- \ No newline at end of file + diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/snake.html b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/snake.html index 5728fc0144..d305381069 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/snake.html +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/snake.html @@ -1,249 +1,250 @@ + + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> - - Apache Tomcat WebSocket Examples: Multiplayer Snake - - + + Apache Tomcat WebSocket Examples: Multiplayer Snake + + - - -
- -
-
-
-
- + + +
+ +
+
+
+
+ diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java index fee7e46e74..f93e2fb5da 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/SampleWebSocketsApplicationTests.java @@ -42,7 +42,6 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient; import samples.websocket.client.GreetingService; import samples.websocket.client.SimpleClientWebSocketHandler; import samples.websocket.client.SimpleGreetingService; -import samples.websocket.config.SampleUndertowWebSocketsApplication; import static org.junit.Assert.assertEquals; @@ -133,6 +132,7 @@ public class SampleWebSocketsApplicationTests { public GreetingService greetingService() { return new SimpleGreetingService(); } + } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java index 302d560cbb..4501e44323 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java @@ -42,10 +42,10 @@ import org.springframework.util.SocketUtils; import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.standard.StandardWebSocketClient; +import samples.websocket.SampleUndertowWebSocketsApplication; import samples.websocket.client.GreetingService; import samples.websocket.client.SimpleClientWebSocketHandler; import samples.websocket.client.SimpleGreetingService; -import samples.websocket.config.SampleUndertowWebSocketsApplication; import samples.websocket.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; import static org.junit.Assert.assertEquals; @@ -63,14 +63,6 @@ public class CustomContainerWebSocketsApplicationTests { private static int PORT = SocketUtils.findAvailableTcpPort(); - @Configuration - protected static class CustomContainerConfiguration { - @Bean - public EmbeddedServletContainerFactory embeddedServletContainerFactory() { - return new UndertowEmbeddedServletContainerFactory("/ws", PORT); - } - } - @Test public void echoEndpoint() throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder( @@ -99,6 +91,16 @@ public class CustomContainerWebSocketsApplicationTests { assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); } + @Configuration + protected static class CustomContainerConfiguration { + + @Bean + public EmbeddedServletContainerFactory embeddedServletContainerFactory() { + return new UndertowEmbeddedServletContainerFactory("/ws", PORT); + } + + } + @Configuration static class ClientConfiguration implements CommandLineRunner { @@ -145,6 +147,7 @@ public class CustomContainerWebSocketsApplicationTests { public GreetingService greetingService() { return new SimpleGreetingService(); } + } } diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/echo.html b/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/echo.html deleted file mode 100644 index 0ffca05b4d..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/echo.html +++ /dev/null @@ -1,133 +0,0 @@ - - - - - Apache Tomcat WebSocket Examples: Echo - - - - - - -
-
-
- -
-
- - -
-
- -
-
- -
-
-
-
-
-
- - \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/index.html b/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/index.html deleted file mode 100644 index e2b76b6e44..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/index.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - Apache Tomcat WebSocket Examples: Index - - - -

Please select the sample you would like to try.

- - - \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/reverse.html b/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/reverse.html deleted file mode 100644 index a87d2e8255..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/reverse.html +++ /dev/null @@ -1,140 +0,0 @@ - - - - - WebSocket Examples: Reverse - - - - - -
-
-
- -
-
- - -
-
- -
-
- -
-
-
-
-
-
- - \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/snake.html b/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/snake.html deleted file mode 100644 index 5728fc0144..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket/src/main/resources/static/snake.html +++ /dev/null @@ -1,249 +0,0 @@ - - - - - - Apache Tomcat WebSocket Examples: Multiplayer Snake - - - - - - -
- -
-
-
-
- - -