WebSocketController.java 1.41 KB
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";
    }

}