Search in sources :

Example 1 with RegistryManagerOptions

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;
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) RegistryManagerOptions(com.microsoft.azure.sdk.iot.service.RegistryManagerOptions) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 2 with RegistryManagerOptions

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;
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) RegistryManagerOptions(com.microsoft.azure.sdk.iot.service.RegistryManagerOptions) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 3 with RegistryManagerOptions

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);
}
Also used : IotHubServiceSasToken(com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken) AzureSasCredential(com.azure.core.credential.AzureSasCredential) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) RegistryManagerOptions(com.microsoft.azure.sdk.iot.service.RegistryManagerOptions)

Example 4 with RegistryManagerOptions

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));
}
Also used : Proxy(java.net.Proxy) ProxyOptions(com.microsoft.azure.sdk.iot.service.ProxyOptions) InetSocketAddress(java.net.InetSocketAddress) Device(com.microsoft.azure.sdk.iot.service.Device) RegistryManagerOptions(com.microsoft.azure.sdk.iot.service.RegistryManagerOptions) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test)

Example 5 with RegistryManagerOptions

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;
}
Also used : RegistryManagerOptions(com.microsoft.azure.sdk.iot.service.RegistryManagerOptions)

Aggregations

RegistryManagerOptions (com.microsoft.azure.sdk.iot.service.RegistryManagerOptions)5 Device (com.microsoft.azure.sdk.iot.service.Device)3 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)3 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)2 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)2 IOException (java.io.IOException)2 AzureSasCredential (com.azure.core.credential.AzureSasCredential)1 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)1 ProxyOptions (com.microsoft.azure.sdk.iot.service.ProxyOptions)1 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)1 InetSocketAddress (java.net.InetSocketAddress)1 Proxy (java.net.Proxy)1 Test (org.junit.Test)1 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)1 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)1 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)1 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)1