in iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/AmqpsReceiverLinkHandler.java [239:314]
IotHubTransportMessage protonMessageToIoTHubMessage(AmqpsMessage protonMsg)
{
log.trace("Converting proton message to iot hub message for {} receiver link with address {} and link correlation id {}. Proton message correlation id {}", getLinkInstanceType(), this.receiverLinkAddress, this.linkCorrelationId, protonMsg.getCorrelationId());
byte[] msgBody;
Data d = (Data) protonMsg.getBody();
if (d != null)
{
Binary b = d.getValue();
msgBody = new byte[b.getLength()];
ByteBuffer buffer = b.asByteBuffer();
buffer.get(msgBody);
}
else
{
msgBody = new byte[0];
}
IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(msgBody, MessageType.UNKNOWN);
Properties properties = protonMsg.getProperties();
if (properties != null)
{
if (properties.getCorrelationId() != null)
{
iotHubTransportMessage.setCorrelationId(properties.getCorrelationId().toString());
}
if (properties.getMessageId() != null)
{
iotHubTransportMessage.setMessageId(properties.getMessageId().toString());
}
if (properties.getTo() != null)
{
iotHubTransportMessage.setProperty(AMQPS_APP_PROPERTY_PREFIX + TO_KEY, properties.getTo());
}
if (properties.getUserId() != null)
{
iotHubTransportMessage.setProperty(AMQPS_APP_PROPERTY_PREFIX + USER_ID_KEY, properties.getUserId().toString());
}
if (properties.getContentEncoding() != null)
{
iotHubTransportMessage.setContentEncoding(properties.getContentEncoding().toString());
}
if (properties.getContentType() != null)
{
iotHubTransportMessage.setContentType(properties.getContentType().toString());
}
}
if (protonMsg.getApplicationProperties() != null)
{
Map<String, Object> applicationProperties = protonMsg.getApplicationProperties().getValue();
for (Map.Entry<String, Object> entry : applicationProperties.entrySet())
{
String propertyKey = entry.getKey();
if (propertyKey.equalsIgnoreCase(MessageProperty.CONNECTION_DEVICE_ID))
{
iotHubTransportMessage.setConnectionDeviceId(entry.getValue().toString());
}
else if (propertyKey.equalsIgnoreCase(MessageProperty.CONNECTION_MODULE_ID))
{
iotHubTransportMessage.setConnectionModuleId(entry.getValue().toString());
}
else if (!MessageProperty.RESERVED_PROPERTY_NAMES.contains(propertyKey))
{
iotHubTransportMessage.setProperty(entry.getKey(), entry.getValue().toString());
}
}
}
return iotHubTransportMessage;
}