58c6da4588bffc5b7abe6133a6a0277297fa844b
[JavaForFun] /
1 package de.spring.webservices.rest.controller;
2
3 import java.time.LocalDateTime;
4
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.messaging.simp.SimpMessagingTemplate;
7 import org.springframework.stereotype.Controller;
8 import org.springframework.web.bind.annotation.RequestMapping;
9 import org.springframework.web.bind.annotation.RequestMethod;
10
11
12 @Controller
13 public class GreetingController {
14
15         private SimpMessagingTemplate template;
16
17     @Autowired
18     public GreetingController(SimpMessagingTemplate template) {
19         this.template = template;
20     }
21
22 //    @MessageMapping("/greeting")
23 //    public String handle(String greeting) {
24 //        return "[" + LocalDateTime.now() + ": " + greeting;
25 //    }
26
27         @RequestMapping(path="/greetings", method=RequestMethod.POST)
28     public void handle(String greeting) {
29                 String text = "[" + LocalDateTime.now() + "]:" + greeting;
30                 this.template.convertAndSend("/topic/greeting", text);
31     }
32
33 }