diff --git a/pom.xml b/pom.xml index 3c8be02c14b87b618d381adec8d7e8306fab08cb..613f49cf50d69dcfc361cd0546d8ce242910fdb1 100644 --- a/pom.xml +++ b/pom.xml @@ -171,6 +171,11 @@ <artifactId>spring-webmvc</artifactId> <version>${org.springframework-version}</version> </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-websocket</artifactId> + <version>${org.springframework-version}</version> + </dependency> <!-- Security --> <dependency> <groupId>org.springframework.security</groupId> diff --git a/src/main/java/de/thm/arsnova/socket/EchoHandler.java b/src/main/java/de/thm/arsnova/socket/EchoHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..a4b08812dd5351b1d79c8841ecea977ea83e59f0 --- /dev/null +++ b/src/main/java/de/thm/arsnova/socket/EchoHandler.java @@ -0,0 +1,16 @@ +package de.thm.arsnova.socket; + +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +public class EchoHandler extends TextWebSocketHandler { + + @Override + public void handleTextMessage(WebSocketSession session, + TextMessage message) throws Exception { + + session.sendMessage(message); + } + +} diff --git a/src/main/java/de/thm/arsnova/socket/WebSocketConfig.java b/src/main/java/de/thm/arsnova/socket/WebSocketConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..3650e2be3ed57d812d470fdb0b8a84f1604680bb --- /dev/null +++ b/src/main/java/de/thm/arsnova/socket/WebSocketConfig.java @@ -0,0 +1,17 @@ +package de.thm.arsnova.socket; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; + +@Configuration +@EnableWebSocket +public class WebSocketConfig implements WebSocketConfigurer { + + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(new EchoHandler(), "/socket/echo"); + } + +} diff --git a/src/main/webapp/WEB-INF/spring/spring-websocket.xml b/src/main/webapp/WEB-INF/spring/spring-websocket.xml new file mode 100644 index 0000000000000000000000000000000000000000..2d86bc8502cbf37af04b2112f5c851f6f3c4fea6 --- /dev/null +++ b/src/main/webapp/WEB-INF/spring/spring-websocket.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:websocket="http://www.springframework.org/schema/websocket" + xsi:schemaLocation="http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + + <websocket:handlers> + <websocket:mapping handler="echoHandler" path="/socket/echo"/> + </websocket:handlers> + + <bean id="echoHandler" class="de.thm.arsnova.socket.EchoHandler" /> +</beans> diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 6e80f45abbbf0334bd7f1c60a4c95b5fdcdc47a4..79137518b9ebfe1e03bc0fab3eda26ecaeab1443 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -20,6 +20,7 @@ <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/arsnova-servlet.xml + /WEB-INF/spring/spring-websocket.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> diff --git a/src/test/resources/test-config.xml b/src/test/resources/test-config.xml index 1b6ae97af84c9bd28970863243c22ecc7e062a7b..63c1fb147fb9ecbb60a41e1d3b34948cddba537d 100644 --- a/src/test/resources/test-config.xml +++ b/src/test/resources/test-config.xml @@ -2,8 +2,10 @@ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> + xmlns:websocket="http://www.springframework.org/schema/websocket" + xsi:schemaLocation="http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <bean id="sessionService" class="de.thm.arsnova.services.SessionService"> <property name="databaseDao" ref="databaseDao" />