Search in sources :

Example 61 with IotHubTransportMessage

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);
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Test(org.junit.Test)

Example 62 with IotHubTransportMessage

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());
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Test(org.junit.Test)

Example 63 with IotHubTransportMessage

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;
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageCallback(com.microsoft.azure.sdk.iot.device.MessageCallback)

Example 64 with 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());
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) AmqpsMessage(com.microsoft.azure.sdk.iot.deps.transport.amqp.AmqpsMessage)

Example 65 with IotHubTransportMessage

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;
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl)

Aggregations

IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)129 Test (org.junit.Test)108 Message (com.microsoft.azure.sdk.iot.device.Message)37 MutablePair (org.apache.commons.lang3.tuple.MutablePair)33 Pair (org.apache.commons.lang3.tuple.Pair)33 DeviceTwin (com.microsoft.azure.sdk.iot.device.DeviceTwin)30 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)25 HashMap (java.util.HashMap)24 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)16 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)16 MessageType (com.microsoft.azure.sdk.iot.device.MessageType)14 Verifications (mockit.Verifications)10 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)8 NonStrictExpectations (mockit.NonStrictExpectations)8 IOException (java.io.IOException)5 FileUploadTask (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask)4 MessageCallback (com.microsoft.azure.sdk.iot.device.MessageCallback)3 MethodResult (com.microsoft.azure.sdk.iot.device.edge.MethodResult)3 HttpsTransportManager (com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager)3 HashSet (java.util.HashSet)3