fix bug:Device reconnect abnormal when certificate authentication is turned on

This commit is contained in:
blackstar-baba 2020-01-10 11:12:36 +08:00 committed by Andrew Shvayka
parent 07eaf4dd77
commit 0fa963be85
2 changed files with 5 additions and 5 deletions

View File

@ -100,12 +100,12 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
private volatile DeviceSessionCtx deviceSessionCtx; private volatile DeviceSessionCtx deviceSessionCtx;
private volatile GatewaySessionHandler gatewaySessionHandler; private volatile GatewaySessionHandler gatewaySessionHandler;
MqttTransportHandler(MqttTransportContext context) { MqttTransportHandler(MqttTransportContext context,SslHandler sslHandler) {
this.sessionId = UUID.randomUUID(); this.sessionId = UUID.randomUUID();
this.context = context; this.context = context;
this.transportService = context.getTransportService(); this.transportService = context.getTransportService();
this.adaptor = context.getAdaptor(); this.adaptor = context.getAdaptor();
this.sslHandler = context.getSslHandler(); this.sslHandler = sslHandler;
this.mqttQoSMap = new ConcurrentHashMap<>(); this.mqttQoSMap = new ConcurrentHashMap<>();
this.deviceSessionCtx = new DeviceSessionCtx(sessionId, mqttQoSMap); this.deviceSessionCtx = new DeviceSessionCtx(sessionId, mqttQoSMap);
} }

View File

@ -36,15 +36,15 @@ public class MqttTransportServerInitializer extends ChannelInitializer<SocketCha
@Override @Override
public void initChannel(SocketChannel ch) { public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline(); ChannelPipeline pipeline = ch.pipeline();
SslHandler sslHandler = null;
if (context.getSslHandlerProvider() != null) { if (context.getSslHandlerProvider() != null) {
SslHandler sslHandler = context.getSslHandlerProvider().getSslHandler(); sslHandler = context.getSslHandlerProvider().getSslHandler();
pipeline.addLast(sslHandler); pipeline.addLast(sslHandler);
context.setSslHandler(sslHandler);
} }
pipeline.addLast("decoder", new MqttDecoder(context.getMaxPayloadSize())); pipeline.addLast("decoder", new MqttDecoder(context.getMaxPayloadSize()));
pipeline.addLast("encoder", MqttEncoder.INSTANCE); pipeline.addLast("encoder", MqttEncoder.INSTANCE);
MqttTransportHandler handler = new MqttTransportHandler(context); MqttTransportHandler handler = new MqttTransportHandler(context,sslHandler);
pipeline.addLast(handler); pipeline.addLast(handler);
ch.closeFuture().addListener(handler); ch.closeFuture().addListener(handler);