diff --git a/src/main/java/org/ros/chatto/websocket/WebSocketController.java b/src/main/java/org/ros/chatto/websocket/WebSocketController.java index 6dafadc..0f5a87b 100644 --- a/src/main/java/org/ros/chatto/websocket/WebSocketController.java +++ b/src/main/java/org/ros/chatto/websocket/WebSocketController.java @@ -1,5 +1,8 @@ package org.ros.chatto.websocket; +import javax.validation.Valid; + +import org.ros.chatto.model.ChatMessage; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.messaging.simp.SimpMessagingTemplate; @@ -14,11 +17,20 @@ public class WebSocketController { private final SimpMessagingTemplate smt; + @MessageMapping("/chat2") + // @SendTo("/topic/messages") + // @SendToUser("/queue/reply") + public void send2(@Payload final Message message) throws Exception { + smt.convertAndSendToUser(message.getTo(), "/queue/reply", message); + // return message; + } + @MessageMapping("/chat") // @SendTo("/topic/messages") // @SendToUser("/queue/reply") - public void send(@Payload final Message message) throws Exception { - smt.convertAndSendToUser(message.getTo(), "/queue/reply", message); + public void send(@Valid final ChatMessage message) throws Exception { + smt.convertAndSendToUser(message.getToUser().getUserName(), + "/queue/reply", message); // return message; } diff --git a/src/main/resources/templates/ws.html b/src/main/resources/templates/ws.html index 88293e3..ca20851 100644 --- a/src/main/resources/templates/ws.html +++ b/src/main/resources/templates/ws.html @@ -14,7 +14,7 @@ } function connect() { - var socket = new SockJS('/chat'); + var socket = new SockJS('/chat2'); stompClient = Stomp.over(socket); stompClient.connect({}, function (frame) { setConnected(true);