Search in sources :

Example 1 with ProvisioningDeviceConnectionException

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

the class ContractAPIAmqp method open.

/**
 * Indicates need to open AMQP connection
 * @param requestData Data used for the connection initialization
 * @throws ProvisioningDeviceConnectionException is thrown when any of the input parameters are invalid
 */
@Override
public synchronized void open(RequestData requestData) throws ProvisioningDeviceConnectionException {
    if (requestData == null) {
        // Codes_SRS_ContractAPIAmqp_34_006: [If requestData is null, this function shall throw a ProvisioningDeviceConnectionException.]
        throw new ProvisioningDeviceConnectionException(new IllegalArgumentException("requestData cannot be null"));
    }
    if (requestData.isX509()) {
        String registrationId = requestData.getRegistrationId();
        if (registrationId == null || registrationId.isEmpty()) {
            // Codes_SRS_ContractAPIAmqp_34_007: [If requestData contains a null or empty registrationId, this function shall throw a ProvisioningDeviceConnectionException.]
            throw new ProvisioningDeviceConnectionException(new IllegalArgumentException("registration Id cannot be null or empty"));
        }
        SSLContext sslContext = requestData.getSslContext();
        if (sslContext == null) {
            // Codes_SRS_ContractAPIAmqp_34_008: [If requestData contains a null SSLContext, this function shall throw a ProvisioningDeviceConnectionException.]
            throw new ProvisioningDeviceConnectionException(new IllegalArgumentException("sslContext cannot be null"));
        }
        // Codes_SRS_ContractAPIAmqp_34_014: [If the requestData is using X509, this function shall open the
        // underlying provisioningAmqpOperations object with the provided registrationId and sslContext.]
        this.provisioningAmqpOperations.open(registrationId, sslContext, this.amqpSaslHandler, this.useWebSockets);
    }
}
Also used : ProvisioningDeviceConnectionException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceConnectionException) SSLContext(javax.net.ssl.SSLContext)

Example 2 with ProvisioningDeviceConnectionException

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

the class ProvisioningAmqpOperations method open.

/**
 * Opens the Amqp connection
 * @param registrationId The specified registration id for the connection
 * @param sslContext The SSLContext that will get used for this connection
 * @param saslHandler custom handler for sasl logic. May be null if no sasl frames are expected
 * @param useWebSockets Flag to determine if using WebSockets
 * @throws ProvisioningDeviceConnectionException if connection could not succeed for any reason.
 */
public void open(String registrationId, SSLContext sslContext, SaslHandler saslHandler, boolean useWebSockets) throws ProvisioningDeviceConnectionException {
    // SRS_ProvisioningAmqpOperations_07_003: [If amqpConnection is not null and is connected, open shall do nothing .]
    try {
        if (this.amqpConnection == null || !this.amqpConnection.isConnected()) {
            // SRS_ProvisioningAmqpOperations_07_004: [open shall throw ProvisioningDeviceClientException if either registrationId or sslContext are null or empty.]
            if (registrationId == null || registrationId.isEmpty()) {
                throw new ProvisioningDeviceConnectionException(new IllegalArgumentException("registration Id cannot be null or empty"));
            }
            if (sslContext == null) {
                throw new ProvisioningDeviceConnectionException(new IllegalArgumentException("sslContext cannot be null"));
            }
            addAmqpLinkProperty(API_VERSION_KEY, SDKUtils.getServiceApiVersion());
            addAmqpLinkProperty(CLIENT_VERSION_IDENTIFIER_KEY, SDKUtils.getUserAgentString());
            // SRS_ProvisioningAmqpOperations_07_005: [This method shall construct the Link Address with /<scopeId>/registrations/<registrationId>.]
            this.amqpLinkAddress = String.format(AMQP_ADDRESS_FMT, this.idScope, registrationId);
            this.amqpConnection = new AmqpsConnection(this.hostName, this, sslContext, saslHandler, useWebSockets);
            this.amqpConnection.setListener(this);
            if (saslHandler != null) {
                // SRS_ProvisioningAmqpOperations_34_019: [If the provided sasl handler is not null, this function shall open the underlying amqpConnection asynchronously.]
                this.amqpConnection.openAmqpAsync();
            } else {
                // SRS_ProvisioningAmqpOperations_34_020: [If the provided sasl handler is null, this function shall open the underlying amqpConnection synchronously.]
                this.amqpConnection.open();
            }
        }
    } catch (Exception ex) {
        // SRS_ProvisioningAmqpOperations_07_006: [This method shall connect to the amqp connection and throw ProvisioningDeviceConnectionException on error.]
        throw new ProvisioningDeviceConnectionException("Failure opening amqp connection", ex);
    }
}
Also used : ProvisioningDeviceConnectionException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceConnectionException) 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 3 with ProvisioningDeviceConnectionException

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceConnectionException 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

ProvisioningDeviceConnectionException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceConnectionException)3 ProvisioningDeviceClientException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException)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 SSLContext (javax.net.ssl.SSLContext)1