use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class IotHubTransportMessageTest method setMethodNameThrowsIllegalArgumentExceptionIfMethodNameIsNull.
/*
**Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_012: [**The function shall throw IllegalArgumentException if the methodName is null.**]**
*/
@Test(expected = IllegalArgumentException.class)
public void setMethodNameThrowsIllegalArgumentExceptionIfMethodNameIsNull() {
// arrange
byte[] data = new byte[1];
MessageType messageType = MessageType.DEVICE_TWIN;
IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
// act
iotHubTransportMessage.setMethodName(null);
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class IotHubTransportMessageTest method setStatusSetsTheStatus.
/*
**Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_008: [**The function shall save the status.**]**
*/
@Test
public void setStatusSetsTheStatus() {
// arrange
String StatusStr = "abcdefg";
byte[] data = new byte[1];
MessageType messageType = MessageType.DEVICE_TWIN;
IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
// act
iotHubTransportMessage.setStatus(StatusStr);
// assert
assertEquals(StatusStr, iotHubTransportMessage.getStatus());
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class AmqpsMethodsReceiverLinkHandler method protonMessageToIoTHubMessage.
@Override
protected IotHubTransportMessage protonMessageToIoTHubMessage(AmqpsMessage protonMsg) {
IotHubTransportMessage iotHubTransportMessage = super.protonMessageToIoTHubMessage(protonMsg);
iotHubTransportMessage.setMessageType(MessageType.DEVICE_METHODS);
iotHubTransportMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_METHOD_RECEIVE_REQUEST);
MessageCallback messageCallback = deviceClientConfig.getDeviceMethodsMessageCallback();
Object messageContext = deviceClientConfig.getDeviceMethodsMessageContext();
iotHubTransportMessage.setMessageCallback(messageCallback);
iotHubTransportMessage.setMessageCallbackContext(messageContext);
if (protonMsg.getApplicationProperties() != null && protonMsg.getApplicationProperties().getValue() != null) {
Map<String, Object> applicationProperties = protonMsg.getApplicationProperties().getValue();
if (applicationProperties.containsKey(APPLICATION_PROPERTY_KEY_IOTHUB_METHOD_NAME)) {
iotHubTransportMessage.setMethodName(applicationProperties.get(APPLICATION_PROPERTY_KEY_IOTHUB_METHOD_NAME).toString());
}
}
if (protonMsg.getProperties() != null && protonMsg.getProperties().getCorrelationId() != null) {
iotHubTransportMessage.setRequestId(protonMsg.getProperties().getCorrelationId().toString());
}
return iotHubTransportMessage;
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class AmqpsReceiverLinkHandler method onDelivery.
@Override
public void onDelivery(Event event) {
// Safe to cast as receiver here since this event only fires when a message is ready to be received over this receiver link
Receiver receiverLink = (Receiver) event.getLink();
AmqpsMessage amqpsMessage = this.getMessageFromReceiverLink(receiverLink);
if (amqpsMessage == null) {
// continue to be called until it is fully formed.
return;
}
IotHubTransportMessage iotHubMessage = this.protonMessageToIoTHubMessage(amqpsMessage);
this.receivedMessagesMap.put(iotHubMessage, amqpsMessage);
this.amqpsLinkStateCallback.onMessageReceived(iotHubMessage);
log.trace("Current link credit on {} receiver link with address {} and link correlation id {} is {}", this.getLinkInstanceType(), this.receiverLinkAddress, this.linkCorrelationId, receiverLink.getCredit());
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class AmqpsTwinSenderLinkHandler method iotHubMessageToProtonMessage.
@Override
protected MessageImpl iotHubMessageToProtonMessage(com.microsoft.azure.sdk.iot.device.Message message) {
if (message.getMessageType() == MessageType.DEVICE_TWIN) {
MessageImpl protonMessage = super.iotHubMessageToProtonMessage(message);
IotHubTransportMessage deviceTwinMessage = (IotHubTransportMessage) message;
if (deviceTwinMessage.getCorrelationId() != null) {
protonMessage.getProperties().setCorrelationId(UUID.fromString(deviceTwinMessage.getCorrelationId()));
this.twinOperationCorrelationMap.put(deviceTwinMessage.getCorrelationId(), deviceTwinMessage.getDeviceOperationType());
}
setMessageAnnotationMapOnProtonMessage(protonMessage, deviceTwinMessage.getDeviceOperationType(), deviceTwinMessage.getVersion());
return protonMessage;
}
return null;
}
Aggregations