use of com.microsoft.azure.sdk.iot.provisioning.service.configs.DeviceRegistrationState in project azure-iot-sdk-java by Azure.
the class RegistrationStatusManager method get.
/**
* Get device registration status information.
*
* @see ProvisioningServiceClient#getDeviceRegistrationState(String)
*
* @param id the {@code String} that identifies the registration status. It cannot be {@code null} or empty.
* @return An {@link DeviceRegistrationState} with the registration status 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 bulk operation.
*/
public DeviceRegistrationState get(String id) throws ProvisioningServiceClientException {
/* SRS_REGISTRATION_STATUS_MANAGER_21_005: [The get shall throw IllegalArgumentException if the provided id is null or empty.] */
if (Tools.isNullOrEmpty(id)) {
throw new IllegalArgumentException("Id cannot be null or empty.");
}
/* SRS_REGISTRATION_STATUS_MANAGER_21_006: [The get shall send a Http request for the path `registrations/[id]`.] */
String enrollmentPath = RegistrationStatusManager.getDeviceRegistrationStatePath(id);
/* SRS_REGISTRATION_STATUS_MANAGER_21_007: [The get shall send a Http request with a Http verb `GET`.] */
/* SRS_REGISTRATION_STATUS_MANAGER_21_008: [The get shall throw ProvisioningServiceClientTransportException if the request failed. Threw by the callee.] */
/* SRS_REGISTRATION_STATUS_MANAGER_21_009: [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, enrollmentPath, null, "");
/* SRS_REGISTRATION_STATUS_MANAGER_21_028: [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_REGISTRATION_STATUS_MANAGER_21_010: [The get shall return a DeviceRegistrationState object created from the body of the response for the Http request .] */
return new DeviceRegistrationState(new String(body, StandardCharsets.UTF_8));
}
Aggregations