/** * Asynchronously sends an event message to the IoT Hub. * * @param message the message to be sent. * @param callback the callback to be invoked when a response is received. * Can be {@code null}. * @param callbackContext a context to be passed to the callback. Can be * {@code null} if no callback is provided. * * @throws IllegalArgumentException if the message provided is {@code null}. * @throws IllegalStateException if the client has not been opened yet or is * already closed. */ public void sendEventAsync(Message message, IotHubEventCallback callback, Object callbackContext) { //Codes_SRS_INTERNALCLIENT_34_045: [This function shall set the provided message's connection device id to the config's saved device id.] message.setConnectionDeviceId(this.config.getDeviceId()); //Codes_SRS_INTERNALCLIENT_21_010: [The sendEventAsync shall asynchronously send the message using the deviceIO connection.] deviceIO.sendEventAsync(message, callback, callbackContext, this.config.getDeviceId()); }
/** * This constructor creates an instance of AmqpsDeviceAuthenticationCBS class and initializes member variables * * @param deviceClientConfig the device config to use for authentication. * @throws IllegalArgumentException if deviceClientConfig is null. */ public AmqpsDeviceAuthenticationCBS(DeviceClientConfig deviceClientConfig) throws IllegalArgumentException { // Codes_SRS_AMQPSDEVICEAUTHENTICATIONCBS_34_050: [This constructor shall call super with the provided user agent string.] super(deviceClientConfig); this.deviceClientConfig = deviceClientConfig; // Codes_SRS_AMQPSDEVICEAUTHENTICATIONCBS_12_001: [The constructor shall set the sender and receiver endpoint path to IoTHub specific values.] this.senderLinkEndpointPath = SENDER_LINK_ENDPOINT_PATH; this.receiverLinkEndpointPath = RECEIVER_LINK_ENDPOINT_PATH; // Codes_SRS_AMQPSDEVICEAUTHENTICATIONCBS_12_002: [The constructor shall concatenate a sender specific prefix to the sender link tag's current value.] this.senderLinkTag = SENDER_LINK_TAG_PREFIX + senderLinkTag; this.receiverLinkTag = RECEIVER_LINK_TAG_PREFIX + receiverLinkTag; // Codes_SRS_AMQPSDEVICEAUTHENTICATIONCBS_12_003: [The constructor shall set the sender and receiver endpoint path.] this.senderLinkAddress = senderLinkEndpointPath; this.receiverLinkAddress = receiverLinkEndpointPath; // Codes_SRS_AMQPSDEVICEAUTHENTICATIONCBS_12_004: [The constructor shall add API version key and API version value to the amqpProperties.*] this.amqpProperties.put(Symbol.getSymbol(API_VERSION_KEY), TransportUtils.IOTHUB_API_VERSION); this.amqpProperties.put(Symbol.getSymbol(MessageProperty.CONNECTION_DEVICE_ID), deviceClientConfig.getDeviceId()); this.logger = new CustomLogger(this.getClass()); }
if (config.getDeviceId() == null || config.getDeviceId().length() == 0)
if (this.deviceClientConfig.getDeviceId().equals(deviceId))
/** * This constructor creates an instance of AmqpsDeviceTelemetry class and initializes member variables * * @param deviceClientConfig The configuration settings for an IoT Hub client * @throws IllegalArgumentException if the deviceClientConfig argument is null */ AmqpsDeviceTelemetry(DeviceClientConfig deviceClientConfig) throws IllegalArgumentException { // Codes_SRS_AMQPSDEVICETELEMETRY_34_050: [This constructor shall call super with the provided user agent string.] super(deviceClientConfig, SENDER_LINK_ENDPOINT_PATH_DEVICES, RECEIVER_LINK_ENDPOINT_PATH_DEVICES, SENDER_LINK_ENDPOINT_PATH_MODULES, deviceClientConfig.getGatewayHostname() != null ? RECEIVER_LINK_ENDPOINT_PATH_MODULES_EDGEHUB : RECEIVER_LINK_ENDPOINT_PATH_MODULES, SENDER_LINK_TAG_PREFIX, RECEIVER_LINK_TAG_PREFIX); this.deviceClientConfig = deviceClientConfig; String moduleId = this.deviceClientConfig.getModuleId(); if (moduleId != null && !moduleId.isEmpty()) { this.amqpProperties.put(Symbol.getSymbol(CORRELATION_ID_KEY), Symbol.getSymbol(this.deviceClientConfig.getDeviceId() + "/" + moduleId)); } else { this.amqpProperties.put(Symbol.getSymbol(CORRELATION_ID_KEY), Symbol.getSymbol(this.deviceClientConfig.getDeviceId())); } }
String deviceId = deviceClientConfig.getDeviceId(); if (moduleId != null && !moduleId.isEmpty())
/** * Convert Proton message to IoTHubMessage if the message type is methods * * @param amqpsMessage The Proton message to convert * @param deviceClientConfig The device client configuration * @return the converted message */ @Override protected AmqpsConvertFromProtonReturnValue convertFromProton(AmqpsMessage amqpsMessage, DeviceClientConfig deviceClientConfig) throws TransportException { if ((amqpsMessage.getAmqpsMessageType() == MessageType.DEVICE_METHODS) && (this.deviceClientConfig.getDeviceId().equals(deviceClientConfig.getDeviceId()))) { // Codes_SRS_AMQPSDEVICEMETHODS_12_016: [The function shall convert the amqpsMessage to IoTHubTransportMessage.] Message message = protonMessageToIoTHubMessage(amqpsMessage); MessageCallback messageCallback = deviceClientConfig.getDeviceMethodsMessageCallback(); Object messageContext = deviceClientConfig.getDeviceMethodsMessageContext(); // Codes_SRS_AMQPSDEVICEMETHODS_12_027: [The function shall create a AmqpsConvertFromProtonReturnValue and set the message field to the new IotHubTransportMessage.] // Codes_SRS_AMQPSDEVICEMETHODS_12_028: [The function shall create a AmqpsConvertFromProtonReturnValue and copy the DeviceClientConfig callback and context to it.] return new AmqpsConvertFromProtonReturnValue(message, messageCallback, messageContext); } else { // Codes_SRS_AMQPSDEVICEMETHODS_12_015: [The function shall return null if the message type is not DEVICE_METHODS.] return null; } }
/** * Convert Proton message to IoTHubMessage if the message type is twin * * @param amqpsMessage The Proton message to convert * @param deviceClientConfig The device client configuration * @throws TransportException if the conversion fails * @return the converted message */ @Override protected AmqpsConvertFromProtonReturnValue convertFromProton(AmqpsMessage amqpsMessage, DeviceClientConfig deviceClientConfig) throws TransportException { if ((amqpsMessage.getAmqpsMessageType() == MessageType.DEVICE_TWIN) && (this.deviceClientConfig.getDeviceId().equals(deviceClientConfig.getDeviceId()))) { // Codes_SRS_AMQPSDEVICETWIN_12_016: [The function shall convert the amqpsMessage to IoTHubTransportMessage.] Message message = protonMessageToIoTHubMessage(amqpsMessage); MessageCallback messageCallback = deviceClientConfig.getDeviceTwinMessageCallback(); Object messageContext = deviceClientConfig.getDeviceTwinMessageContext(); // Codes_SRS_AMQPSDEVICETWIN_12_027: [The function shall create a AmqpsConvertFromProtonReturnValue and set the message field to the new IotHubTransportMessage.] // Codes_SRS_AMQPSDEVICETWIN_12_028: [The function shall create a AmqpsConvertFromProtonReturnValue and copy the DeviceClientConfig callback and context to it.] return new AmqpsConvertFromProtonReturnValue(message, messageCallback, messageContext); } else { // Codes_SRS_AMQPSDEVICETWIN_12_015: [The function shall return null if the message type is not DEVICE_TWIN.] return null; } }
subscribeMessage.setConnectionDeviceId(this.config.getDeviceId()); this.deviceIO.sendEventAsync(subscribeMessage, new deviceMethodRequestMessageCallback(), null, this.config.getDeviceId());
public ResponseMessage sendFileUploadMessage(IotHubTransportMessage message) throws IOException { //Codes_SRS_HTTPSTRANSPORTMANAGER_34_028 [This function shall set the uri path of the provided message to the // format devices/<deviceid>/modules/<moduleid>/files if a moduleId is present or // devices/<deviceid>/modules/<moduleid>/files otherwise, and then send it.] String uri = new IotHubUri("", this.config.getDeviceId(), PATH_FILES_STRING, this.config.getModuleId()).toStringWithoutApiVersion(); message.setUriPath(uri); return this.send(message, new HashMap<String, String>()); }
public ResponseMessage sendFileUploadNotification(IotHubTransportMessage message) throws IOException { //Codes_SRS_HTTPSTRANSPORTMANAGER_34_029 [This function shall set the uri path of the provided message to the // format devices/<deviceid>/modules/<moduleid>/files/notifications if a moduleId is present or // devices/<deviceid>/modules/<moduleid>/files/notifications otherwise, and then send it.] String uri = new IotHubUri("", this.config.getDeviceId(), PATH_NOTIFICATIONS_STRING, this.config.getModuleId()).toStringWithoutApiVersion(); message.setUriPath(uri); return this.send(message, new HashMap<String, String>()); }
private void checkSubscription() { if (!isSubscribed) { /* **Codes_SRS_DEVICETWIN_25_018: [**If not already subscribed then this method shall create a device twin message with empty payload and set its type as DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_REQUEST.**]** */ IotHubTransportMessage desiredPropertiesNotificationRequest = new IotHubTransportMessage(new byte[0], MessageType.DEVICE_TWIN); desiredPropertiesNotificationRequest.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_REQUEST); /* **Codes_SRS_DEVICETWIN_25_019: [**If not already subscribed then this method shall send the message using sendEventAsync.**]** */ this.deviceIO.sendEventAsync(desiredPropertiesNotificationRequest, new deviceTwinRequestMessageCallback(), null, this.config.getDeviceId()); } }
public void getDeviceTwin() { /* **Codes_SRS_DEVICETWIN_25_005: [**The method shall create a device twin message with empty payload to be sent IotHub.**]** */ IotHubTransportMessage getTwinRequestMessage = new IotHubTransportMessage(new byte[0], MessageType.DEVICE_TWIN); /* **Codes_SRS_DEVICETWIN_25_007: [**This method shall set the request id for the message by calling setRequestId .**]** */ getTwinRequestMessage.setRequestId(String.valueOf(requestId++)); /* **Codes_SRS_DEVICETWIN_25_006: [**This method shall set the message type as DEVICE_OPERATION_TWIN_GET_REQUEST by calling setDeviceOperationType.**]** */ getTwinRequestMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_GET_REQUEST); /* **Codes_SRS_DEVICETWIN_25_008: [**This method shall send the message to the lower transport layers by calling sendEventAsync.**]** */ this.deviceIO.sendEventAsync(getTwinRequestMessage, new deviceTwinRequestMessageCallback(), null, this.config.getDeviceId()); }
/** * Convert Proton message to IoTHubMessage if the message type is telemetry * * @param amqpsMessage The Proton message to convert * @param deviceClientConfig The device client configuration * @return the converted message */ @Override protected AmqpsConvertFromProtonReturnValue convertFromProton(AmqpsMessage amqpsMessage, DeviceClientConfig deviceClientConfig) throws TransportException { if (((amqpsMessage.getAmqpsMessageType() == null) || (amqpsMessage.getAmqpsMessageType() == MessageType.DEVICE_TELEMETRY)) && (this.deviceClientConfig.getDeviceId().equals(deviceClientConfig.getDeviceId()))) { // Codes_SRS_AMQPSDEVICETELEMETRY_12_009: [The function shall create a new IoTHubMessage using the Proton message body.] // Codes_SRS_AMQPSDEVICETELEMETRY_12_010: [**The function shall copy the correlationId, messageId, To and userId properties to the IotHubMessage properties.] // Codes_SRS_AMQPSDEVICETELEMETRY_12_011: [The function shall copy the Proton application properties to IoTHubMessage properties excluding the reserved property names.] Message message = protonMessageToIoTHubMessage(amqpsMessage); MessageCallback messageCallback = deviceClientConfig.getDeviceTelemetryMessageCallback(message.getInputName()); Object messageContext = deviceClientConfig.getDeviceTelemetryMessageContext(message.getInputName()); // Codes_SRS_AMQPSDEVICETELEMETRY_12_012: [The function shall create a new AmqpsConvertFromProtonReturnValue object and fill it with the converted message and the user callback and user context values from the deviceClientConfig.] // Codes_SRS_AMQPSDEVICETELEMETRY_12_013: [The function shall return with the new AmqpsConvertFromProtonReturnValue object.] return new AmqpsConvertFromProtonReturnValue(message, messageCallback, messageContext); } else { // Codes_SRS_AMQPSDEVICETELEMETRY_12_008: [The function shall return null if the Proton message type is not null or DEVICE_TELEMETRY.] return null; } }
additionalHeaders.put(MODULE_ID, this.config.getDeviceId() + "/" + this.config.getModuleId());
public static String buildExceptionMessage(String baseMessage, Collection<InternalClient> clients) { String hostname = ""; String protocol = ""; Collection<String> deviceIds = new ArrayList<>(); Collection<String> moduleIds = new ArrayList<>(); for (InternalClient client : clients) { hostname = client.getConfig().getIotHubHostname(); protocol = client.getConfig().getProtocol().toString(); deviceIds.add(client.getConfig().getDeviceId()); if (client.getConfig().getModuleId() != null && !client.getConfig().getModuleId().isEmpty()) { moduleIds.add(client.getConfig().getModuleId()); } } return buildExceptionMessage( baseMessage, deviceIds, protocol, hostname, moduleIds); }
updateReportedPropertiesRequest.setConnectionDeviceId(this.config.getDeviceId()); this.deviceIO.sendEventAsync(updateReportedPropertiesRequest, new deviceTwinRequestMessageCallback(), null, this.config.getDeviceId());
public static String buildExceptionMessage(String baseMessage, InternalClient client) { if (client == null || client.getConfig() == null) { throw new IllegalArgumentException("client and config must not be null"); } return buildExceptionMessage( baseMessage, client.getConfig().getDeviceId(), client.getConfig().getProtocol().toString(), client.getConfig().getIotHubHostname(), client.getConfig().getModuleId()); }
userProperties.put(NAME_KEY, host + DEVICES_PATH + deviceClientConfig.getDeviceId()); ApplicationProperties applicationProperties = new ApplicationProperties(userProperties); outgoingMessage.setApplicationProperties(applicationProperties);
public CorrelationDetailsLoggingAssert(InternalClient internalClient) { this(internalClient.getConfig().getIotHubHostname(), internalClient.getConfig().getDeviceId(), internalClient.getConfig().getProtocol().toString(), internalClient.getConfig().getModuleId()); }