use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class AmqpsSenderLinkHandler method iotHubMessageToProtonMessage.
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;
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class HttpsBatchMessageTest method getPropertiesReturnsNoProperties.
// Tests_SRS_HTTPSBATCHMESSAGE_11_012: [The function shall return an empty array.]
@Test
public void getPropertiesReturnsNoProperties() throws IotHubSizeExceededException {
List<HttpsSingleMessage> mockMessageList = new ArrayList<>();
HttpsBatchMessage batchMsg = new HttpsBatchMessage(mockMessageList);
MessageProperty[] testProperties = batchMsg.getProperties();
MessageProperty[] expectedProperties = new MessageProperty[0];
assertThat(testProperties, is(expectedProperties));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MessagePropertyTest method hasNameFailsForNonMatchingName.
// Tests_SRS_MESSAGEPROPERTY_11_006: [The function shall return true if and only if the property has the given name, where the names are compared in a case-insensitive manner.]
@Test
public void hasNameFailsForNonMatchingName() {
final String name = "test-name";
final String value = "test-value";
MessageProperty property = new MessageProperty(name, value);
boolean testHasName = property.hasSameName("test-mame");
final boolean expectedHasName = false;
assertThat(testHasName, is(expectedHasName));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MessagePropertyTest method constructorSavesPropertyValue.
// Tests_SRS_MESSAGEPROPERTY_11_001: [The constructor shall save the property name and value.]
// Tests_SRS_MESSAGEPROPERTY_11_005: [The function shall return the property value.]
@Test
public void constructorSavesPropertyValue() {
final String name = "test-name";
final String value = "test-value";
MessageProperty property = new MessageProperty(name, value);
String testValue = property.getValue();
assertThat(testValue, is(value));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MessagePropertyTest method constructorSavesPropertyName.
// Tests_SRS_MESSAGEPROPERTY_11_001: [The constructor shall save the property name and value.]
// Tests_SRS_MESSAGEPROPERTY_11_004: [The function shall return the property name.]
@Test
public void constructorSavesPropertyName() {
final String name = "test-name";
final String value = "test-value";
MessageProperty property = new MessageProperty(name, value);
String testName = property.getName();
assertThat(testName, is(name));
}
Aggregations