use of com.microsoft.azure.sdk.iot.deps.serializer.DeviceParser in project azure-iot-sdk-java by Azure.
the class RegistryManager method updateDevice.
/**
* Update device with forceUpdate input parameter
* @deprecated The forceUpdate argument does nothing so this method will always behave the same as {@link #updateDevice(Device)}
*
* @param device The device object containing updated data
* @param forceUpdate This value is not used
* @return The updated device object
* @throws IOException This exception is thrown if the IO operation failed
* @throws IotHubException This exception is thrown if the response verification failed
*/
@Deprecated
public Device updateDevice(Device device, Boolean forceUpdate) throws IOException, IotHubException, JsonSyntaxException {
if (device == null) {
throw new IllegalArgumentException("device cannot be null");
}
device.setForceUpdate(forceUpdate);
URL url = IotHubConnectionString.getUrlDevice(this.hostName, device.getDeviceId());
HttpRequest request = CreateRequest(url, HttpMethod.PUT, device.toDeviceParser().toJson().getBytes(StandardCharsets.UTF_8));
request.setHeaderField("If-Match", "*");
HttpResponse response = request.send();
IotHubExceptionManager.httpResponseVerification(response);
String bodyStr = new String(response.getBody(), StandardCharsets.UTF_8);
return new Device(new DeviceParser(bodyStr));
}
use of com.microsoft.azure.sdk.iot.deps.serializer.DeviceParser in project azure-iot-sdk-java by Azure.
the class RegistryManager method getDevice.
/**
* Get device data by device Id from IotHub
*
* @param deviceId The id of requested device
* @return The device object of requested device
* @throws IOException This exception is thrown if the IO operation failed
* @throws IotHubException This exception is thrown if the response verification failed
*/
public Device getDevice(String deviceId) throws IOException, IotHubException, JsonSyntaxException {
if (Tools.isNullOrEmpty(deviceId)) {
throw new IllegalArgumentException("deviceId cannot be null or empty");
}
URL url = IotHubConnectionString.getUrlDevice(this.hostName, deviceId);
HttpRequest request = CreateRequest(url, HttpMethod.GET, new byte[0]);
HttpResponse response = request.send();
IotHubExceptionManager.httpResponseVerification(response);
String bodyStr = new String(response.getBody(), StandardCharsets.UTF_8);
return new Device(new DeviceParser(bodyStr));
}
use of com.microsoft.azure.sdk.iot.deps.serializer.DeviceParser in project azure-iot-sdk-java by Azure.
the class RegistryManager method addDevice.
/**
* Add device using the given Device object
* Return with the response device object from IotHub
*
* @param device The device object to add
* @return The future object for the requested operation
* @throws IOException This exception is thrown if the IO operation failed
* @throws IotHubException This exception is thrown if the response verification failed
*/
public Device addDevice(Device device) throws IOException, IotHubException, JsonSyntaxException {
if (device == null) {
throw new IllegalArgumentException("device cannot be null");
}
String deviceJson = device.toDeviceParser().toJson();
URL url = IotHubConnectionString.getUrlDevice(this.hostName, device.getDeviceId());
HttpRequest request = CreateRequest(url, HttpMethod.PUT, deviceJson.getBytes(StandardCharsets.UTF_8));
HttpResponse response = request.send();
IotHubExceptionManager.httpResponseVerification(response);
String bodyStr = new String(response.getBody(), StandardCharsets.UTF_8);
return new Device(new DeviceParser(bodyStr));
}
use of com.microsoft.azure.sdk.iot.deps.serializer.DeviceParser in project azure-iot-sdk-java by Azure.
the class RegistryManager method updateModule.
/**
* Update module with forceUpdate input parameter
* @deprecated The forceUpdate argument does nothing so this method will always behave the same as @link #updateModule(Module)}
*
* @param module The module object containing updated data
* @param forceUpdate This value is not used
* @return The updated module object
* @throws IOException This exception is thrown if the IO operation failed
* @throws IotHubException This exception is thrown if the response verification failed
*/
@Deprecated
public Module updateModule(Module module, Boolean forceUpdate) throws IOException, IotHubException, JsonSyntaxException {
if (module == null) {
throw new IllegalArgumentException("module cannot be null");
}
module.setForceUpdate(forceUpdate);
URL url = IotHubConnectionString.getUrlModule(this.hostName, module.getDeviceId(), module.getId());
HttpRequest request = CreateRequest(url, HttpMethod.PUT, module.toDeviceParser().toJson().getBytes(StandardCharsets.UTF_8));
request.setHeaderField("If-Match", "*");
HttpResponse response = request.send();
IotHubExceptionManager.httpResponseVerification(response);
String bodyStr = new String(response.getBody(), StandardCharsets.UTF_8);
return new Module(new DeviceParser(bodyStr));
}
use of com.microsoft.azure.sdk.iot.deps.serializer.DeviceParser in project azure-iot-sdk-java by Azure.
the class RegistryManager method getModule.
/**
* Get module data by device Id and module Id from IotHub
*
* @param deviceId The id of requested device
* @param moduleId The id of requested module
* @return The module object of requested module on the specific device
* @throws IOException This exception is thrown if the IO operation failed
* @throws IotHubException This exception is thrown if the response verification failed
*/
public Module getModule(String deviceId, String moduleId) throws IOException, IotHubException, JsonSyntaxException {
if (Tools.isNullOrEmpty(deviceId)) {
throw new IllegalArgumentException("deviceId cannot be null or empty");
}
if (Tools.isNullOrEmpty(moduleId)) {
throw new IllegalArgumentException("moduleId cannot be null or empty");
}
URL url = IotHubConnectionString.getUrlModule(this.hostName, deviceId, moduleId);
HttpRequest request = CreateRequest(url, HttpMethod.GET, new byte[0]);
HttpResponse response = request.send();
IotHubExceptionManager.httpResponseVerification(response);
String bodyStr = new String(response.getBody(), StandardCharsets.UTF_8);
return new Module(new DeviceParser(bodyStr));
}
Aggregations