Search in sources :

Example 1 with ProvisioningServiceClientServiceException

use of com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException in project azure-iot-sdk-java by Azure.

the class IndividualEnrollmentManager method getAttestationMechanism.

AttestationMechanism getAttestationMechanism(String registrationId) throws ProvisioningServiceClientException {
    if (Tools.isNullOrEmpty(registrationId)) {
        throw new IllegalArgumentException("registrationId cannot be null or empty.");
    }
    String enrollmentAttestationMechanismPath = IndividualEnrollmentManager.getEnrollmentAttestationMechanismPath(registrationId);
    String payload = "{}";
    HttpResponse httpResponse = contractApiHttp.request(HttpMethod.POST, enrollmentAttestationMechanismPath, null, payload);
    byte[] body = httpResponse.getBody();
    if (body == null) {
        throw new ProvisioningServiceClientServiceException("Unexpected empty body received from service");
    }
    return new AttestationMechanism(new String(body, StandardCharsets.UTF_8));
}
Also used : ProvisioningServiceClientServiceException(com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException) HttpResponse(com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse)

Example 2 with ProvisioningServiceClientServiceException

use of com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException in project azure-iot-sdk-java by Azure.

the class IndividualEnrollmentManager method bulkOperation.

/**
 * Rum a bulk individualEnrollment operation.
 *
 * @see ProvisioningServiceClient#runBulkEnrollmentOperation(BulkOperationMode, Collection)
 *
 * @param bulkOperationMode the {@link BulkOperationMode} that defines the single operation to do over the individualEnrollments. It cannot be {@code null}.
 * @param individualEnrollments the collection of {@link IndividualEnrollment} that contains the description of each individualEnrollment. It cannot be {@code null} or empty.
 * @return An {@link BulkEnrollmentOperationResult} with the result of the bulk operation request.
 * @throws IllegalArgumentException if the provided parameters are not correct.
 * @throws ProvisioningServiceClientTransportException if the SDK failed to send the request to the Device Provisioning Service.
 * @throws ProvisioningServiceClientException if the Device Provisioning Service was not able to execute the bulk operation.
 */
BulkEnrollmentOperationResult bulkOperation(BulkOperationMode bulkOperationMode, Collection<IndividualEnrollment> individualEnrollments) throws ProvisioningServiceClientException {
    /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_012: [The BulkEnrollmentOperation shall throw IllegalArgumentException if the provided bulkOperationMode is null.] */
    if (bulkOperationMode == null) {
        throw new IllegalArgumentException("bulkOperationMode cannot be null.");
    }
    /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_013: [The BulkEnrollmentOperation shall throw IllegalArgumentException if the provided individualEnrollments is null or empty.] */
    if ((individualEnrollments == null) || individualEnrollments.isEmpty()) {
        throw new IllegalArgumentException("individualEnrollments cannot be null or empty.");
    }
    /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_014: [The BulkEnrollmentOperation shall send a Http request for the path `individualEnrollments`.] */
    String bulkEnrollmentPath = IndividualEnrollmentManager.getEnrollmentsPath();
    /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_015: [The BulkEnrollmentOperation shall send a Http request with a body with the individualEnrollments content in JSON format.] */
    String bulkEnrollmentPayload = BulkEnrollmentOperation.toJson(bulkOperationMode, individualEnrollments);
    /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_016: [The BulkEnrollmentOperation shall send a Http request with a Http verb `POST`.] */
    /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_017: [The BulkEnrollmentOperation shall throw ProvisioningServiceClientTransportException if the request failed. Threw by the callee.] */
    /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_018: [The BulkEnrollmentOperation shall throw ProvisioningServiceClientException if the Device Provisioning Service could not successfully execute the request. Threw by the callee.] */
    HttpResponse httpResponse = contractApiHttp.request(HttpMethod.POST, bulkEnrollmentPath, null, bulkEnrollmentPayload);
    /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_043: [The BulkEnrollmentOperation shall throw ProvisioningServiceClientServiceException if the heepResponse contains a null body.] */
    byte[] body = httpResponse.getBody();
    if (body == null) {
        throw new ProvisioningServiceClientServiceException("Http response for BulkEnrollmentOperation cannot contains a null body");
    }
    /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_019: [The BulkEnrollmentOperation shall return a BulkEnrollmentOperationResult object created from the body of the response for the Http request .] */
    return new BulkEnrollmentOperationResult(new String(body, StandardCharsets.UTF_8));
}
Also used : ProvisioningServiceClientServiceException(com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException) HttpResponse(com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse)

