Commit 49d05b7a8a2326cd3f23785c5035b451c72819be

Authored by 芯火源
1 parent 57f514e8

fix: TCP脚本响应内容为空引起的异常修复

... ... @@ -297,7 +297,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements
297 297
298 298 if (DataConstants.PROVISION.equals(accessToken) || DataConstants.PROVISION.equals(accessToken)) {
299 299 deviceSessionCtx.setProvisionOnly(true);
300   - ctx.writeAndFlush(createTcpConnAckMsg(CONNECTION_ACCEPTED.name()));
  300 + pushDeviceMsg(ctx,CONNECTION_ACCEPTED.name());
301 301 } else {
302 302 TkScriptInvokeService.authScripts.forEach(id -> {
303 303 ListenableFuture item = context.getJsEngine().invokeFunction(id, accessToken);
... ... @@ -347,9 +347,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements
347 347 }
348 348
349 349
350   - private ByteBuf createTcpConnAckMsg(String msg) {
351   - return Unpooled.copiedBuffer(ByteUtils.getBytes(msg, ByteUtils.UTF_8));
352   - }
  350 +
353 351
354 352 @Override
355 353 public void channelReadComplete(ChannelHandlerContext ctx) {
... ... @@ -450,7 +448,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements
450 448 public void onSuccess(Void msg) {
451 449 SessionMetaData sessionMetaData = transportService.registerAsyncSession(deviceSessionCtx.getSessionInfo(), TcpTransportHandler.this);
452 450 checkGatewaySession(sessionMetaData);
453   - ctx.writeAndFlush(createTcpConnAckMsg(authEntry.getSuccess()));
  451 + pushDeviceMsg(ctx,authEntry.getSuccess());
454 452 deviceSessionCtx.setConnected(true);
455 453 log.debug("[{}] Client connected!", sessionId);
456 454
... ... @@ -474,7 +472,8 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements
474 472 private void onValidateFailed(ChannelHandlerContext ctx, MqttConnectReturnCode msg) {
475 473 authedCounter.incrementAndGet();
476 474 if (TkScriptInvokeService.authScripts.size() == authedCounter.intValue()) {
477   - ctx.writeAndFlush(createTcpConnAckMsg(msg.name()));
  475 + pushDeviceMsg(ctx,msg.name());
  476 +
478 477 ctx.close();
479 478 }
480 479 }
... ...