WebSocketController.java
1.4 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
package com.huaheng.mobile.websocket;
import com.google.gson.Gson;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
public class WebSocketController {
@RequestMapping(value = "/operation/{vmc}/{cmd}")
public void remote(@PathVariable("vmc") long vmc, @PathVariable("cmd") String cmd){
RemoteOperation operation = new RemoteOperation();
operation.setVmc_no(vmc);
operation.setOperation(cmd);
String message = new Gson().toJson(operation);
System.out.println("message in json is :"+message);
WebSocketServer.send(cmd);
}
@RequestMapping(value = "/remote")
public void remote(@RequestBody Map<String, String> param){
String vmc = param.get("vmc");
String cmd = param.get("cmd");
RemoteOperation operation = new RemoteOperation();
operation.setVmc_no(Long.valueOf(vmc));
operation.setOperation(cmd);
String message = new Gson().toJson(operation);
System.out.println("message in json is :"+message);
WebSocketServer.send(cmd);
}
@RequestMapping(value = "/test")
public String test(){
System.out.print("test");
return "hello world";
}
}