Example 3 with ProvisioningServiceClientServiceException

use of com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException in project azure-iot-sdk-java by Azure.

the class EnrollmentGroupManager method getAttestationMechanism.

AttestationMechanism getAttestationMechanism(String enrollmentGroupId) throws ProvisioningServiceClientException {
    if (Tools.isNullOrEmpty(enrollmentGroupId)) {
        throw new IllegalArgumentException("enrollmentGroupId cannot be null or empty.");
    }
    String enrollmentAttestationMechanismPath = getEnrollmentGroupAttestationMechanismPath(enrollmentGroupId);
    String payload = "{}";
    HttpResponse httpResponse = contractApiHttp.request(HttpMethod.POST, enrollmentAttestationMechanismPath, null, payload);
    byte[] body = httpResponse.getBody();
    if (body == null) {
        throw new ProvisioningServiceClientServiceException("Unexpected empty body received from service");
    }
    return new AttestationMechanism(new String(body, StandardCharsets.UTF_8));
}
Also used : ProvisioningServiceClientServiceException(com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException) HttpResponse(com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse) AttestationMechanism(com.microsoft.azure.sdk.iot.provisioning.service.configs.AttestationMechanism)

Example 4 with ProvisioningServiceClientServiceException

use of com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException in project azure-iot-sdk-java by Azure.

the class EnrollmentGroupManager method createOrUpdate.

/**
 * Create or update an enrollmentGroup record.
 *
 * @param enrollmentGroup is an {@link EnrollmentGroup} that describes the enrollmentGroup that will be created or
 *                        updated. It cannot be {@code null}.
 * @return a {@link EnrollmentGroup} with the result of the creation or update request.
 * @throws IllegalArgumentException if the provided parameter is not correct.
 * @throws ProvisioningServiceClientTransportException if the SDK failed to send the request to the Device Provisioning Service.
 * @throws ProvisioningServiceClientException if the Device Provisioning Service was not able to create or update the enrollmentGroup.
 */
EnrollmentGroup createOrUpdate(EnrollmentGroup enrollmentGroup) throws ProvisioningServiceClientException {
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_005: [The createOrUpdate shall throw IllegalArgumentException if the provided enrollmentGroup is null.] */
    if (enrollmentGroup == null) {
        throw new IllegalArgumentException("enrollmentGroup cannot be null.");
    }
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_006: [The createOrUpdate shall send a Http request for the path `enrollmentGroups/[enrollmentGroupId]`.] */
    String id = enrollmentGroup.getEnrollmentGroupId();
    String enrollmentGroupPath = EnrollmentGroupManager.getEnrollmentGroupPath(id);
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_007: [The createOrUpdate shall send a Http request with a body with the enrollmentGroup content in JSON format.] */
    String enrollmentGroupPayload = enrollmentGroup.toJson();
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_045: [If the enrollmentGroup contains eTag, the createOrUpdate shall send a Http request with `If-Match` the eTag in the header.] */
    Map<String, String> headerParameters = new HashMap<>();
    if (!Tools.isNullOrEmpty(enrollmentGroup.getEtag())) {
        headerParameters.put(CONDITION_KEY, enrollmentGroup.getEtag());
    }
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_008: [The createOrUpdate shall send a Http request with a Http verb `PUT`.] */
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_009: [The createOrUpdate shall throw ProvisioningServiceClientTransportException if the request failed. Threw by the callee.] */
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_010: [The createOrUpdate shall throw ProvisioningServiceClientException if the Device Provisioning Service could not successfully execute the request. Threw by the callee.] */
    HttpResponse httpResponse = contractApiHttp.request(HttpMethod.PUT, enrollmentGroupPath, headerParameters, enrollmentGroupPayload);
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_042: [The createOrUpdate shall throw ProvisioningServiceClientServiceException if the heepResponse contains a null body.] */
    byte[] body = httpResponse.getBody();
    if (body == null) {
        throw new ProvisioningServiceClientServiceException("Http response for createOrUpdate cannot contains a null body");
    }
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_011: [The createOrUpdate shall return an EnrollmentGroup object created from the body of the response for the Http request .] */
    return new EnrollmentGroup(new String(body, StandardCharsets.UTF_8));
}
Also used : ProvisioningServiceClientServiceException(com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException) HashMap(java.util.HashMap) EnrollmentGroup(com.microsoft.azure.sdk.iot.provisioning.service.configs.EnrollmentGroup) HttpResponse(com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse)

