NO-JIRA Fix MQTT trace logging NPE
This commit is contained in:
parent
6eb78a2634
commit
b5539b9da4
|
@ -128,7 +128,7 @@ public class MQTTProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
AuditLogger.setRemoteAddress(connection.getRemoteAddress());
|
||||
}
|
||||
|
||||
MQTTUtil.logMessage(session.getState(), message, true);
|
||||
MQTTUtil.logMessage(session.getState(), message, true, session.getVersion());
|
||||
|
||||
if (this.ctx == null) {
|
||||
this.ctx = ctx;
|
||||
|
@ -407,7 +407,7 @@ public class MQTTProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
if (this.protocolManager.invokeOutgoing(message, connection) != null) {
|
||||
return;
|
||||
}
|
||||
MQTTUtil.logMessage(session.getState(), message, false);
|
||||
MQTTUtil.logMessage(session.getState(), message, false, session.getVersion());
|
||||
ctx.writeAndFlush(message, ctx.voidPromise());
|
||||
}
|
||||
|
||||
|
|
|
@ -244,7 +244,7 @@ public class MQTTUtil {
|
|||
return message;
|
||||
}
|
||||
|
||||
public static void logMessage(MQTTSessionState state, MqttMessage message, boolean inbound) {
|
||||
public static void logMessage(MQTTSessionState state, MqttMessage message, boolean inbound, MQTTVersion version) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
StringBuilder log = new StringBuilder("MQTT(");
|
||||
|
||||
|
@ -350,12 +350,16 @@ public class MQTTUtil {
|
|||
case PUBREC:
|
||||
case PUBREL:
|
||||
case PUBCOMP:
|
||||
MqttPubReplyMessageVariableHeader pubReplyVariableHeader = (MqttPubReplyMessageVariableHeader) message.variableHeader();
|
||||
log.append(" reasonCode=").append(formatByte(pubReplyVariableHeader.reasonCode()));
|
||||
if (version == MQTTVersion.MQTT_5) {
|
||||
MqttPubReplyMessageVariableHeader pubReplyVariableHeader = (MqttPubReplyMessageVariableHeader) message.variableHeader();
|
||||
log.append(" reasonCode=").append(formatByte(pubReplyVariableHeader.reasonCode()));
|
||||
}
|
||||
break;
|
||||
case DISCONNECT:
|
||||
MqttReasonCodeAndPropertiesVariableHeader disconnectVariableHeader = (MqttReasonCodeAndPropertiesVariableHeader) message.variableHeader();
|
||||
log.append(" reasonCode=").append(formatByte(disconnectVariableHeader.reasonCode()));
|
||||
if (version == MQTTVersion.MQTT_5) {
|
||||
MqttReasonCodeAndPropertiesVariableHeader disconnectVariableHeader = (MqttReasonCodeAndPropertiesVariableHeader) message.variableHeader();
|
||||
log.append(" reasonCode=").append(formatByte(disconnectVariableHeader.reasonCode()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue