WebSocketController.java
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.bootdo.oa.controller;
import com.bootdo.system.service.SessionService;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bootdo.common.utils.R;
import com.bootdo.oa.domain.Message;
import com.bootdo.oa.domain.Response;
import java.security.Principal;
@Controller
public class WebSocketController {
@Autowired
SimpMessagingTemplate template;
@Autowired
SessionService sessionService;
/*@Autowired
WelcomeTask welcomeTask;
@MessageMapping("/welcome") // 浏览器发送请求通过@messageMapping 映射/welcome 这个地址。
@SendTo("/topic/getResponse") // 服务器端有消息时,会订阅@SendTo 中的路径的浏览器发送消息。
public Response say(Message message) throws Exception {
Thread.sleep(1000);
return new Response("Welcome, " + message.getName() + "!");
}
@GetMapping("/test")
String test() {
return "test";
}
@RequestMapping("/welcome")
@ResponseBody
public R say02() {
try {
welcomeTask.sayWelcome();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return R.ok();
}*/
// @ResponseBody
// @GetMapping("/chat")
// public String handleChat(Principal principal, String msg) {
// template.convertAndSendToUser(sessionService.listPrincipal().get(0).toString(), "/queue/notifications", principal.getName() + "给您发来了消息:" + msg);
// return sessionService.listPrincipal().get(0).toString();
// }
}