use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinClientOptions in project azure-iot-sdk-java by Azure.
the class GetTwinTests method testGetDeviceTwinWithProxy.
@Test
@StandardTierHubOnlyTest
public void testGetDeviceTwinWithProxy() throws IOException, InterruptedException, IotHubException, GeneralSecurityException, ModuleClientException, URISyntaxException {
if (testInstance.protocol != IotHubClientProtocol.MQTT || testInstance.authenticationType != AuthenticationType.SAS || testInstance.clientType != ClientType.DEVICE_CLIENT) {
// when the device is using MQTT with SAS auth
return;
}
super.setUpNewDeviceAndModule();
String testProxyHostname = "127.0.0.1";
int testProxyPort = 8892;
HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(testProxyPort).start();
try {
Proxy serviceSideProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(testProxyHostname, testProxyPort));
ProxyOptions proxyOptions = new ProxyOptions(serviceSideProxy);
DeviceTwinClientOptions options = DeviceTwinClientOptions.builder().proxyOptions(proxyOptions).build();
testInstance.twinServiceClient = DeviceTwin.createFromConnectionString(iotHubConnectionString, options);
super.testGetDeviceTwin();
} finally {
proxyServer.stop();
}
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinClientOptions in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method testOptionsDefaults.
@Test
public void testOptionsDefaults() {
DeviceTwinClientOptions options = DeviceTwinClientOptions.builder().build();
assertEquals((int) Deencapsulation.getField(DeviceTwinClientOptions.class, "DEFAULT_HTTP_READ_TIMEOUT_MS"), options.getHttpReadTimeout());
assertEquals((int) Deencapsulation.getField(DeviceTwinClientOptions.class, "DEFAULT_HTTP_CONNECT_TIMEOUT_MS"), options.getHttpConnectTimeout());
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinClientOptions in project azure-iot-sdk-java by Azure.
the class DeviceTwinCommon method buildDeviceTwinClientWithAzureSasCredential.
protected static DeviceTwin buildDeviceTwinClientWithAzureSasCredential() {
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential azureSasCredential = new AzureSasCredential(serviceSasToken.toString());
DeviceTwinClientOptions options = DeviceTwinClientOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build();
return new DeviceTwin(iotHubConnectionStringObj.getHostName(), azureSasCredential, options);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinClientOptions in project azure-iot-sdk-java by Azure.
the class Tools method buildDeviceTwinClientWithTokenCredential.
public static DeviceTwin buildDeviceTwinClientWithTokenCredential() {
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
TokenCredential tokenCredential = buildTokenCredentialFromEnvironment();
DeviceTwinClientOptions options = DeviceTwinClientOptions.builder().build();
return new DeviceTwin(iotHubConnectionStringObj.getHostName(), tokenCredential, options);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinClientOptions in project azure-iot-sdk-java by Azure.
the class AzureSasCredentialSample method runTwinClientSample.
private static void runTwinClientSample(String iotHubHostName, AzureSasCredential credential, String deviceId) {
// DeviceTwin 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.
DeviceTwinClientOptions options = DeviceTwinClientOptions.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.
DeviceTwin twinClient = new DeviceTwin(iotHubHostName, credential, options);
DeviceTwinDevice newDeviceTwin = new DeviceTwinDevice(deviceId);
try {
System.out.println("Getting twin for device " + deviceId);
twinClient.getTwin(newDeviceTwin);
} catch (IotHubException | IOException e) {
System.err.println("Failed to get twin for device " + deviceId);
e.printStackTrace();
System.exit(-1);
}
System.out.println("Successfully got the twin for the new device");
System.out.println("Device Id: " + newDeviceTwin.getDeviceId());
System.out.println("ETag: " + newDeviceTwin.getETag());
}
Aggregations