use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class MultiplexingClientTests method registrationsUnwindForClientOfDifferentHostName.
@Test
public void registrationsUnwindForClientOfDifferentHostName() throws Exception {
Device nonMultiplexedDevice = Tools.getTestDevice(iotHubConnectionString, testInstance.protocol, AuthenticationType.SAS, false).getDevice();
String deviceConnectionString = registryManager.getDeviceConnectionString(nonMultiplexedDevice);
// intentionally change the hostname of the device to simulate registering a device with a different hostname
// to a multiplexing client. It shouldn't matter that the hostname itself isn't tied to an actual IoT Hub since
// no network requests should be made before this hostname validation.
String actualHostName = IotHubConnectionString.createConnectionString(iotHubConnectionString).getHostName();
deviceConnectionString = deviceConnectionString.replace(actualHostName, "some-fake-host-name.azure-devices.net");
DeviceClient deviceClientWithDifferentHostName = new DeviceClient(deviceConnectionString, testInstance.protocol);
registrationsUnwindForUnsupportedOperationExceptions(deviceClientWithDifferentHostName);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class MultiplexingClientTests method registrationsUnwindForDifferentProtocolClient.
@Test
public void registrationsUnwindForDifferentProtocolClient() throws Exception {
// Protocol for the new client is AMQPS if the test parameters are for AMQPS_WS, and vice versa. MultiplexingClient
// should throw an exception since this new client's protocol doesn't match, even though both AMQPS and AMQPS_WS are valid
// protocols
IotHubClientProtocol protocol = testInstance.protocol == IotHubClientProtocol.AMQPS ? IotHubClientProtocol.AMQPS_WS : IotHubClientProtocol.AMQPS;
Device newDevice = Tools.getTestDevice(iotHubConnectionString, protocol, AuthenticationType.SAS, false).getDevice();
String deviceConnectionString = registryManager.getDeviceConnectionString(newDevice);
DeviceClient differentProtocolDeviceClient = new DeviceClient(deviceConnectionString, protocol);
registrationsUnwindForUnsupportedOperationExceptions(differentProtocolDeviceClient);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class MultiplexingClientTests method invokeMethodSucceed.
@Test
@StandardTierHubOnlyTest
public void invokeMethodSucceed() throws Exception {
testInstance.setup(DEVICE_MULTIPLEX_COUNT);
testInstance.multiplexingClient.open();
DeviceMethod deviceMethodServiceClient = DeviceMethod.createFromConnectionString(iotHubConnectionString);
for (int i = 0; i < DEVICE_MULTIPLEX_COUNT; i++) {
// Subscribe to methods on the multiplexed client
String expectedMethodName = UUID.randomUUID().toString();
DeviceMethodCallback deviceMethodCallback = new DeviceMethodCallback(expectedMethodName);
subscribeToDeviceMethod(testInstance.deviceClientArray.get(i), deviceMethodCallback);
testDeviceMethod(deviceMethodServiceClient, testInstance.deviceIdentityArray.get(i).getDeviceId(), expectedMethodName, deviceMethodCallback);
}
testInstance.multiplexingClient.close();
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class Tools method addModules.
private static void addModules(Iterable<Module> modules, String connectionString) throws IOException, IotHubException {
if (modules == null) {
throw new IllegalArgumentException("modules cannot be null");
}
IotHubConnectionString iotHubConnectionString = IotHubConnectionString.createConnectionString(connectionString);
URL url = getBulkDeviceAddUrl(iotHubConnectionString);
List<ExportImportDeviceParser> parsers = new ArrayList<>();
for (Module module : modules) {
ExportImportDeviceParser exportImportDevice = new ExportImportDeviceParser();
exportImportDevice.setId(module.getDeviceId());
exportImportDevice.setModuleId(module.getId());
AuthenticationParser authenticationParser = new AuthenticationParser();
if (module.getAuthenticationType() == AuthenticationType.SAS) {
authenticationParser.setType(AuthenticationTypeParser.SAS);
authenticationParser.setSymmetricKey(new SymmetricKeyParser(module.getSymmetricKey().getPrimaryKey(), module.getSymmetricKey().getSecondaryKey()));
} else {
authenticationParser.setType(AuthenticationTypeParser.SELF_SIGNED);
authenticationParser.setThumbprint(new X509ThumbprintParser(module.getPrimaryThumbprint(), module.getSecondaryThumbprint()));
}
exportImportDevice.setAuthentication(authenticationParser);
exportImportDevice.setImportMode(IMPORT_MODE_CREATE);
parsers.add(exportImportDevice);
}
ExportImportDevicesParser body = new ExportImportDevicesParser();
body.setExportImportDevices(parsers);
bulkRegistryOperation(body.toJson(), url, connectionString);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class Tools method getX509TestModule.
private static TestModuleIdentity getX509TestModule(String iotHubConnectionString, IotHubClientProtocol protocol, boolean needCleanTwin) throws URISyntaxException, IOException, IotHubException, InterruptedException, ModuleClientException, GeneralSecurityException {
// remove an identity from the queue.
synchronized (testX509ModuleQueueLock) {
TestModuleIdentity testModuleIdentity;
if (!needCleanTwin && testX509ModuleWithTwinQueue.size() > 0) {
log.debug("Acquiring test module from testX509ModuleWithTwinQueue");
testModuleIdentity = testX509ModuleWithTwinQueue.remove();
} else {
if (testX509ModuleQueue.size() < 1) {
// No cached modules to return, so create a new set of modules to cache, and return one of the newly created modules
log.debug("Proactively adding another {} modules to the SAS test module queue", PROACTIVE_TEST_DEVICE_REGISRATION_COUNT);
List<Device> devices = new ArrayList<>();
List<Module> modulesToAdd = new ArrayList<>();
for (int i = 0; i < PROACTIVE_TEST_DEVICE_REGISRATION_COUNT; i++) {
TestDeviceIdentity testDeviceIdentity = getTestDevice(iotHubConnectionString, protocol, AuthenticationType.SELF_SIGNED, needCleanTwin);
devices.add(testDeviceIdentity.device);
Module module = Module.createModule(testDeviceIdentity.device.getDeviceId(), "test-module-" + UUID.randomUUID(), AuthenticationType.SELF_SIGNED);
String x509Thumbprint = IntegrationTest.x509CertificateGenerator.getX509Thumbprint();
module.setThumbprintFinal(x509Thumbprint, x509Thumbprint);
modulesToAdd.add(module);
}
addModules(modulesToAdd, iotHubConnectionString);
for (int i = 0; i < PROACTIVE_TEST_DEVICE_REGISRATION_COUNT; i++) {
testX509ModuleQueue.add(new TestModuleIdentity(null, devices.get(i), modulesToAdd.get(i)));
}
}
log.debug("Acquiring test module from testX509ModuleQueue");
testModuleIdentity = testX509ModuleQueue.remove();
}
SSLContext sslContext = SSLContextBuilder.buildSSLContext(IntegrationTest.x509CertificateGenerator.getPublicCertificate(), IntegrationTest.x509CertificateGenerator.getPrivateKey());
ModuleClient moduleClient = new ModuleClient(DeviceConnectionString.get(iotHubConnectionString, testModuleIdentity.device, testModuleIdentity.module), protocol, sslContext);
testModuleIdentity.setModuleClient(moduleClient);
return testModuleIdentity;
}
}
Aggregations