diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/ArduinoService.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/ArduinoService.java index 88b562f948..7a51ac6dd7 100644 --- a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/ArduinoService.java +++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/ArduinoService.java @@ -37,6 +37,7 @@ import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants; import org.wso2.carbon.device.mgt.iot.arduino.service.dto.DeviceJSON; import org.wso2.carbon.device.mgt.iot.arduino.service.transport.ArduinoMQTTSubscriber; import org.wso2.carbon.device.mgt.iot.arduino.service.util.ArduinoServiceUtils; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.exception.AccessTokenException; import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; @@ -99,17 +100,21 @@ public class ArduinoService { final ArduinoMQTTSubscriber arduinoMQTTSubscriber) { this.arduinoMQTTSubscriber = arduinoMQTTSubscriber; - Runnable xmppStarter = new Runnable() { - @Override - public void run() { - arduinoMQTTSubscriber.initConnector(); - arduinoMQTTSubscriber.connectAndSubscribe(); - } - }; + if (MqttConfig.getInstance().isEnabled()) { + Runnable xmppStarter = new Runnable() { + @Override + public void run() { + arduinoMQTTSubscriber.initConnector(); + arduinoMQTTSubscriber.connectAndSubscribe(); + } + }; - Thread xmppStarterThread = new Thread(xmppStarter); - xmppStarterThread.setDaemon(true); - xmppStarterThread.start(); + Thread xmppStarterThread = new Thread(xmppStarter); + xmppStarterThread.setDaemon(true); + xmppStarterThread.start(); + } else { + log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, ArduinoMQTTSubscriber not started."); + } } /** diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayControllerService.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayControllerService.java index 194f835f38..120a89b0a7 100644 --- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayControllerService.java +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayControllerService.java @@ -24,6 +24,7 @@ import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.device.DeviceType; import org.wso2.carbon.apimgt.annotations.device.feature.Feature; import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.exception.DigitalDisplayException; import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport.CommunicationHandlerException; import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.util.DigitalDisplayMqttCommunicationHandler; @@ -54,9 +55,12 @@ public class DigitalDisplayControllerService { public void setDigitalDisplayMqttCommunicationHandler( DigitalDisplayMqttCommunicationHandler digitalDisplayMqttCommunicationHandler) { DigitalDisplayControllerService.digitalDisplayMqttCommunicationHandler = digitalDisplayMqttCommunicationHandler; - - digitalDisplayMqttCommunicationHandler.connect(); - + if (MqttConfig.getInstance().isEnabled()) { + digitalDisplayMqttCommunicationHandler.connect(); + } else { + log.warn("MQTT disabled in 'devicemgt-config.xml'. " + + "Hence, DigitalDisplayMqttCommunicationHandler not started."); + } } /** diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/util/DigitalDisplayMqttCommunicationHandler.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/util/DigitalDisplayMqttCommunicationHandler.java index 3c545a58fb..66529a9e0d 100644 --- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/util/DigitalDisplayMqttCommunicationHandler.java +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/util/DigitalDisplayMqttCommunicationHandler.java @@ -15,10 +15,6 @@ import java.util.UUID; import java.util.concurrent.ScheduledFuture; -/** - * Created by nuwan on 11/16/15. - */ - public class DigitalDisplayMqttCommunicationHandler extends MQTTCommunicationHandler { private static Log log = LogFactory.getLog(DigitalDisplayMqttCommunicationHandler.class); diff --git a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneRealTimeService.java b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneRealTimeService.java index c70649511d..5c39364b0e 100644 --- a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneRealTimeService.java +++ b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneRealTimeService.java @@ -19,6 +19,8 @@ package org.wso2.carbon.device.mgt.iot.droneanalyzer.service; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; +import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants; import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.transport.DroneAnalyzerXMPPConnector; import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.trasformer.MessageTransformer; @@ -34,10 +36,15 @@ public class DroneRealTimeService { private MessageTransformer messageController; private DroneAnalyzerXMPPConnector xmppConnector; - public DroneRealTimeService(){ + public DroneRealTimeService() { messageController = new MessageTransformer(); xmppConnector = new DroneAnalyzerXMPPConnector(messageController); - xmppConnector.connectLoginAndSetFilterOnReceiver(); + + if (XmppConfig.getInstance().isEnabled()){ + xmppConnector.connectLoginAndSetFilterOnReceiver(); + } else { + log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started."); + } } diff --git a/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java b/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java index edabd1b9c3..f87698f5c9 100644 --- a/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java +++ b/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java @@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.iot.DeviceManagement; import org.wso2.carbon.device.mgt.iot.DeviceValidator; import org.wso2.carbon.device.mgt.iot.apimgt.AccessTokenInfo; import org.wso2.carbon.device.mgt.iot.apimgt.TokenClient; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient; @@ -63,8 +64,8 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -@API( name="raspberrypi", version="1.0.0", context="/raspberrypi") -@DeviceType( value = "raspberrypi") +@API(name = "raspberrypi", version = "1.0.0", context = "/raspberrypi") +@DeviceType(value = "raspberrypi") public class RaspberryPiService { private static Log log = LogFactory.getLog(RaspberryPiService.class); @@ -88,17 +89,21 @@ public class RaspberryPiService { final RaspberryPiMQTTSubscriber raspberryPiMQTTSubscriber) { this.raspberryPiMQTTSubscriber = raspberryPiMQTTSubscriber; - Runnable xmppStarter = new Runnable() { - @Override - public void run() { - raspberryPiMQTTSubscriber.initConnector(); - raspberryPiMQTTSubscriber.connectAndSubscribe(); - } - }; + if (MqttConfig.getInstance().isEnabled()) { + Runnable xmppStarter = new Runnable() { + @Override + public void run() { + raspberryPiMQTTSubscriber.initConnector(); + raspberryPiMQTTSubscriber.connectAndSubscribe(); + } + }; - Thread xmppStarterThread = new Thread(xmppStarter); - xmppStarterThread.setDaemon(true); - xmppStarterThread.start(); + Thread xmppStarterThread = new Thread(xmppStarter); + xmppStarterThread.setDaemon(true); + xmppStarterThread.start(); + } else { + log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started."); + } } /** diff --git a/components/device-mgt-iot-virtualfirealarm/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/device-mgt-iot-virtualfirealarm/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 ed849d364e..2864b759eb 100644 --- a/components/device-mgt-iot-virtualfirealarm/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/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java @@ -71,7 +71,7 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler { resource = agentManager.getAgentConfigs().getDeviceOwner(); xmppDeviceJID = username + "@" + server; - xmppAdminJID = AgentConstants.XMPP_ADMIN_ACCOUNT_UNAME + "@" + server; + xmppAdminJID = agentManager.getAgentConfigs().getServerName() + "_" + AgentConstants.DEVICE_TYPE + "@" + server; Runnable connect = new Runnable() { @@ -187,19 +187,26 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler { Runnable pushDataRunnable = new Runnable() { @Override public void run() { - int currentTemperature = agentManager.getTemperature(); - String payLoad = AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature; - Message xmppMessage = new Message(); - xmppMessage.setTo(xmppAdminJID); - xmppMessage.setSubject("PUBLISHER"); - xmppMessage.setBody(payLoad); - xmppMessage.setType(Message.Type.chat); - - sendXMPPMessage(xmppAdminJID, xmppMessage); - log.info(AgentConstants.LOG_APPENDER + "Message: '" + xmppMessage.getBody() + - "' sent to XMPP JID [" + xmppAdminJID + "] under subject [" + - xmppMessage.getSubject() + "]"); + + try { + int currentTemperature = agentManager.getTemperature(); + + String message = AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature; + String payLoad = AgentUtilOperations.prepareSecurePayLoad(message); + + xmppMessage.setTo(xmppAdminJID); + xmppMessage.setSubject("PUBLISHER"); + xmppMessage.setBody(payLoad); + xmppMessage.setType(Message.Type.chat); + + sendXMPPMessage(xmppAdminJID, xmppMessage); + log.info(AgentConstants.LOG_APPENDER + "Message: '" + message + "' sent to XMPP JID - " + + "[" + xmppAdminJID + "] under subject [" + xmppMessage.getSubject() + "]."); + } catch (AgentCoreOperationException e) { + log.warn(AgentConstants.LOG_APPENDER + "Preparing Secure payload failed for XMPP JID - " + + "[" + xmppAdminJID + "] with subject - [" + xmppMessage.getSubject() + "]."); + } } }; diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.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.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java index 9c968edf84..26fd7d313b 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.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.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java @@ -36,6 +36,7 @@ import org.wso2.carbon.device.mgt.iot.DeviceManagement; import org.wso2.carbon.device.mgt.iot.DeviceValidator; import org.wso2.carbon.device.mgt.iot.apimgt.AccessTokenInfo; import org.wso2.carbon.device.mgt.iot.apimgt.TokenClient; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient; @@ -83,8 +84,8 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -@API( name="virtual_firealarm", version="1.0.0", context="/virtual_firealarm") -@DeviceType( value = "virtual_firealarm") +@API(name = "virtual_firealarm", version = "1.0.0", context = "/virtual_firealarm") +@DeviceType(value = "virtual_firealarm") public class VirtualFireAlarmService { private static Log log = LogFactory.getLog(VirtualFireAlarmService.class); @@ -104,9 +105,7 @@ public class VirtualFireAlarmService { private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector; private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); - /** - * * @param verificationManager */ public void setVerificationManager( @@ -116,48 +115,43 @@ public class VirtualFireAlarmService { } /** - * * @param virtualFireAlarmXMPPConnector */ public void setVirtualFireAlarmXMPPConnector( final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) { this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector; - Runnable mqttStarter = new Runnable() { - @Override - public void run() { - virtualFireAlarmXMPPConnector.initConnector(); - virtualFireAlarmXMPPConnector.connect(); - } - }; + if (MqttConfig.getInstance().isEnabled()) { + Runnable mqttStarter = new Runnable() { + @Override + public void run() { + virtualFireAlarmXMPPConnector.initConnector(); + virtualFireAlarmXMPPConnector.connect(); + } + }; - Thread mqttStarterThread = new Thread(mqttStarter); - mqttStarterThread.setDaemon(true); - mqttStarterThread.start(); + Thread mqttStarterThread = new Thread(mqttStarter); + mqttStarterThread.setDaemon(true); + mqttStarterThread.start(); + } else { + log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started."); + } } /** - * * @param virtualFireAlarmMQTTConnector */ public void setVirtualFireAlarmMQTTConnector( final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) { this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector; - -// Runnable xmppStarter = new Runnable() { -// @Override -// public void run() { - virtualFireAlarmMQTTConnector.connect(); -// } -// }; -// -// Thread xmppStarterThread = new Thread(xmppStarter); -// xmppStarterThread.setDaemon(true); -// xmppStarterThread.start(); + if (XmppConfig.getInstance().isEnabled()) { + virtualFireAlarmMQTTConnector.connect(); + } else { + log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started."); + } } /** - * * @return */ public VerificationManager getVerificationManager() { @@ -165,7 +159,6 @@ public class VirtualFireAlarmService { } /** - * * @return */ public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() { @@ -173,7 +166,6 @@ public class VirtualFireAlarmService { } /** - * * @return */ public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() { @@ -186,7 +178,6 @@ public class VirtualFireAlarmService { --------------------------------------------------------------------------------------- */ /** - * * @param deviceId * @param name * @param owner @@ -238,7 +229,6 @@ public class VirtualFireAlarmService { } /** - * * @param deviceId * @param response */ @@ -267,7 +257,6 @@ public class VirtualFireAlarmService { } /** - * * @param deviceId * @param name * @param response @@ -312,7 +301,6 @@ public class VirtualFireAlarmService { } /** - * * @param deviceId * @return */ @@ -340,7 +328,6 @@ public class VirtualFireAlarmService { } /** - * * @param username * @return */ @@ -377,7 +364,6 @@ public class VirtualFireAlarmService { } /** - * * @param owner * @param customDeviceName * @param sketchType @@ -411,7 +397,6 @@ public class VirtualFireAlarmService { } /** - * * @param owner * @param customDeviceName * @param sketchType @@ -439,7 +424,6 @@ public class VirtualFireAlarmService { } /** - * * @param owner * @param customDeviceName * @param sketchType @@ -507,7 +491,6 @@ public class VirtualFireAlarmService { } /** - * * @return */ private static String shortUUID() { @@ -522,7 +505,6 @@ public class VirtualFireAlarmService { --------------------------------------------------------------------------------------- */ /** - * * @param owner * @param deviceId * @param deviceIP @@ -563,7 +545,6 @@ public class VirtualFireAlarmService { Called by an external client intended to control the Virtual FireAlarm bulb */ /** - * * @param owner * @param deviceId * @param protocol @@ -722,7 +703,6 @@ public class VirtualFireAlarmService { } /** - * * @param owner * @param deviceId * @param protocol @@ -755,7 +735,7 @@ public class VirtualFireAlarmService { if (log.isDebugEnabled()) { log.debug("Sending request to read virtual-firealarm-temperature of device " + - "[" + deviceId + "] via " + protocolString); + "[" + deviceId + "] via " + protocolString); } try { @@ -767,9 +747,9 @@ public class VirtualFireAlarmService { } String temperatureValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP( - deviceHTTPEndpoint, - VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, - false); + deviceHTTPEndpoint, + VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, + false); SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP, @@ -801,7 +781,6 @@ public class VirtualFireAlarmService { } /** - * * @param dataMsg * @param response */ @@ -818,12 +797,12 @@ public class VirtualFireAlarmService { if (registeredIp == null) { log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " + - deviceIp + " for device ID - " + deviceId); + deviceIp + " for device ID - " + deviceId); response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); return; } else if (!registeredIp.equals(deviceIp)) { log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + deviceId + - " is already registered under some other IP. Re-registration required"); + " is already registered under some other IP. Re-registration required"); response.setStatus(Response.Status.CONFLICT.getStatusCode()); return; } @@ -839,7 +818,6 @@ public class VirtualFireAlarmService { /** - * * @param operation * @param message * @return @@ -922,7 +900,6 @@ public class VirtualFireAlarmService { } /** - * * @param operation * @param inputStream * @return diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.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.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java index 2a26e38e13..b5ddf93dfd 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.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.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java @@ -73,6 +73,7 @@ public class VirtualFireAlarmXMPPConnector extends XMPPTransportHandler { public void createXMPPAccountForDeviceType() { boolean accountExists = false; XmppServerClient xmppServerClient = new XmppServerClient(); + xmppServerClient.initControlQueue(); try { accountExists = xmppServerClient.doesXMPPUserAccountExist(xmppVFireAlarmAdminUsername); diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/mqtt/MqttSubscriber.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/mqtt/MqttSubscriber.java index 5028c39b5f..a80af1dc77 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/mqtt/MqttSubscriber.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/mqtt/MqttSubscriber.java @@ -203,7 +203,10 @@ public abstract class MqttSubscriber implements MqttCallback { */ @Override public void connectionLost(Throwable throwable) { - log.warn("Lost Connection for client: " + this.clientId + " to " + this.mqttBrokerEndPoint + ".\nThis was due to - " + throwable.getMessage()); + if (log.isDebugEnabled()) { + log.warn("Lost Connection for client: " + this.clientId + " to " + this.mqttBrokerEndPoint + + ".\nThis was due to - " + throwable.getMessage()); + } Runnable reSubscriber = new Runnable() { @Override @@ -219,8 +222,6 @@ public abstract class MqttSubscriber implements MqttCallback { log.debug("Could not reconnect and subscribe to ControlQueue."); } } - } else { - return; } } }; @@ -263,7 +264,11 @@ public abstract class MqttSubscriber implements MqttCallback { } String topic = iMqttDeliveryToken.getTopics()[0]; String client = iMqttDeliveryToken.getClient().getClientId(); - log.info("Message - '" + message + "' of client [" + client + "] for the topic (" + topic + ") was delivered successfully."); + + if (log.isDebugEnabled()) { + log.debug("Message - '" + message + "' of client [" + client + "] for the topic (" + topic + + ") was delivered successfully."); + } } /** diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/xmpp/XmppServerClient.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/xmpp/XmppServerClient.java index 3f9c7aaae5..0b07b14241 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/xmpp/XmppServerClient.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/xmpp/XmppServerClient.java @@ -62,7 +62,7 @@ public class XmppServerClient implements ControlQueueConnector { } @Override - public void initControlQueue() throws DeviceControllerException { + public void initControlQueue() { xmppEndpoint = XmppConfig.getInstance().getXmppEndpoint(); xmppUsername = XmppConfig.getInstance().getXmppUsername(); xmppPassword = XmppConfig.getInstance().getXmppPassword(); diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/transport/mqtt/MQTTTransportHandler.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/transport/mqtt/MQTTTransportHandler.java index b05f9f6e75..cc8c6b46cd 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/transport/mqtt/MQTTTransportHandler.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/transport/mqtt/MQTTTransportHandler.java @@ -285,9 +285,10 @@ public abstract class MQTTTransportHandler */ @Override public void connectionLost(Throwable throwable) { - log.warn("Lost Connection for client: " + this.clientId + - " to " + this.mqttBrokerEndPoint + ".\nThis was due to - " + - throwable.getMessage()); + if (log.isDebugEnabled()) { + log.warn("Lost Connection for client: " + this.clientId + " to " + this.mqttBrokerEndPoint + "." + + "\nThis was due to - " + throwable.getMessage()); + } Thread reconnectThread = new Thread() { public void run() {