Example 5 with ProvisioningServiceClientServiceException

use of com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException in project azure-iot-sdk-java by Azure.

the class EnrollmentGroupManager method get.

/**
 * Get enrollmentGroup information.
 *
 * @see ProvisioningServiceClient#getEnrollmentGroup(String)
 *
 * @param enrollmentGroupId the {@code String} that identifies the enrollmentGroup. It cannot be {@code null} or empty.
 * @return An {@link EnrollmentGroup} with the enrollmentGroup information.
 * @throws IllegalArgumentException if the provided parameter is not correct.
 * @throws ProvisioningServiceClientTransportException if the SDK failed to send the request to the Device Provisioning Service.
 * @throws ProvisioningServiceClientException if the Device Provisioning Service was not able to execute the get operation.
 */
EnrollmentGroup get(String enrollmentGroupId) throws ProvisioningServiceClientException {
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_020: [The get shall throw IllegalArgumentException if the provided enrollmentGroupId is null or empty.] */
    if (Tools.isNullOrEmpty(enrollmentGroupId)) {
        throw new IllegalArgumentException("enrollmentGroupId cannot be null or empty.");
    }
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_021: [The get shall send a Http request for the path `enrollmentGroups/[enrollmentGroupId]`.] */
    String enrollmentGroupPath = EnrollmentGroupManager.getEnrollmentGroupPath(enrollmentGroupId);
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_022: [The get shall send a Http request with a Http verb `GET`.] */
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_023: [The get shall throw ProvisioningServiceClientTransportException if the request failed. Threw by the callee.] */
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_024: [The get shall throw ProvisioningServiceClientException if the Device Provisioning Service could not successfully execute the request. Threw by the callee.] */
    HttpResponse httpResponse = contractApiHttp.request(HttpMethod.GET, enrollmentGroupPath, null, "");
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_043: [The get shall throw ProvisioningServiceClientServiceException if the heepResponse contains a null body.] */
    byte[] body = httpResponse.getBody();
    if (body == null) {
        throw new ProvisioningServiceClientServiceException("Http response for get cannot contains a null body");
    }
    /* SRS_ENROLLMENT_GROUP_MANAGER_21_025: [The get shall return an EnrollmentGroup object created from the body of the response for the Http request .] */
    return new EnrollmentGroup(new String(body, StandardCharsets.UTF_8));
}
Also used : ProvisioningServiceClientServiceException(com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException) EnrollmentGroup(com.microsoft.azure.sdk.iot.provisioning.service.configs.EnrollmentGroup) HttpResponse(com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse)

Aggregations

HttpResponse (com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse)7 ProvisioningServiceClientServiceException (com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException)7 EnrollmentGroup (com.microsoft.azure.sdk.iot.provisioning.service.configs.EnrollmentGroup)2 HashMap (java.util.HashMap)2 AttestationMechanism (com.microsoft.azure.sdk.iot.provisioning.service.configs.AttestationMechanism)1