|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; |
|
|
import com.inspect.tcpserver.domain.AjaxResult; |
|
|
import com.inspect.tcpserver.domain.AjaxResult; |
|
|
import com.inspect.tcpserver.tcp.NettyClient; |
|
|
import com.inspect.tcpserver.tcp.NettyClient; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.MDC; |
|
|
import org.slf4j.MDC; |
|
|
@ -15,8 +16,7 @@ import java.util.UUID; |
|
|
@RestController |
|
|
@RestController |
|
|
@RequestMapping("/client") |
|
|
@RequestMapping("/client") |
|
|
public class ClientController { |
|
|
public class ClientController { |
|
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(ClientController.class); |
|
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(ClientController.class); |
|
|
|
|
|
|
|
|
@Resource |
|
|
@Resource |
|
|
NettyClient nettyClient; |
|
|
NettyClient nettyClient; |
|
|
@ -41,23 +41,22 @@ public class ClientController { |
|
|
public AjaxResult sendMsg(@RequestBody String msg) { |
|
|
public AjaxResult sendMsg(@RequestBody String msg) { |
|
|
try { |
|
|
try { |
|
|
if (StringUtils.isBlank(msg)) { |
|
|
if (StringUtils.isBlank(msg)) { |
|
|
return AjaxResult.fail("500", "发送消息msg为空"); |
|
|
|
|
|
|
|
|
return AjaxResult.fail("500", "消息为空"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 此处只是为了判断传入的格式是否正确 |
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(msg); |
|
|
JSONObject jsonObject = JSONObject.parseObject(msg); |
|
|
if (null == jsonObject) { |
|
|
if (null == jsonObject) { |
|
|
return AjaxResult.fail("500", "发送消息json对象为空"); |
|
|
|
|
|
|
|
|
return AjaxResult.fail("500", "消息JSON解析失败"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
logger.info("巡视主机客户端接收到消息,发送到上级{}", msg); |
|
|
|
|
|
|
|
|
logger.info("################ 巡视主机客户端接收到消息, 发送到上级 ################\n{}", msg); |
|
|
msg = msg.replaceAll("sendCode", "SendCode"); |
|
|
msg = msg.replaceAll("sendCode", "SendCode"); |
|
|
msg = msg.replaceAll("receiveCode", "ReceiveCode"); |
|
|
msg = msg.replaceAll("receiveCode", "ReceiveCode"); |
|
|
msg = msg.replaceAll("type", "Type"); |
|
|
msg = msg.replaceAll("type", "Type"); |
|
|
nettyClient.sendJsonMessage(msg); |
|
|
nettyClient.sendJsonMessage(msg); |
|
|
return AjaxResult.success(); |
|
|
return AjaxResult.success(); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("客户端发送消息捕获异常", e); |
|
|
|
|
|
|
|
|
logger.error("################ 客户端发送消息捕获异常 ################\n{}", ExceptionUtils.getStackTrace(e)); |
|
|
return AjaxResult.fail(500, "数据格式不正确"); |
|
|
return AjaxResult.fail(500, "数据格式不正确"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|