|
|
|
@ -103,6 +103,9 @@ public class NettyClient { |
|
|
|
this.sendCode = upSystemServerProperties.iipCode; |
|
|
|
this.receiveCode = upSystemServerProperties.upCode; |
|
|
|
|
|
|
|
log.info("upperServer config serverIP:{}, serverPort:{}, sendCode:{}, receiveCode:{}", |
|
|
|
this.serverIP, this.serverPort, this.sendCode, this.receiveCode); |
|
|
|
|
|
|
|
try { |
|
|
|
// 客户端启动对象 |
|
|
|
Bootstrap bootstrap = new Bootstrap(); |
|
|
|
@ -125,11 +128,11 @@ public class NettyClient { |
|
|
|
// ChannelFuture 类分析 , Netty 异步模型 |
|
|
|
// sync 作用是该方法不会再次阻塞 |
|
|
|
ChannelFuture channelFuture = bootstrap.connect(serverIP, serverPort).addListener(new ConnectionListener(this)).sync(); |
|
|
|
log.info("nettyClient连接服务器成功"); |
|
|
|
log.info("connected to upperServer"); |
|
|
|
// 关闭通道, 开始监听 |
|
|
|
channelFuture.channel().closeFuture().sync(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} catch(Exception e) { |
|
|
|
log.error("error", e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -154,8 +157,9 @@ public class NettyClient { |
|
|
|
|
|
|
|
client.sendProtoBuffer(allBuf); |
|
|
|
this.sendIndex++; |
|
|
|
log.info("sent data to upperServer successfully"); |
|
|
|
} else { |
|
|
|
log.warn("###### 会话:{}, 与上级系统连接失败 ######", uuid); |
|
|
|
log.info("###### 会话:{}, 与上级系统连接失败 ######", uuid); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -266,11 +270,14 @@ public class NettyClient { |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.uuid, binaryModel.id, xml, ResultControl.class); |
|
|
|
break; |
|
|
|
default: |
|
|
|
log.warn("ClienHandler接收到的type:{}不在处理范围内, 不予处理", type); |
|
|
|
log.info("ClienHandler接收到的type:{}不在处理范围内, 不予处理", type); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("###### 消息处理返回json: {} ######", json); |
|
|
|
|
|
|
|
// 将上级下发的指令,转发到业务端处理,接收业务端处理后的结果,上报给上级系统 |
|
|
|
if (type != SystemType.system && !StringUtil.isNullOrEmpty(json)) { |
|
|
|
log.info("###### 调用业务端处理json: {} ######", json); |
|
|
|
|
|
|
|
//调用业务端处理 |
|
|
|
ResponseEntity<com.inspect.tcpserver.domain.Result> ajaxResultResponseEntity = restTemplate.postForEntity(iipSendUrl, json, com.inspect.tcpserver.domain.Result.class); |
|
|
|
@ -297,7 +304,7 @@ public class NettyClient { |
|
|
|
|
|
|
|
} else { |
|
|
|
// 调用业务端处理失败 |
|
|
|
log.warn("下发指令,失败,httpCode:{}", statusCode); |
|
|
|
log.info("下发指令,失败,httpCode:{}", statusCode); |
|
|
|
response = createDownFailResponse(); |
|
|
|
|
|
|
|
} |
|
|
|
@ -305,6 +312,7 @@ public class NettyClient { |
|
|
|
// 将xml消息转为json格式字符串 |
|
|
|
//String msg = upJson2Xml.ModelJson2Xml(response); |
|
|
|
String msg = upJson2Xml.UpStreamJson2Xml(response, ModelControl.class); |
|
|
|
log.info("###### 消息响应: {} ######", msg); |
|
|
|
|
|
|
|
// 上报上级系统,会话类型为响应 |
|
|
|
sendMsgToUpper(false, binaryModel.uuid, msg); |
|
|
|
@ -368,7 +376,7 @@ public class NettyClient { |
|
|
|
cacheTimeInterval(heart, patrolDevice, nest, weather); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
log.error("error", e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -454,11 +462,13 @@ public class NettyClient { |
|
|
|
|
|
|
|
public void sendRegisterToUpper() { |
|
|
|
String xml = createRegHeart(false); |
|
|
|
log.info("send register xml to upperServer: {}", xml); |
|
|
|
sendMsgToUpper(true, "", xml); |
|
|
|
} |
|
|
|
|
|
|
|
public void sendHeartbeatToUpper() { |
|
|
|
String xml = createRegHeart(true); |
|
|
|
log.info("send heartbeat xml to upperServer: {}", xml); |
|
|
|
sendMsgToUpper(true, "", xml); |
|
|
|
} |
|
|
|
|
|
|
|
@ -569,7 +579,7 @@ public class NettyClient { |
|
|
|
log.info("###### 会话:{}, 向上级系统发送模型更新上报指令 ######\n{}", uuid, xml); |
|
|
|
break; |
|
|
|
default: |
|
|
|
log.warn("###### 会话:{}, 应用向上级系统发送消息, 类型: [{}] 不在处理范围内, 不予处理 ######", uuid, type); |
|
|
|
log.info("###### 会话:{}, 应用向上级系统发送消息, 类型: [{}] 不在处理范围内, 不予处理 ######", uuid, type); |
|
|
|
} |
|
|
|
if (!StringUtils.isEmpty(xml)) { |
|
|
|
// 将设备别名转换为上级别名 |
|
|
|
|