diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_publisher/android_sense_publisher.xml b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_publisher/android_sense_publisher.xml index 1e16ab1789..fcb3aadf18 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_publisher/android_sense_publisher.xml +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_publisher/android_sense_publisher.xml @@ -20,6 +20,6 @@ - + diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_receiver/android_sense_receiver.xml b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_receiver/android_sense_receiver.xml index 4ba6b5ff92..48bb1f9194 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_receiver/android_sense_receiver.xml +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_receiver/android_sense_receiver.xml @@ -23,7 +23,7 @@ admin org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTContentValidator default - https://localhost:${carbon.https.port}/dynamic-client-web/register + https://${iot.core.host}:${iot.core.https.port}/dynamic-client-web/register tcp://${mqtt.broker.host}:${mqtt.broker.port} true diff --git a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Arduino/arduino_receiver/arduino_receiver.xml b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Arduino/arduino_receiver/arduino_receiver.xml index 8edadbdf6f..a12cae6801 100644 --- a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Arduino/arduino_receiver/arduino_receiver.xml +++ b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Arduino/arduino_receiver/arduino_receiver.xml @@ -24,7 +24,7 @@ default all 100 - https://localhost:${carbon.https.port}/services/OAuth2TokenValidationService + https://localhost:${dcr.endpoint.port}/services/OAuth2TokenValidationService admin diff --git a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/raspberrypi/raspberrypi_receiver/raspberrypi_receiver.xml b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/raspberrypi/raspberrypi_receiver/raspberrypi_receiver.xml index 65846c0b43..60d130514e 100644 --- a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/raspberrypi/raspberrypi_receiver/raspberrypi_receiver.xml +++ b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/raspberrypi/raspberrypi_receiver/raspberrypi_receiver.xml @@ -22,7 +22,7 @@ admin org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTContentValidator default - https://localhost:${carbon.https.port}/dynamic-client-web/register + https://${iot.core.host}:${iot.core.https.port}/dynamic-client-web/register tcp://${mqtt.broker.host}:${mqtt.broker.port} true diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTBrokerConnectionConfiguration.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTBrokerConnectionConfiguration.java index 55a4bf0570..0724937799 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTBrokerConnectionConfiguration.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTBrokerConnectionConfiguration.java @@ -17,6 +17,8 @@ */ package org.wso2.carbon.device.mgt.input.adapter.mqtt.util; +import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException; + /** * This holds the configurations related to MQTT Broker. */ @@ -65,7 +67,7 @@ public class MQTTBrokerConnectionConfiguration { public MQTTBrokerConnectionConfiguration(String brokerUrl, String brokerUsername, String brokerScopes, String dcrUrl, String cleanSession, int keepAlive, - String contentValidatorClassName, String contentTransformerClassName) { + String contentValidatorClassName, String contentTransformerClassName) throws InputEventAdapterException { this.brokerUsername = brokerUsername; this.brokerScopes = brokerScopes; if (brokerScopes == null) { diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/PropertyUtils.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/PropertyUtils.java index 5cede58f6f..91a512b79d 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/PropertyUtils.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/PropertyUtils.java @@ -18,37 +18,28 @@ package org.wso2.carbon.device.mgt.input.adapter.mqtt.util; -import org.wso2.carbon.base.ServerConfiguration; -import org.wso2.carbon.core.util.Utils; +import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException; -public class PropertyUtils { - private static final String MQTT_PORT = "\\$\\{mqtt.broker.port\\}"; - private static final String MQTT_BROKER_HOST = "\\$\\{mqtt.broker.host\\}"; - private static final String CARBON_CONFIG_PORT_OFFSET = "Ports.Offset"; - private static final String DEFAULT_CARBON_LOCAL_IP_PROPERTY = "carbon.local.ip"; - private static final int CARBON_DEFAULT_PORT_OFFSET = 0; - private static final int DEFAULT_MQTT_PORT = 1886; +import java.util.regex.Matcher; +import java.util.regex.Pattern; - //This method is only used if the mb features are within DAS. - public static String replaceMqttProperty (String urlWithPlaceholders) { - urlWithPlaceholders = Utils.replaceSystemProperty(urlWithPlaceholders); - urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_PORT, "" + (DEFAULT_MQTT_PORT + getPortOffset())); - urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_BROKER_HOST, System.getProperty( - DEFAULT_CARBON_LOCAL_IP_PROPERTY, "localhost")); - return urlWithPlaceholders; - } +class PropertyUtils { - private static int getPortOffset() { - ServerConfiguration carbonConfig = ServerConfiguration.getInstance(); - String portOffset = System.getProperty("portOffset", carbonConfig.getFirstProperty(CARBON_CONFIG_PORT_OFFSET)); - try { - if (portOffset != null) { - return Integer.parseInt(portOffset.trim()); + //This method is only used if the mb features are within DAS. + static String replaceMqttProperty(String urlWithPlaceholders) throws InputEventAdapterException { + String regex = "\\$\\{(.*?)\\}"; + Pattern pattern = Pattern.compile(regex); + Matcher matchPattern = pattern.matcher(urlWithPlaceholders); + while (matchPattern.find()) { + String sysPropertyName = matchPattern.group(1); + String sysPropertyValue = System.getProperty(sysPropertyName); + if (sysPropertyValue != null && !sysPropertyName.isEmpty()) { + urlWithPlaceholders = urlWithPlaceholders.replaceAll("\\$\\{(" + sysPropertyName + ")\\}", sysPropertyValue); } else { - return CARBON_DEFAULT_PORT_OFFSET; + throw new InputEventAdapterException("System property - " + sysPropertyName + + " is not defined, hence cannot resolve : " + urlWithPlaceholders); } - } catch (NumberFormatException e) { - return CARBON_DEFAULT_PORT_OFFSET; } + return urlWithPlaceholders; } }