use of com.microsoft.azure.sdk.iot.deps.serializer.DeviceParser in project azure-iot-sdk-java by Azure.
the class RegistryManagerTest method commonModuleExpectations.
private void commonModuleExpectations(String connectionString, String deviceId, String moduleId) throws Exception {
new NonStrictExpectations() {
{
IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
result = iotHubConnectionString;
iotHubConnectionString.getHostName();
result = "aaa.bbb.ccc";
IotHubConnectionString.getUrlModule(anyString, deviceId, moduleId);
result = mockUrl;
mockHttpRequest.send();
result = mockHttpResponse;
IotHubExceptionManager.httpResponseVerification((HttpResponse) any);
mockHttpResponse.getBody();
result = moduleJson.getBytes(StandardCharsets.UTF_8);
Deencapsulation.invoke(module, "toDeviceParser");
result = new DeviceParser();
}
};
}
use of com.microsoft.azure.sdk.iot.deps.serializer.DeviceParser in project azure-iot-sdk-java by Azure.
the class RegistryManagerTest method commonExpectations.
private void commonExpectations(String connectionString, String deviceId) throws Exception {
new NonStrictExpectations() {
{
IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
result = iotHubConnectionString;
iotHubConnectionString.getHostName();
result = "aaa.bbb.ccc";
IotHubConnectionString.getUrlDevice(anyString, deviceId);
result = mockUrl;
mockHttpRequest.send();
result = mockHttpResponse;
IotHubExceptionManager.httpResponseVerification((HttpResponse) any);
mockHttpResponse.getBody();
result = deviceJson.getBytes(StandardCharsets.UTF_8);
Deencapsulation.invoke(device, "toDeviceParser");
result = new DeviceParser();
}
};
}
use of com.microsoft.azure.sdk.iot.deps.serializer.DeviceParser in project azure-iot-sdk-java by Azure.
the class RegistryManager method getDevices.
/**
* Get list of devices
* @deprecated as of release 1.12.0. Please use
* {@link com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin#queryTwin(String sqlQuery, Integer pageSize)}
* to query for all devices.
*
* @param maxCount The requested count of devices
* @return The array of requested device objects
* @throws IOException This exception is thrown if the IO operation failed
* @throws IotHubException This exception is thrown if the response verification failed
*/
@Deprecated
public ArrayList<Device> getDevices(Integer maxCount) throws IOException, IotHubException, JsonSyntaxException {
if (maxCount < 1) {
throw new IllegalArgumentException("maxCount cannot be less then 1");
}
URL url = IotHubConnectionString.getUrlDeviceList(this.hostName, maxCount);
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);
try (JsonReader jsonReader = Json.createReader(new StringReader(bodyStr))) {
ArrayList<Device> deviceList = new ArrayList<>();
JsonArray deviceArray = jsonReader.readArray();
for (int i = 0; i < deviceArray.size(); i++) {
JsonObject jsonObject = deviceArray.getJsonObject(i);
Device iotHubDevice = new Device(new DeviceParser(jsonObject.toString()));
deviceList.add(iotHubDevice);
}
return deviceList;
}
}
use of com.microsoft.azure.sdk.iot.deps.serializer.DeviceParser in project azure-iot-sdk-java by Azure.
the class RegistryManager method getModulesOnDevice.
/**
* Get modules data by device Id from IotHub
*
* @param deviceId The id of requested device
* @return The module objects 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 List<Module> getModulesOnDevice(String deviceId) throws IOException, IotHubException, JsonSyntaxException {
if (Tools.isNullOrEmpty(deviceId)) {
throw new IllegalArgumentException("deviceId cannot be null or empty");
}
URL url = IotHubConnectionString.getUrlModulesOnDevice(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);
try (JsonReader jsonReader = Json.createReader(new StringReader(bodyStr))) {
List<Module> moduleList = new ArrayList<>();
JsonArray deviceArray = jsonReader.readArray();
for (int i = 0; i < deviceArray.size(); i++) {
JsonObject jsonObject = deviceArray.getJsonObject(i);
Module iotHubModule = new Module(new DeviceParser(jsonObject.toString()));
moduleList.add(iotHubModule);
}
return moduleList;
}
}
use of com.microsoft.azure.sdk.iot.deps.serializer.DeviceParser in project azure-iot-sdk-java by Azure.
the class RegistryManager method addModule.
/**
* Add module using the given Module object
* Return with the response module object from IotHub
*
* @param module The module object to add
* @return The module 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 Module addModule(Module module) throws IOException, IotHubException, JsonSyntaxException {
if (module == null) {
throw new IllegalArgumentException("module cannot be null");
}
String moduleJson = module.toDeviceParser().toJson();
URL url = IotHubConnectionString.getUrlModule(this.hostName, module.getDeviceId(), module.getId());
HttpRequest request = CreateRequest(url, HttpMethod.PUT, moduleJson.getBytes(StandardCharsets.UTF_8));
HttpResponse response = request.send();
IotHubExceptionManager.httpResponseVerification(response);
String bodyStr = new String(response.getBody(), StandardCharsets.UTF_8);
return new Module(new DeviceParser(bodyStr));
}
Aggregations