use of com.microsoft.azure.sdk.iot.service.RegistryManagerOptions in project azure-iot-sdk-java by Azure.
the class AzureSasCredentialSample method runRegistryManagerSample.
private static String runRegistryManagerSample(String iotHubHostName, AzureSasCredential credential) {
// RegistryManager has some configurable options for HTTP read and connect timeouts, as well as for setting proxies.
// For this sample, the default options will be used though.
RegistryManagerOptions options = RegistryManagerOptions.builder().build();
// This constructor takes in your implementation of AzureSasCredential which allows you to use symmetric key based
// authentication without giving the client your connection string.
RegistryManager registryManager = new RegistryManager(iotHubHostName, credential, options);
String deviceId = "my-new-device-" + UUID.randomUUID().toString();
Device newDevice = Device.createDevice(deviceId, AuthenticationType.SAS);
try {
System.out.println("Creating device " + deviceId);
registryManager.addDevice(newDevice);
System.out.println("Successfully created device " + deviceId);
} catch (IOException | IotHubException e) {
System.err.println("Failed to register new device");
e.printStackTrace();
System.exit(-1);
}
return deviceId;
}
use of com.microsoft.azure.sdk.iot.service.RegistryManagerOptions in project azure-iot-sdk-java by Azure.
the class RoleBasedAuthenticationSample method runRegistryManagerSample.
private static String runRegistryManagerSample(String iotHubHostName, TokenCredential credential) {
// RegistryManager has some configurable options for HTTP read and connect timeouts, as well as for setting proxies.
// For this sample, the default options will be used though.
RegistryManagerOptions options = RegistryManagerOptions.builder().build();
// This constructor takes in your implementation of TokenCredential which allows you to use RBAC authentication
// rather than symmetric key based authentication that comes with constructors that take connection strings.
RegistryManager registryManager = new RegistryManager(iotHubHostName, credential, options);
String deviceId = "my-new-device-" + UUID.randomUUID().toString();
Device newDevice = Device.createDevice(deviceId, AuthenticationType.SAS);
try {
System.out.println("Creating device " + deviceId);
registryManager.addDevice(newDevice);
System.out.println("Successfully created device " + deviceId);
} catch (IOException | IotHubException e) {
System.err.println("Failed to register new device");
e.printStackTrace();
System.exit(-1);
}
return deviceId;
}
use of com.microsoft.azure.sdk.iot.service.RegistryManagerOptions in project azure-iot-sdk-java by Azure.
the class RegistryManagerTests method buildRegistryManagerWithAzureSasCredential.
private static RegistryManager buildRegistryManagerWithAzureSasCredential() {
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential azureSasCredential = new AzureSasCredential(serviceSasToken.toString());
RegistryManagerOptions options = RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build();
return new RegistryManager(iotHubConnectionStringObj.getHostName(), azureSasCredential, options);
}
use of com.microsoft.azure.sdk.iot.service.RegistryManagerOptions in project azure-iot-sdk-java by Azure.
the class RegistryManagerTests method deviceLifecycleWithProxy.
@Test
public void deviceLifecycleWithProxy() throws Exception {
Proxy testProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(testProxyHostname, testProxyPort));
ProxyOptions proxyOptions = new ProxyOptions(testProxy);
RegistryManagerOptions registryManagerOptions = RegistryManagerOptions.builder().proxyOptions(proxyOptions).build();
RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance(registryManagerOptions);
// -Create-//
Device deviceAdded = Device.createFromId(testInstance.deviceId, DeviceStatus.Enabled, null);
Tools.addDeviceWithRetry(testInstance.registryManager, deviceAdded);
// -Read-//
Device deviceRetrieved = testInstance.registryManager.getDevice(testInstance.deviceId);
// -Update-//
Device deviceUpdated = testInstance.registryManager.getDevice(testInstance.deviceId);
deviceUpdated.setStatus(DeviceStatus.Disabled);
deviceUpdated = testInstance.registryManager.updateDevice(deviceUpdated);
// -Delete-//
testInstance.registryManager.removeDevice(testInstance.deviceId);
// Assert
assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, deviceAdded.getDeviceId());
assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, deviceRetrieved.getDeviceId());
assertEquals(buildExceptionMessage("", hostName), DeviceStatus.Disabled, deviceUpdated.getStatus());
assertTrue(buildExceptionMessage("", hostName), deviceWasDeletedSuccessfully(testInstance.registryManager, testInstance.deviceId));
}
use of com.microsoft.azure.sdk.iot.service.RegistryManagerOptions in project azure-iot-sdk-java by Azure.
the class Tools method getRegistyManager.
public static RegistryManager getRegistyManager(String iotHubConnectionString) throws IOException {
if (registryManager == null) {
RegistryManagerOptions options = RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build();
registryManager = RegistryManager.createFromConnectionString(iotHubConnectionString, options);
}
return registryManager;
}
Aggregations