Commit 2ec09e08ff377d84b02e1223009bb76dc0aad594

Authored by zbeacon
1 parent 616f6a8b

Added ProvisionTransportType to get protocol

... ... @@ -42,6 +42,7 @@ import lombok.extern.slf4j.Slf4j;
42 42 import org.thingsboard.server.common.data.DataConstants;
43 43 import org.thingsboard.server.common.data.DeviceProfile;
44 44 import org.thingsboard.server.common.data.DeviceTransportType;
  45 +import org.thingsboard.server.common.data.TransportPayloadType;
45 46 import org.thingsboard.server.common.data.device.profile.MqttTopics;
46 47 import org.thingsboard.server.common.msg.EncryptionUtil;
47 48 import org.thingsboard.server.common.transport.SessionMsgListener;
... ... @@ -159,6 +160,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
159 160 if (e.getCause().toString().contains("JsonSyntaxException")) {
160 161 TransportProtos.ProvisionDeviceRequestMsg provisionRequestMsg = deviceSessionCtx.getContext().getProtoMqttAdaptor().convertToProvisionRequestMsg(deviceSessionCtx, mqttMsg);
161 162 transportService.process(provisionRequestMsg, new DeviceProvisionCallback(ctx, msgId, provisionRequestMsg));
  163 + deviceSessionCtx.setProvisionPayloadType(TransportPayloadType.PROTOBUF);
162 164 log.trace("[{}][{}] Processing provision publish msg [{}][{}]!", sessionId, deviceSessionCtx.getDeviceId(), topicName, msgId);
163 165 } else {
164 166 throw e;
... ... @@ -326,7 +328,11 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
326 328 ctx.writeAndFlush(createMqttPubAckMsg(msgId));
327 329 }
328 330 try {
329   - deviceSessionCtx.getPayloadAdaptor().convertToPublish(deviceSessionCtx, provisionResponseMsg).ifPresent(deviceSessionCtx.getChannel()::writeAndFlush);
  331 + if (deviceSessionCtx.getProvisionPayloadType().equals(TransportPayloadType.JSON)) {
  332 + deviceSessionCtx.getContext().getJsonMqttAdaptor().convertToPublish(deviceSessionCtx, provisionResponseMsg).ifPresent(deviceSessionCtx.getChannel()::writeAndFlush);
  333 + } else {
  334 + deviceSessionCtx.getContext().getProtoMqttAdaptor().convertToPublish(deviceSessionCtx, provisionResponseMsg).ifPresent(deviceSessionCtx.getChannel()::writeAndFlush);
  335 + }
330 336 } catch (Exception e) {
331 337 log.trace("[{}] Failed to convert device attributes response to MQTT msg", sessionId, e);
332 338 }
... ...
... ... @@ -55,6 +55,10 @@ public class DeviceSessionCtx extends MqttDeviceAwareSessionContext {
55 55 private volatile MqttTopicFilter attributesTopicFilter = MqttTopicFilterFactory.getDefaultAttributesFilter();
56 56 private volatile TransportPayloadType payloadType = TransportPayloadType.JSON;
57 57
  58 + @Getter
  59 + @Setter
  60 + private TransportPayloadType provisionPayloadType = payloadType;
  61 +
58 62 public DeviceSessionCtx(UUID sessionId, ConcurrentMap<MqttTopicMatcher, Integer> mqttQoSMap, MqttTransportContext context) {
59 63 super(sessionId, mqttQoSMap);
60 64 this.context = context;
... ...