-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.demo</groupId> | ||
<artifactId>websockets</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
|
||
<name>test-websockets</name> | ||
<description>Demo project for Websockets</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.2.5.RELEASE</version> | ||
<relativePath /> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-websocket</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.webjars.bower</groupId> | ||
<artifactId>sockjs-client</artifactId> | ||
<version>1.0.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.webjars.bower</groupId> | ||
<artifactId>stomp-websocket</artifactId> | ||
<version>2.3.4</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-tomcat</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package demo; | ||
|
||
public class Greeting { | ||
|
||
private String content; | ||
|
||
public Greeting(String content) { | ||
this.content = content; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
samples/websockets/src/main/java/demo/GreetingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package demo; | ||
|
||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.SendTo; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
public class GreetingController { | ||
|
||
@MessageMapping("/hello") | ||
@SendTo("/topic/greetings") | ||
public Greeting greeting(HelloMessage message) throws Exception { | ||
Thread.sleep(3000); // simulated delay | ||
return new Greeting("Hello, " + message.getName() + "!"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package demo; | ||
|
||
public class HelloMessage { | ||
|
||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
samples/websockets/src/main/java/demo/ServletInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package demo; | ||
|
||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.boot.context.web.SpringBootServletInitializer; | ||
|
||
public class ServletInitializer extends SpringBootServletInitializer { | ||
|
||
@Override | ||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | ||
return application.sources(TestWebsocketsApplication.class); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
samples/websockets/src/main/java/demo/TestWebsocketsApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package demo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class TestWebsocketsApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(TestWebsocketsApplication.class, args); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
samples/websockets/src/main/java/demo/WebSocketConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package demo; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; | ||
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; | ||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; | ||
|
||
@Configuration | ||
@EnableWebSocketMessageBroker | ||
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { | ||
|
||
@Override | ||
public void configureMessageBroker(MessageBrokerRegistry config) { | ||
config.enableSimpleBroker("/topic"); | ||
config.setApplicationDestinationPrefixes("/app"); | ||
} | ||
|
||
@Override | ||
public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
registry.addEndpoint("/hello").withSockJS(); | ||
} | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Hello WebSocket</title> | ||
<script src="webjars/sockjs-client/1.0.3/dist/sockjs-0.3.4.js"></script> | ||
<script src="webjars/stomp-websocket/2.3.4/lib/stomp.js"></script> | ||
<script type="text/javascript"> | ||
var stompClient = null; | ||
|
||
function setConnected(connected) { | ||
document.getElementById('connect').disabled = connected; | ||
document.getElementById('disconnect').disabled = !connected; | ||
document.getElementById('conversationDiv').style.visibility = connected ? 'visible' | ||
: 'hidden'; | ||
document.getElementById('response').innerHTML = ''; | ||
} | ||
|
||
function connect() { | ||
var socket = new SockJS('/hello'); | ||
stompClient = Stomp.over(socket); | ||
stompClient.connect({}, function(frame) { | ||
setConnected(true); | ||
console.log('Connected: ' + frame); | ||
stompClient.subscribe('/topic/greetings', function(greeting) { | ||
showGreeting(JSON.parse(greeting.body).content); | ||
}); | ||
}); | ||
} | ||
|
||
function disconnect() { | ||
if (stompClient != null) { | ||
stompClient.disconnect(); | ||
} | ||
setConnected(false); | ||
console.log("Disconnected"); | ||
} | ||
|
||
function sendName() { | ||
var name = document.getElementById('name').value; | ||
stompClient.send("/app/hello", {}, JSON.stringify({ | ||
'name' : name | ||
})); | ||
} | ||
|
||
function showGreeting(message) { | ||
var response = document.getElementById('response'); | ||
var p = document.createElement('p'); | ||
p.style.wordWrap = 'break-word'; | ||
p.appendChild(document.createTextNode(message)); | ||
response.appendChild(p); | ||
} | ||
</script> | ||
</head> | ||
<body onload="disconnect()"> | ||
<noscript> | ||
<h2 style="color: #ff0000">Seems your browser doesn't support | ||
Javascript! Websocket relies on Javascript being enabled. Please | ||
enable Javascript and reload this page!</h2> | ||
</noscript> | ||
<div> | ||
<div> | ||
<button id="connect" onclick="connect();">Connect</button> | ||
<button id="disconnect" disabled="disabled" onclick="disconnect();">Disconnect</button> | ||
</div> | ||
<div id="conversationDiv"> | ||
<label>What is your name?</label><input type="text" id="name" /> | ||
<button id="sendName" onclick="sendName();">Send</button> | ||
<p id="response"></p> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
18 changes: 18 additions & 0 deletions
18
samples/websockets/src/test/java/demo/TestWebsocketsApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package demo; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.test.context.web.WebAppConfiguration; | ||
import org.springframework.boot.test.SpringApplicationConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringApplicationConfiguration(classes = TestWebsocketsApplication.class) | ||
@WebAppConfiguration | ||
public class TestWebsocketsApplicationTests { | ||
|
||
@Test | ||
public void contextLoads() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<launchConfiguration type="net.sourceforge.eclipsejetty.launchConfigurationType"> | ||
<intAttribute key="net.sourceforge.eclipsejetty.launcher.acceptor.limit.count" value="8"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.acceptor.limit.enabled" value="false"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.ajp.enabled" value="false"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.annotations.enabled" value="true"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.cache.client.enabled" value="true"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.cache.server.enabled" value="true"/> | ||
<intAttribute key="net.sourceforge.eclipsejetty.launcher.configVersion" value="1"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.console.enabled" value="true"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.context" value="/"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.customWebDefaults.enabled" value="false"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.customWebDefaults.resource" value=""/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.gracefulShutdown.override.enabled" value="false"/> | ||
<intAttribute key="net.sourceforge.eclipsejetty.launcher.gracefulShutdown.override.timeout" value="1000"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.httpsEnabled" value="false"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.httpsPort" value="8443"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.jetty.config.active.0" value="true"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.jetty.config.path.0" value=""/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.jetty.config.type.0" value="DEFAULT"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.jetty.embedded" value="false"/> | ||
<intAttribute key="net.sourceforge.eclipsejetty.launcher.jetty.microVersion" value="13"/> | ||
<intAttribute key="net.sourceforge.eclipsejetty.launcher.jetty.minorVersion" value="2"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.jetty.path" value="${JETTY9_HOME}"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.jetty.version" value="JETTY_9"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.jmx.enabled" value="false"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.jndi.enabled" value="false"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.jsp.enabled" value="true"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.launcher.excludeGenericIds" value=""/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.launcher.excludeLibs" value=""/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.launcher.globalGenericIds" value=""/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.launcher.globalLibs" value=""/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.launcher.includeGenericIds" value=""/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.launcher.includeLibs" value=""/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.launcher.info" value="true"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.port" value="8080"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.scope.compile.exclude" value="false"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.scope.import.exclude" value="true"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.scope.none.exclude" value="true"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.scope.provided.exclude" value="true"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.scope.runtime.exclude" value="false"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.scope.system.exclude" value="true"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.scope.test.exclude" value="true"/> | ||
<intAttribute key="net.sourceforge.eclipsejetty.launcher.threadPool.limit.count" value="16"/> | ||
<booleanAttribute key="net.sourceforge.eclipsejetty.launcher.threadPool.limit.enabled" value="false"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.webappdir" value="src/main/webapp"/> | ||
<stringAttribute key="net.sourceforge.eclipsejetty.launcher.websocket.enabled" value="true"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="net.sourceforge.eclipsejetty.launcher.JettyLaunchClassPathProvider"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="net.sourceforge.eclipsejetty.starter.jetty9.Jetty9LauncherMain"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="websockets"/> | ||
</launchConfiguration> |