[BAEL-16663] - Split or move spring-mvc-java module
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
package com.baeldung.web.controller;
|
||||
|
||||
import com.baeldung.model.Message;
|
||||
import com.baeldung.model.OutputMessage;
|
||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||
import org.springframework.messaging.handler.annotation.SendTo;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@Controller
|
||||
public class ChatController {
|
||||
|
||||
@MessageMapping("/chat")
|
||||
@SendTo("/topic/messages")
|
||||
public OutputMessage send(final Message message) throws Exception {
|
||||
|
||||
final String time = new SimpleDateFormat("HH:mm").format(new Date());
|
||||
return new OutputMessage(message.getFrom(), message.getText(), time);
|
||||
}
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.baeldung.web.controller;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.messaging.handler.annotation.MessageExceptionHandler;
|
||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.messaging.simp.annotation.SendToUser;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
@Controller
|
||||
public class WebsocketSendToUserController {
|
||||
|
||||
private Gson gson = new Gson();
|
||||
|
||||
@MessageMapping("/message")
|
||||
@SendToUser("/queue/reply")
|
||||
public String processMessageFromClient(@Payload String message, Principal principal) throws Exception {
|
||||
return gson.fromJson(message, Map.class).get("name").toString();
|
||||
}
|
||||
|
||||
@MessageExceptionHandler
|
||||
@SendToUser("/queue/errors")
|
||||
public String handleException(Throwable exception) {
|
||||
return exception.getMessage();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user