/** * Convert Proton message to IoTHubMessage if the message type is twin * * @param amqpsMessage The Proton message to convert * @param deviceClientConfig The device client configuration * @throws TransportException if the conversion fails * @return the converted message */ @Override protected AmqpsConvertFromProtonReturnValue convertFromProton(AmqpsMessage amqpsMessage, DeviceClientConfig deviceClientConfig) throws TransportException { if ((amqpsMessage.getAmqpsMessageType() == MessageType.DEVICE_TWIN) && (this.deviceClientConfig.getDeviceId().equals(deviceClientConfig.getDeviceId()))) { // Codes_SRS_AMQPSDEVICETWIN_12_016: [The function shall convert the amqpsMessage to IoTHubTransportMessage.] Message message = protonMessageToIoTHubMessage(amqpsMessage); MessageCallback messageCallback = deviceClientConfig.getDeviceTwinMessageCallback(); Object messageContext = deviceClientConfig.getDeviceTwinMessageContext(); // Codes_SRS_AMQPSDEVICETWIN_12_027: [The function shall create a AmqpsConvertFromProtonReturnValue and set the message field to the new IotHubTransportMessage.] // Codes_SRS_AMQPSDEVICETWIN_12_028: [The function shall create a AmqpsConvertFromProtonReturnValue and copy the DeviceClientConfig callback and context to it.] return new AmqpsConvertFromProtonReturnValue(message, messageCallback, messageContext); } else { // Codes_SRS_AMQPSDEVICETWIN_12_015: [The function shall return null if the message type is not DEVICE_TWIN.] return null; } }
transportMessage.setMessageCallbackContext(this.config.getDeviceTwinMessageContext()); break; case DEVICE_METHODS: