diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerServiceImpl.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerServiceImpl.java index e5a794f509..5e109aaf7d 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerServiceImpl.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerServiceImpl.java @@ -62,7 +62,7 @@ public class AndroidSenseManagerServiceImpl implements AndroidSenseManagerServic androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain()); String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint(); if (mqttEndpoint.contains(Constants.LOCALHOST)) { - mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getHostName()); + mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getServerUrl()); } androidConfiguration.setMqttEndpoint(mqttEndpoint); return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(androidConfiguration.toString()) @@ -85,7 +85,7 @@ public class AndroidSenseManagerServiceImpl implements AndroidSenseManagerServic androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain()); String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint(); if (mqttEndpoint.contains(Constants.LOCALHOST)) { - mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getHostName()); + mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getServerUrl()); } androidConfiguration.setMqttEndpoint(mqttEndpoint); return Response.ok(androidConfiguration.toString()).build(); diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ZipUtil.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ZipUtil.java index 9f3dca2690..1cad521204 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ZipUtil.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ZipUtil.java @@ -47,7 +47,7 @@ public class ZipUtil { String iotServerIP; try { - iotServerIP = Utils.getHostName(); + iotServerIP = Utils.getServerUrl(); String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY); Map contextParams = new HashMap<>(); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java index 4bc6a6164c..26aaf2aa7f 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java @@ -55,7 +55,7 @@ public class Utils { public static final String HOST_NAME = "HostName"; private static final Log log = LogFactory.getLog(Utils.class); - public static String getHostName() { + public static String getServerUrl() { String hostName = ServerConfiguration.getInstance().getFirstProperty(HOST_NAME); try { if (hostName == null) { diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/ZipUtil.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/ZipUtil.java index b90c145ad4..6c9fd54b36 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/ZipUtil.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/ZipUtil.java @@ -52,7 +52,7 @@ public class ZipUtil { String iotServerIP; try { - iotServerIP = Utils.getHostName(); + iotServerIP = Utils.getServerUrl(); String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY); String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY); String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java index f1fe40bd90..5beebd415c 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java @@ -68,11 +68,8 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler { final AgentManager agentManager = AgentManager.getInstance(); username = agentManager.getAgentConfigs().getDeviceId(); password = agentManager.getAgentConfigs().getAuthToken(); - resource = agentManager.getAgentConfigs().getDeviceOwner(); - - xmppDeviceJID = username + "@" + server; - xmppAdminJID = "wso2_" + AgentConstants.DEVICE_TYPE + "@" + server; - + xmppDeviceJID = username + "@" + agentManager.getAgentConfigs().getXmppServerName(); + xmppAdminJID = "wso2admin_" + AgentConstants.DEVICE_TYPE + "@" + agentManager.getAgentConfigs().getXmppServerName(); Runnable connect = new Runnable() { public void run() { diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConfiguration.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConfiguration.java index 7a54be78ef..d79e6b029b 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConfiguration.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConfiguration.java @@ -39,6 +39,7 @@ public class AgentConfiguration { private String authToken; private String refreshToken; private int dataPushInterval; + private String xmppServerName; public String getTenantDomain() { return tenantDomain; @@ -159,6 +160,14 @@ public class AgentConfiguration { public void setScepContext(String scepContext) { this.scepContext = scepContext; } + + public String getXmppServerName() { + return xmppServerName; + } + + public void setXmppServerName(String xmppServerName) { + this.xmppServerName = xmppServerName; + } } diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java index 09975cde4a..84267523f8 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java @@ -134,4 +134,6 @@ public class AgentConstants { "select deviceID, temp\n" + "insert into bulbOffStream;"; + + public static final String XMPP_SERVER_NAME_PROPERTY = "xmpp-server-name"; } diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java index 440582c7f7..822327301f 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java @@ -102,6 +102,8 @@ public class AgentUtilOperations { AgentConstants.MQTT_BROKER_EP_PROPERTY)); iotServerConfigs.setXmppServerEndpoint(properties.getProperty( AgentConstants.XMPP_SERVER_EP_PROPERTY)); + iotServerConfigs.setXmppServerName(properties.getProperty( + AgentConstants.XMPP_SERVER_NAME_PROPERTY)); iotServerConfigs.setAuthMethod(properties.getProperty( AgentConstants.AUTH_METHOD_PROPERTY)); iotServerConfigs.setAuthToken(properties.getProperty( @@ -138,6 +140,8 @@ public class AgentUtilOperations { iotServerConfigs.getRefreshToken()); log.info(AgentConstants.LOG_APPENDER + "Data Push Interval: " + iotServerConfigs.getDataPushInterval()); + log.info(AgentConstants.LOG_APPENDER + "XMPP Server Name: " + + iotServerConfigs.getXmppServerName()); } catch (FileNotFoundException ex) { log.error(AgentConstants.LOG_APPENDER + "Unable to find " + propertiesFileName + diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/resources/deviceConfig.properties b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/resources/deviceConfig.properties index 1dc1374b99..4eba166c1a 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/resources/deviceConfig.properties +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/resources/deviceConfig.properties @@ -32,3 +32,4 @@ auth-token=79d68b50ae5f5a06e812889979b3453 refresh-token=8bdda6359dddad218cff3354d5a8cb3b network-interface=en0 push-interval=14 +xmpp-server-name=localhost \ No newline at end of file diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java index b29cd492eb..45d103adcd 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.communication.xmpp import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jivesoftware.smack.packet.Message; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentConfiguration; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentConstants; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentManager; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentUtilOperations; @@ -68,11 +69,8 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler { final AgentManager agentManager = AgentManager.getInstance(); username = agentManager.getAgentConfigs().getDeviceId(); password = agentManager.getAgentConfigs().getAuthToken(); - resource = agentManager.getAgentConfigs().getDeviceOwner(); - - xmppDeviceJID = username + "@" + server; - xmppAdminJID = "wso2_" + AgentConstants.DEVICE_TYPE + "@" + server; - + xmppDeviceJID = username + "@" + agentManager.getAgentConfigs().getXmppServerName(); + xmppAdminJID = "wso2admin_" + AgentConstants.DEVICE_TYPE + "@" + agentManager.getAgentConfigs().getXmppServerName(); Runnable connect = new Runnable() { public void run() { diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java index 68cb58ee80..64b52b8b78 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java @@ -39,6 +39,7 @@ public class AgentConfiguration { private String authToken; private String refreshToken; private int dataPushInterval; + private String xmppServerName; public String getTenantDomain() { return tenantDomain; @@ -159,6 +160,14 @@ public class AgentConfiguration { public void setScepContext(String scepContext) { this.scepContext = scepContext; } + + public String getXmppServerName() { + return xmppServerName; + } + + public void setXmppServerName(String xmppServerName) { + this.xmppServerName = xmppServerName; + } } diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java index 1a9771b8e8..8836aa09c7 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java @@ -77,6 +77,7 @@ public class AgentConstants { public static final String APIM_GATEWAY_EP_PROPERTY = "apim-ep"; public static final String MQTT_BROKER_EP_PROPERTY = "mqtt-ep"; public static final String XMPP_SERVER_EP_PROPERTY = "xmpp-ep"; + public static final String XMPP_SERVER_NAME_PROPERTY = "xmpp-server-name"; public static final String AUTH_METHOD_PROPERTY = "auth-method"; public static final String AUTH_TOKEN_PROPERTY = "auth-token"; public static final String REFRESH_TOKEN_PROPERTY = "refresh-token"; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java index c7eb9d342c..656ce84905 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java @@ -106,6 +106,8 @@ public class AgentUtilOperations { AgentConstants.MQTT_BROKER_EP_PROPERTY)); iotServerConfigs.setXmppServerEndpoint(properties.getProperty( AgentConstants.XMPP_SERVER_EP_PROPERTY)); + iotServerConfigs.setXmppServerName(properties.getProperty( + AgentConstants.XMPP_SERVER_NAME_PROPERTY)); iotServerConfigs.setAuthMethod(properties.getProperty( AgentConstants.AUTH_METHOD_PROPERTY)); iotServerConfigs.setAuthToken(properties.getProperty( @@ -142,6 +144,8 @@ public class AgentUtilOperations { iotServerConfigs.getRefreshToken()); log.info(AgentConstants.LOG_APPENDER + "Data Push Interval: " + iotServerConfigs.getDataPushInterval()); + log.info(AgentConstants.LOG_APPENDER + "XMPP Server Name: " + + iotServerConfigs.getXmppServerName()); } catch (FileNotFoundException ex) { String errorMsg = "[" + propertiesFileName + "] file not found at: " + AgentConstants.PROPERTIES_FILE_PATH; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/resources/deviceConfig.properties b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/resources/deviceConfig.properties index 1dc1374b99..4eba166c1a 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/resources/deviceConfig.properties +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/resources/deviceConfig.properties @@ -32,3 +32,4 @@ auth-token=79d68b50ae5f5a06e812889979b3453 refresh-token=8bdda6359dddad218cff3354d5a8cb3b network-interface=en0 push-interval=14 +xmpp-server-name=localhost \ No newline at end of file diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java index 213cb3fbc8..e4a8aa55f6 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorization import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFirealarmSecurityManager; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.SensorRecord; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.APIUtil; @@ -83,7 +84,8 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo Map dynamicProperties = new HashMap<>(); switch (protocolString) { case XMPP_PROTOCOL: - dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, deviceId); + dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, + deviceId + "@" + XmppConfig.getInstance().getXmppServerName()); dynamicProperties.put(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "CONTROL-REQUEST"); dynamicProperties.put(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY, VirtualFireAlarmConstants.CHAT_PROPERTY_KEY); @@ -91,7 +93,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo dynamicProperties, encryptedMsg); break; default: - String publishTopic = APIUtil.getTenantDomainOftheUser() + "/" + VirtualFireAlarmConstants.DEVICE_TYPE + "/" + deviceId; dynamicProperties.put(VirtualFireAlarmConstants.ADAPTER_TOPIC_PROPERTY, publishTopic); @@ -131,7 +132,8 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo Map dynamicProperties = new HashMap<>(); switch (protocolString) { case XMPP_PROTOCOL: - dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, deviceId); + dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, + deviceId + "@" + XmppConfig.getInstance().getXmppServerName()); dynamicProperties.put(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "POLICTY-REQUEST"); dynamicProperties.put(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY, VirtualFireAlarmConstants.CHAT_PROPERTY_KEY); diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java index 7929873068..4d7fed54cf 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java @@ -53,7 +53,7 @@ public class ZipUtil { String iotServerIP; try { - iotServerIP = Utils.getHostName(); + iotServerIP = Utils.getServerUrl(); String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY); String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY); String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort; @@ -80,7 +80,7 @@ public class ZipUtil { contextParams.put("XMPP_EP", "XMPP:" + xmppEndpoint); contextParams.put("DEVICE_TOKEN", token); contextParams.put("DEVICE_REFRESH_TOKEN", refreshToken); - + contextParams.put("SERVER_NAME", XmppConfig.getInstance().getXmppServerName()); ZipArchive zipFile; zipFile = Utils.getSketchArchive(archivesPath, templateSketchPath, contextParams, deviceName); return zipFile; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java index 64d4e50fd5..693eb3524f 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java @@ -80,11 +80,12 @@ public class VirtualFireAlarmConstants { public static final String IS_ENABLED_KEY = "enabled"; public static final String HOST_KEY = "host"; public static final String PORT_KEY = "port"; - public static final String CONNECTION_PORT = "connection.port"; public static final String ADMIN_USERNAME = "admin.username"; public static final String ADMIN_PASSWORD = "admin.password"; public static final String XMPP_SERVER_PASSWORD = "admin@123456789"; + public static final String SERVER_NAME = "serverName"; + public static final String MQTT_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "mqtt.properties"; public static final String XMPP_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java index 011334538d..875072379b 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java @@ -38,6 +38,8 @@ import org.wso2.carbon.event.output.adapter.core.MessageType; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration; import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException; import org.json.JSONObject; +import org.wso2.carbon.utils.NetworkUtils; + import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; @@ -45,6 +47,7 @@ import javax.sql.DataSource; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.SocketException; import java.security.PublicKey; import java.security.cert.X509Certificate; import java.sql.Connection; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmEventAdapterSubscription.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmEventAdapterSubscription.java index ee3ec6a6ed..25489d9b55 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmEventAdapterSubscription.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmEventAdapterSubscription.java @@ -14,6 +14,9 @@ public class VirtualFirealarmEventAdapterSubscription implements InputEventAdapt if (actualMessage.contains("PUBLISHER")) { float temperature = Float.parseFloat(actualMessage.split(":")[2]); VirtualFireAlarmUtils.publishToDAS(deviceId, temperature); + } else { + float temperature = Float.parseFloat(actualMessage.split(":")[1]); + VirtualFireAlarmUtils.publishToDAS(deviceId, temperature); } } } diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppConfig.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppConfig.java index 3a0eebebbb..12f9b5fcc7 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppConfig.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppConfig.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFireAlarmUtils; import java.io.File; import java.io.IOException; @@ -37,6 +38,7 @@ public class XmppConfig { private String virtualFirealarmAdminUsername; private String virtualFirealarmAdminPassword; private String virtualFirealarmAdminJID; + private String xmppServerName; private static XmppConfig xmppConfig = new XmppConfig(); private static final Log log = LogFactory.getLog(XmppConfig.class); @@ -48,12 +50,13 @@ public class XmppConfig { Properties properties = new Properties(); properties.load(propertyStream); xmppServerIP = properties.getProperty(VirtualFireAlarmConstants.HOST_KEY); + xmppServerName = properties.getProperty(VirtualFireAlarmConstants.SERVER_NAME); xmppServerPort = Integer.parseInt(properties.getProperty(VirtualFireAlarmConstants.PORT_KEY)); isEnabled = Boolean.parseBoolean(properties.getProperty(VirtualFireAlarmConstants.IS_ENABLED_KEY)); xmppUsername = properties.getProperty(VirtualFireAlarmConstants.ADMIN_USERNAME); xmppPassword = properties.getProperty(VirtualFireAlarmConstants.ADMIN_PASSWORD); virtualFirealarmAdminUsername = "wso2admin_" + VirtualFireAlarmConstants.DEVICE_TYPE; - virtualFirealarmAdminJID = virtualFirealarmAdminUsername + "@" + xmppServerIP; + virtualFirealarmAdminJID = virtualFirealarmAdminUsername + "@" + xmppServerName; virtualFirealarmAdminPassword = VirtualFireAlarmConstants.XMPP_SERVER_PASSWORD; } catch (IOException e) { log.error(e); @@ -97,4 +100,7 @@ public class XmppConfig { return virtualFirealarmAdminJID; } + public String getXmppServerName() { + return xmppServerName; + } } diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppServerClient.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppServerClient.java index fccb6c70ad..e2607b71ab 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppServerClient.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppServerClient.java @@ -18,8 +18,6 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jivesoftware.smack.AccountManager; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.XMPPConnection; @@ -36,7 +34,8 @@ public class XmppServerClient { if (xmppAccount != null) { try { ConnectionConfiguration config = new ConnectionConfiguration(XmppConfig.getInstance().getXmppServerIP(), - XmppConfig.getInstance().getXmppServerPort()); + XmppConfig.getInstance().getXmppServerPort(), + "Accounts"); XMPPConnection xmppConnection = new XMPPConnection(config); xmppConnection.connect(); xmppConnection.login(XmppConfig.getInstance().getXmppUsername(), XmppConfig.getInstance().getXmppPassword()); diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppUtil.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppUtil.java index fa6f3c0896..4e60862b84 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppUtil.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppUtil.java @@ -32,10 +32,10 @@ public class XmppUtil { XmppServerClient xmppServerClient = new XmppServerClient(); try { XmppAccount xmppAccount = new XmppAccount(); - xmppAccount.setAccountName(XmppConfig.getInstance().getVirtualFirealarmAdminJID()); + xmppAccount.setAccountName(XmppConfig.getInstance().getVirtualFirealarmAdminUsername()); xmppAccount.setUsername(XmppConfig.getInstance().getVirtualFirealarmAdminUsername()); xmppAccount.setPassword(XmppConfig.getInstance().getVirtualFirealarmAdminPassword()); - xmppAccount.setEmail(""); + xmppAccount.setEmail(XmppConfig.getInstance().getVirtualFirealarmAdminJID()); xmppServerClient.createAccount(xmppAccount); } catch (VirtualFirealarmDeviceMgtPluginException e) { String errorMsg = "An error was encountered whilst trying to create Server XMPP account for device-type - " diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js index 2009b37fcb..4dd97dd238 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js @@ -21,8 +21,7 @@ function onRequest(context) { var deviceType = context.uriParams.deviceType; var deviceId = request.getParameter("id"); var autoCompleteParams = [ - {"name" : "deviceId", "value" : deviceId}, - {"name" : "protocol", "value" : "MQTT"} + {"name" : "deviceId", "value" : deviceId} ]; if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { diff --git a/features/iot-plugins-feature/iot-base-plugin-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/xmpp.properties b/features/iot-plugins-feature/iot-base-plugin-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/xmpp.properties index 23e272d69f..c85a6e6b56 100644 --- a/features/iot-plugins-feature/iot-base-plugin-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/xmpp.properties +++ b/features/iot-plugins-feature/iot-base-plugin-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/xmpp.properties @@ -2,4 +2,5 @@ enabled=false host=localhost port=5222 admin.username=admin -admin.password=admin \ No newline at end of file +admin.password=admin +serverName=localhost \ No newline at end of file diff --git a/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties b/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties index 874f87585e..47a3a73a6c 100644 --- a/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties +++ b/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties @@ -31,5 +31,5 @@ auth-method=token auth-token=${DEVICE_TOKEN} refresh-token=${DEVICE_REFRESH_TOKEN} push-interval=15 - +xmpp-server-name=${SERVER_NAME} diff --git a/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties b/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties index 874f87585e..47a3a73a6c 100644 --- a/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties +++ b/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties @@ -31,5 +31,5 @@ auth-method=token auth-token=${DEVICE_TOKEN} refresh-token=${DEVICE_REFRESH_TOKEN} push-interval=15 - +xmpp-server-name=${SERVER_NAME}