Search in sources :

Example 1 with ReadSettingsHelper.getString

use of org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString in project open-smart-grid-platform by OSGP.

the class MqttDeviceSteps method startPublishingClient.

private void startPublishingClient(final String host, final int port, final String topic, final String payload, final Map<String, String> parameters) {
    final SimulatorSpec spec = new SimulatorSpec(host, port);
    spec.setStartupPauseMillis(2000);
    final Message message = new Message(topic, payload, 10000);
    final Message[] messages = { message };
    spec.setMessages(messages);
    MqttClientSslConfig mqttClientSslConfig = null;
    final boolean mqttSslEnabled = ReadSettingsHelper.getBoolean(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_ENABLED, PlatformDistributionAutomationDefaults.MQTT_SSL_ENABLED);
    if (mqttSslEnabled) {
        final String truststoreLocation = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_LOCATION, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_LOCATION);
        final String truststorePassword = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_PASSWORD, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_PASSWORD);
        final String truststoreType = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_TYPE, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_TYPE);
        final ResourceLoader resourceLoader = new DefaultResourceLoader();
        final Resource trustStoreResource = resourceLoader.getResource(truststoreLocation);
        mqttClientSslConfig = MqttClientSslConfigFactory.getMqttClientSslConfig(trustStoreResource, truststorePassword, truststoreType);
    }
    final SimulatorSpecPublishingClient publishingClient = new SimulatorSpecPublishingClient(spec, mqttClientSslConfig);
    publishingClient.start();
}
Also used : MqttClientSslConfig(com.hivemq.client.mqtt.MqttClientSslConfig) SimulatorSpecPublishingClient(org.opensmartgridplatform.simulator.protocol.mqtt.SimulatorSpecPublishingClient) ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Message(org.opensmartgridplatform.simulator.protocol.mqtt.spec.Message) Resource(org.springframework.core.io.Resource) SimulatorSpec(org.opensmartgridplatform.simulator.protocol.mqtt.spec.SimulatorSpec) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Aggregations

MqttClientSslConfig (com.hivemq.client.mqtt.MqttClientSslConfig)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 SimulatorSpecPublishingClient (org.opensmartgridplatform.simulator.protocol.mqtt.SimulatorSpecPublishingClient)1 Message (org.opensmartgridplatform.simulator.protocol.mqtt.spec.Message)1 SimulatorSpec (org.opensmartgridplatform.simulator.protocol.mqtt.spec.SimulatorSpec)1 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)1 Resource (org.springframework.core.io.Resource)1 ResourceLoader (org.springframework.core.io.ResourceLoader)1