in iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/AmqpsSenderLinkHandler.java [259:335]
MessageImpl iotHubMessageToProtonMessage(Message message)
{
log.trace("Converting IoT Hub message to proton message for {} sender link with address {} and link correlation id {}. IoT Hub message correlationId {}", getLinkInstanceType(), this.senderLinkAddress, this.linkCorrelationId, message.getCorrelationId());
MessageImpl outgoingMessage = (MessageImpl) Proton.message();
Properties properties = new Properties();
if (message.getMessageId() != null)
{
properties.setMessageId(message.getMessageId());
}
if (message.getCorrelationId() != null)
{
properties.setCorrelationId(message.getCorrelationId());
}
if (message.getContentType() != null)
{
properties.setContentType(Symbol.valueOf(message.getContentType()));
}
if (message.getContentEncoding() != null)
{
properties.setContentEncoding(Symbol.valueOf(message.getContentEncoding()));
}
outgoingMessage.setProperties(properties);
Map<String, Object> userProperties = new HashMap<>();
if (message.getProperties().length > 0)
{
for (MessageProperty messageProperty : message.getProperties())
{
if (!MessageProperty.RESERVED_PROPERTY_NAMES.contains(messageProperty.getName()))
{
userProperties.put(messageProperty.getName(), messageProperty.getValue());
}
}
}
if (message.getConnectionDeviceId() != null)
{
userProperties.put(MessageProperty.CONNECTION_DEVICE_ID, message.getConnectionDeviceId());
}
if (message.getConnectionModuleId() != null)
{
userProperties.put(MessageProperty.CONNECTION_MODULE_ID, message.getConnectionModuleId());
}
if (message.getCreationTimeUTC() != null)
{
userProperties.put(MessageProperty.IOTHUB_CREATION_TIME_UTC, message.getCreationTimeUTCString());
}
ApplicationProperties applicationProperties = new ApplicationProperties(userProperties);
outgoingMessage.setApplicationProperties(applicationProperties);
Map<Symbol, Object> messageAnnotationsMap = new HashMap<>();
if (message.isSecurityMessage())
{
messageAnnotationsMap.put(Symbol.valueOf(MessageProperty.IOTHUB_SECURITY_INTERFACE_ID), MessageProperty.IOTHUB_SECURITY_INTERFACE_ID_VALUE);
}
if (message.getComponentName() != null && !message.getComponentName().isEmpty())
{
messageAnnotationsMap.put(Symbol.valueOf(MessageProperty.COMPONENT_ID), message.getComponentName());
}
MessageAnnotations messageAnnotations = new MessageAnnotations(messageAnnotationsMap);
outgoingMessage.setMessageAnnotations(messageAnnotations);
Binary binary = new Binary(message.getBytes());
Section section = new Data(binary);
outgoingMessage.setBody(section);
return outgoingMessage;
}