From 060c2dd079a367adaad9e6135a3abc2a6738f1d1 Mon Sep 17 00:00:00 2001 From: Shabirmean Date: Wed, 23 Dec 2015 11:50:23 +0530 Subject: [PATCH] Changes to minor errors in the VirtualFireAlarmService --- .gitignore | 5 +- .../service/VirtualFireAlarmService.java | 12 ++-- .../VirtualFireAlarmXMPPConnector.java | 57 ++++++++++--------- .../service/VirtualFireAlarmService.java | 5 -- 4 files changed, 39 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 717de4fa5a..c469f7d058 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,7 @@ target hs_err_pid* # Ignore generated capps -carbonapps \ No newline at end of file +carbonapps + +# Ignore generated device-type DBs +*.h2.db \ No newline at end of file diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java index c505e1c36f..c9c0056548 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java @@ -121,8 +121,8 @@ public class VirtualFireAlarmService { final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) { this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector; - if (MqttConfig.getInstance().isEnabled()) { - Runnable mqttStarter = new Runnable() { + if (XmppConfig.getInstance().isEnabled()) { + Runnable xmppStarter = new Runnable() { @Override public void run() { virtualFireAlarmXMPPConnector.initConnector(); @@ -130,9 +130,9 @@ public class VirtualFireAlarmService { } }; - Thread mqttStarterThread = new Thread(mqttStarter); - mqttStarterThread.setDaemon(true); - mqttStarterThread.start(); + Thread xmppStarterThread = new Thread(xmppStarter); + xmppStarterThread.setDaemon(true); + xmppStarterThread.start(); } else { log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started."); } @@ -144,7 +144,7 @@ public class VirtualFireAlarmService { public void setVirtualFireAlarmMQTTConnector( final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) { this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector; - if (XmppConfig.getInstance().isEnabled()) { + if (MqttConfig.getInstance().isEnabled()) { virtualFireAlarmMQTTConnector.connect(); } else { log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started."); diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java index b5ddf93dfd..ef74390d14 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java @@ -71,42 +71,43 @@ public class VirtualFireAlarmXMPPConnector extends XMPPTransportHandler { } public void createXMPPAccountForDeviceType() { - boolean accountExists = false; + boolean accountExists; XmppServerClient xmppServerClient = new XmppServerClient(); xmppServerClient.initControlQueue(); try { accountExists = xmppServerClient.doesXMPPUserAccountExist(xmppVFireAlarmAdminUsername); - } catch (DeviceControllerException e) { - String errorMsg = "An error was encountered whilst trying to check whether Server XMPP account exists " + - "for device-type - " + VirtualFireAlarmConstants.DEVICE_TYPE; - log.error(errorMsg, e); - } - if (!accountExists) { - XmppAccount xmppAccount = new XmppAccount(); - - xmppAccount.setAccountName(xmppVFireAlarmAdminUsername); - xmppAccount.setUsername(xmppVFireAlarmAdminUsername); - xmppAccount.setPassword(V_FIREALARM_XMPP_PASSWORD); - xmppAccount.setEmail(""); - - try { - boolean xmppCreated = xmppServerClient.createXMPPAccount(xmppAccount); - if (!xmppCreated) { - log.warn("Server XMPP Account was not created for device-type - " + - VirtualFireAlarmConstants.DEVICE_TYPE + - ". Check whether XMPP is enabled in \"devicemgt-config.xml\" & restart."); - } else { - log.info("Server XMPP Account [" + xmppVFireAlarmAdminUsername + - "] was not created for device-type - " + VirtualFireAlarmConstants.DEVICE_TYPE); + if (!accountExists) { + XmppAccount xmppAccount = new XmppAccount(); + + xmppAccount.setAccountName(xmppVFireAlarmAdminUsername); + xmppAccount.setUsername(xmppVFireAlarmAdminUsername); + xmppAccount.setPassword(V_FIREALARM_XMPP_PASSWORD); + xmppAccount.setEmail(""); + + try { + boolean xmppCreated = xmppServerClient.createXMPPAccount(xmppAccount); + if (!xmppCreated) { + log.warn("Server XMPP Account was not created for device-type - " + + VirtualFireAlarmConstants.DEVICE_TYPE + + ". Check whether XMPP is enabled in \"devicemgt-config.xml\" & restart."); + } else { + log.info("Server XMPP Account [" + xmppVFireAlarmAdminUsername + + "] was not created for device-type - " + VirtualFireAlarmConstants.DEVICE_TYPE); + } + } catch (DeviceControllerException e) { + String errorMsg = + "An error was encountered whilst trying to create Server XMPP account for device-type - " + + VirtualFireAlarmConstants.DEVICE_TYPE; + log.error(errorMsg, e); } - } catch (DeviceControllerException e) { - String errorMsg = - "An error was encountered whilst trying to create Server XMPP account for device-type - " - + VirtualFireAlarmConstants.DEVICE_TYPE; - log.error(errorMsg, e); } + + } catch (DeviceControllerException e) { + String errorMsg = "An error was encountered whilst trying to check whether Server XMPP account exists " + + "for device-type - " + VirtualFireAlarmConstants.DEVICE_TYPE + ".\n Check [devicemgt-config.xml]"; + log.error(errorMsg, e); } } diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java index 1f08a15dff..e340b63c5d 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java @@ -95,14 +95,9 @@ public class VirtualFireAlarmService { @Context //injected response proxy supporting multiple thread private HttpServletResponse response; - public static final String XMPP_PROTOCOL = "XMPP"; - public static final String HTTP_PROTOCOL = "HTTP"; - public static final String MQTT_PROTOCOL = "MQTT"; - private VerificationManager verificationManager; private VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector; private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector; - private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); /** * @param verificationManager