Search in sources :

Example 1 with ProvisioningDeviceTransportException

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceTransportException in project azure-iot-sdk-java by Azure.

the class ProvisioningAmqpOperations method sendAmqpMessage.

private synchronized void sendAmqpMessage(String msgType, String operationId, byte[] msgBody) throws ProvisioningDeviceClientException {
    try {
        AmqpMessage outgoingMessage = new AmqpMessage();
        Map<String, Object> userProperties = new HashMap<>();
        userProperties.put(AMQP_OP_TYPE_PROPERTY, msgType);
        if (operationId != null && !operationId.isEmpty()) {
            userProperties.put(AMQP_OPERATION_ID, operationId);
        }
        outgoingMessage.setApplicationProperty(userProperties);
        if (msgBody != null && msgBody.length > 0) {
            outgoingMessage.setBody(msgBody);
        }
        this.amqpConnection.sendAmqpMessage(outgoingMessage);
    } catch (Exception e) {
        throw new ProvisioningDeviceTransportException("Failure sending AMQP message", e);
    }
}
Also used : ProvisioningDeviceTransportException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceTransportException) HashMap(java.util.HashMap) ProvisioningDeviceConnectionException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceConnectionException) ProvisioningDeviceTransportException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceTransportException) IOException(java.io.IOException) ProvisioningDeviceClientException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException)

Example 2 with ProvisioningDeviceTransportException

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceTransportException in project azure-iot-sdk-java by Azure.

the class ContractAPIAmqp method getRegistrationStatus.

/**
 * Gets the registration status over AMQP
 * @param requestData A non {@code null} value with all the request data
 * @param responseCallback A non {@code null} value for the callback
 * @param callbackContext An object for context. Can be {@code null}
 * @throws ProvisioningDeviceClientException If any of the parameters are invalid ({@code null} or empty)
 * @throws ProvisioningDeviceTransportException If any of the API calls to transport fail
 * @throws ProvisioningDeviceHubException If hub responds back with an invalid status
 */
public synchronized void getRegistrationStatus(RequestData requestData, ResponseCallback responseCallback, Object callbackContext) throws ProvisioningDeviceClientException {
    // SRS_ContractAPIAmqp_07_009: [If requestData is null this method shall throw ProvisioningDeviceClientException.]
    if (requestData == null) {
        throw new ProvisioningDeviceClientException(new IllegalArgumentException("requestData cannot be null"));
    }
    // SRS_ContractAPIAmqp_07_010: [If requestData.getOperationId() is null or empty, this method shall throw ProvisioningDeviceClientException.]
    String operationId = requestData.getOperationId();
    if (operationId == null || operationId.isEmpty()) {
        throw new ProvisioningDeviceClientException(new IllegalArgumentException("operationId cannot be null or empty"));
    }
    // SRS_ContractAPIAmqp_07_011: [If responseCallback is null, this method shall throw ProvisioningDeviceClientException.]
    if (responseCallback == null) {
        throw new ProvisioningDeviceClientException("responseCallback cannot be null");
    }
    // SRS_ContractAPIAmqp_07_012: [If amqpConnection is null or not connected, this method shall throw ProvisioningDeviceConnectionException.]
    try {
        if (!this.provisioningAmqpOperations.isAmqpConnected()) {
            throw new ProvisioningDeviceConnectionException("Amqp is not connected");
        }
    } catch (Exception e) {
        throw new ProvisioningDeviceClientException(e);
    }
    // SRS_ContractAPIAmqp_07_013: [This method shall send an AMQP message with the property of iotdps-get-operationstatus and the OperationId.]
    this.provisioningAmqpOperations.sendStatusMessage(operationId, responseCallback, callbackContext);
}
Also used : ProvisioningDeviceConnectionException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceConnectionException) ProvisioningDeviceClientException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException) ProvisioningDeviceConnectionException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceConnectionException) ProvisioningDeviceTransportException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceTransportException) ProvisioningDeviceHubException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceHubException) IOException(java.io.IOException) ProvisioningDeviceClientException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException)

Aggregations

ProvisioningDeviceClientException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException)2 ProvisioningDeviceConnectionException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceConnectionException)2 ProvisioningDeviceTransportException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceTransportException)2 IOException (java.io.IOException)2 ProvisioningDeviceHubException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceHubException)1 HashMap (java.util.HashMap)1