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..b05fe32b77 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() {
@@ -88,8 +88,7 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler {
} catch (TransportHandlerException e) {
if (log.isDebugEnabled()) {
log.warn(AgentConstants.LOG_APPENDER +
- "Connection/Login to XMPP server at: " + server +
- " failed");
+ "Connection/Login to XMPP server at: " + server + " failed");
}
}
}
@@ -187,19 +186,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() + "].");
+ }
}
};
@@ -212,22 +218,24 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler {
public void disconnect() {
Runnable stopConnection = new Runnable() {
public void run() {
- while (isConnected()) {
+
+ if ( dataPushServiceHandler != null) {
dataPushServiceHandler.cancel(true);
+ }
+
+ while (isConnected()) {
connectorServiceHandler.cancel(true);
closeConnection();
if (log.isDebugEnabled()) {
log.warn(AgentConstants.LOG_APPENDER +
- "Unable to 'STOP' connection to XMPP server at: " +
- server);
+ "Unable to 'STOP' connection to XMPP server at: " + server);
}
try {
Thread.sleep(timeoutInterval);
} catch (InterruptedException e1) {
- log.error(AgentConstants.LOG_APPENDER +
- "XMPP-Terminator: Thread Sleep Interrupt Exception");
+ log.error(AgentConstants.LOG_APPENDER + "XMPP-Terminator: Thread Sleep Interrupt Exception");
}
}
diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/pom.xml
similarity index 97%
rename from components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml
rename to components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/pom.xml
index 89ab6e7024..0121d62aa6 100644
--- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml
+++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/pom.xml
@@ -28,11 +28,11 @@
4.0.0
- org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl
+ org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl1.9.2-SNAPSHOTwarWSO2 Carbon - IoT Server VirtualFireAlarm API
- WSO2 Carbon - Virtual FireAlarm Service API Implementation
+ WSO2 Carbon - Virtual FireAlarm Service Controller API Implementationhttp://wso2.org
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.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java
similarity index 63%
rename from 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
rename to 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 9c968edf84..c505e1c36f 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.controller.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,356 +166,18 @@ public class VirtualFireAlarmService {
}
/**
- *
* @return
*/
public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() {
return virtualFireAlarmMQTTConnector;
}
- /* ---------------------------------------------------------------------------------------
- Device management specific APIs
- Also contains utility methods required for the execution of these APIs
- --------------------------------------------------------------------------------------- */
-
- /**
- *
- * @param deviceId
- * @param name
- * @param owner
- * @return
- */
- @Path("manager/device/register")
- @PUT
- public boolean register(@QueryParam("deviceId") String deviceId,
- @QueryParam("name") String name, @QueryParam("owner") String owner) {
-
- DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
-
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
- try {
- if (deviceManagement.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
- response.setStatus(Response.Status.CONFLICT.getStatusCode());
- return false;
- }
- Device device = new Device();
- device.setDeviceIdentifier(deviceId);
- EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
-
- enrolmentInfo.setDateOfEnrolment(new Date().getTime());
- enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
- enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
- enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
-
- device.setName(name);
- device.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
- enrolmentInfo.setOwner(owner);
- device.setEnrolmentInfo(enrolmentInfo);
- boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device);
-
- if (added) {
- response.setStatus(Response.Status.OK.getStatusCode());
- } else {
- response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
- }
-
- return added;
- } catch (DeviceManagementException e) {
- response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
- return false;
- } finally {
- deviceManagement.endTenantFlow();
- }
- }
-
- /**
- *
- * @param deviceId
- * @param response
- */
- @Path("manager/device/remove/{device_id}")
- @DELETE
- public void removeDevice(@PathParam("device_id") String deviceId, @Context HttpServletResponse response) {
-
- DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
- try {
- boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(
- deviceIdentifier);
- if (removed) {
- response.setStatus(Response.Status.OK.getStatusCode());
- } else {
- response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
- }
- } catch (DeviceManagementException e) {
- response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
- } finally {
- deviceManagement.endTenantFlow();
- }
-
- }
-
- /**
- *
- * @param deviceId
- * @param name
- * @param response
- * @return
- */
- @Path("manager/device/update/{device_id}")
- @POST
- public boolean updateDevice(@PathParam("device_id") String deviceId,
- @QueryParam("name") String name,
- @Context HttpServletResponse response) {
-
- DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
-
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
- try {
- Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
- device.setDeviceIdentifier(deviceId);
-
- // device.setDeviceTypeId(deviceTypeId);
- device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
-
- device.setName(name);
- device.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
-
- boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device);
-
- if (updated) {
- response.setStatus(Response.Status.OK.getStatusCode());
- } else {
- response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
- }
- return updated;
- } catch (DeviceManagementException e) {
- response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
- return false;
- } finally {
- deviceManagement.endTenantFlow();
- }
-
- }
-
- /**
- *
- * @param deviceId
- * @return
- */
- @Path("manager/device/{device_id}")
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Device getDevice(@PathParam("device_id") String deviceId) {
-
- DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
-
- try {
- return deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
-
- } catch (DeviceManagementException e) {
- response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
- return null;
- } finally {
- deviceManagement.endTenantFlow();
- }
-
- }
-
- /**
- *
- * @param username
- * @return
- */
- @Path("manager/devices/{username}")
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Device[] getFirealarmDevices(@PathParam("username") String username) {
-
- DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
-
- try {
- List userDevices =
- deviceManagement.getDeviceManagementService().getDevicesOfUser(
- username);
- ArrayList userDevicesforFirealarm = new ArrayList<>();
- for (Device device : userDevices) {
-
- if (device.getType().equals(VirtualFireAlarmConstants.DEVICE_TYPE) &&
- device.getEnrolmentInfo().getStatus().equals(
- EnrolmentInfo.Status.ACTIVE)) {
- userDevicesforFirealarm.add(device);
-
- }
- }
-
- return userDevicesforFirealarm.toArray(new Device[]{});
- } catch (DeviceManagementException e) {
- response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
- return null;
- } finally {
- deviceManagement.endTenantFlow();
- }
- }
-
- /**
- *
- * @param owner
- * @param customDeviceName
- * @param sketchType
- * @return
- */
- //TODO:: Needs to go to "common.war" cz all the devices have this
- @Path("manager/device/{sketch_type}/download")
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Response downloadSketch(@QueryParam("owner") String owner,
- @QueryParam("deviceName") String customDeviceName,
- @PathParam("sketch_type") String sketchType) {
- try {
- ZipArchive zipFile = createDownloadFile(owner, customDeviceName, sketchType);
- Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
- response.type("application/zip");
- response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
- return response.build();
-
- } catch (IllegalArgumentException ex) {
- return Response.status(400).entity(ex.getMessage()).build();//bad request
- } catch (DeviceManagementException ex) {
- return Response.status(500).entity(ex.getMessage()).build();
- } catch (AccessTokenException ex) {
- return Response.status(500).entity(ex.getMessage()).build();
- } catch (DeviceControllerException ex) {
- return Response.status(500).entity(ex.getMessage()).build();
- } catch (IOException ex) {
- return Response.status(500).entity(ex.getMessage()).build();
- }
- }
-
- /**
- *
- * @param owner
- * @param customDeviceName
- * @param sketchType
- * @return
- */
- @Path("manager/device/{sketch_type}/generate_link")
- @GET
- public Response generateSketchLink(@QueryParam("owner") String owner,
- @QueryParam("deviceName") String customDeviceName,
- @PathParam("sketch_type") String sketchType) {
-
- try {
- ZipArchive zipFile = createDownloadFile(owner, customDeviceName, sketchType);
- Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
- return rb.build();
- } catch (IllegalArgumentException ex) {
- return Response.status(400).entity(ex.getMessage()).build();//bad request
- } catch (DeviceManagementException ex) {
- return Response.status(500).entity(ex.getMessage()).build();
- } catch (AccessTokenException ex) {
- return Response.status(500).entity(ex.getMessage()).build();
- } catch (DeviceControllerException ex) {
- return Response.status(500).entity(ex.getMessage()).build();
- }
- }
-
- /**
- *
- * @param owner
- * @param customDeviceName
- * @param sketchType
- * @return
- * @throws DeviceManagementException
- * @throws AccessTokenException
- * @throws DeviceControllerException
- */
- private ZipArchive createDownloadFile(String owner, String customDeviceName, String sketchType)
- throws DeviceManagementException, AccessTokenException, DeviceControllerException {
- if (owner == null) {
- throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
- }
-
- //create new device id
- String deviceId = shortUUID();
-
- KeyGenerationUtil.createApplicationKeys("virtual_firealarm");
-
- TokenClient accessTokenClient = new TokenClient(VirtualFireAlarmConstants.DEVICE_TYPE);
- AccessTokenInfo accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId);
-
- //create token
- String accessToken = accessTokenInfo.getAccess_token();
- String refreshToken = accessTokenInfo.getRefresh_token();
- //adding registering data
-
- XmppAccount newXmppAccount = new XmppAccount();
- newXmppAccount.setAccountName(owner + "_" + deviceId);
- newXmppAccount.setUsername(deviceId);
- newXmppAccount.setPassword(accessToken);
- newXmppAccount.setEmail(deviceId + "@wso2.com");
-
- XmppServerClient xmppServerClient = new XmppServerClient();
- xmppServerClient.initControlQueue();
- boolean status;
-
- if (XmppConfig.getInstance().isEnabled()) {
- status = xmppServerClient.createXMPPAccount(newXmppAccount);
- if (!status) {
- String msg =
- "XMPP Account was not created for device - " + deviceId + " of owner - " + owner +
- ".XMPP might have been disabled in org.wso2.carbon.device.mgt.iot" +
- ".common.config.server.configs";
- log.warn(msg);
- throw new DeviceManagementException(msg);
- }
- }
-
- //Register the device with CDMF
- String deviceName = customDeviceName + "_" + deviceId;
- status = register(deviceId, deviceName, owner);
-
- if (!status) {
- String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner;
- throw new DeviceManagementException(msg);
- }
-
-
- ZipUtil ziputil = new ZipUtil();
- ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName,
- accessToken, refreshToken);
- zipFile.setDeviceId(deviceId);
- return zipFile;
- }
-
- /**
- *
- * @return
- */
- private static String shortUUID() {
- UUID uuid = UUID.randomUUID();
- long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong();
- return Long.toString(l, Character.MAX_RADIX);
- }
-
/* ---------------------------------------------------------------------------------------
Device specific APIs - Control APIs + Data-Publishing APIs
Also contains utility methods required for the execution of these APIs
--------------------------------------------------------------------------------------- */
/**
- *
* @param owner
* @param deviceId
* @param deviceIP
@@ -563,7 +218,6 @@ public class VirtualFireAlarmService {
Called by an external client intended to control the Virtual FireAlarm bulb */
/**
- *
* @param owner
* @param deviceId
* @param protocol
@@ -722,7 +376,6 @@ public class VirtualFireAlarmService {
}
/**
- *
* @param owner
* @param deviceId
* @param protocol
@@ -755,7 +408,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 +420,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 +454,6 @@ public class VirtualFireAlarmService {
}
/**
- *
* @param dataMsg
* @param response
*/
@@ -818,12 +470,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 +491,6 @@ public class VirtualFireAlarmService {
/**
- *
* @param operation
* @param message
* @return
@@ -922,7 +573,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/dto/DeviceJSON.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/dto/DeviceJSON.java
similarity index 100%
rename from 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/dto/DeviceJSON.java
rename to 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/dto/DeviceJSON.java
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/exception/VirtualFireAlarmException.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/exception/VirtualFireAlarmException.java
similarity index 100%
rename from 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/exception/VirtualFireAlarmException.java
rename to 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/exception/VirtualFireAlarmException.java
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/VirtualFireAlarmMQTTConnector.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/VirtualFireAlarmMQTTConnector.java
similarity index 100%
rename from 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/VirtualFireAlarmMQTTConnector.java
rename to 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/VirtualFireAlarmMQTTConnector.java
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.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java
similarity index 99%
rename from 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
rename to 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 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.controller.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-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VerificationManager.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/util/VerificationManager.java
similarity index 100%
rename from 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/util/VerificationManager.java
rename to 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/util/VerificationManager.java
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/util/VirtualFireAlarmServiceUtils.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/util/VirtualFireAlarmServiceUtils.java
similarity index 100%
rename from 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/util/VirtualFireAlarmServiceUtils.java
rename to 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/util/VirtualFireAlarmServiceUtils.java
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/util/scep/ContentType.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/util/scep/ContentType.java
similarity index 100%
rename from 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/util/scep/ContentType.java
rename to 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/util/scep/ContentType.java
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/util/scep/SCEPOperation.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/util/scep/SCEPOperation.java
similarity index 100%
rename from 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/util/scep/SCEPOperation.java
rename to 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/util/scep/SCEPOperation.java
diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/resources.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/META-INF/resources.xml
similarity index 100%
rename from components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/resources.xml
rename to components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/META-INF/resources.xml
diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/webapp-classloading.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml
similarity index 100%
rename from components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/webapp-classloading.xml
rename to components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml
diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml
similarity index 100%
rename from components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml
rename to components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml
diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/WEB-INF/web.xml
similarity index 100%
rename from components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/web.xml
rename to components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/WEB-INF/web.xml
diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/pom.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/pom.xml
new file mode 100644
index 0000000000..e0d84b85d3
--- /dev/null
+++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/pom.xml
@@ -0,0 +1,262 @@
+
+
+
+
+
+ device-mgt-iot-virtualfirealarm
+ org.wso2.carbon.devicemgt-plugins
+ 1.9.2-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl
+ 1.9.2-SNAPSHOT
+ war
+ WSO2 Carbon - IoT Server VirtualFireAlarm API
+ WSO2 Carbon - Virtual FireAlarm Service Management API Implementation
+ http://wso2.org
+
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+ provided
+
+
+ org.apache.axis2.wso2
+ axis2-client
+
+
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.analytics
+ provided
+
+
+ org.apache.axis2.wso2
+ axis2-client
+
+
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.certificate.mgt.core
+ provided
+
+
+ commons-codec.wso2
+ commons-codec
+
+
+
+
+
+
+
+ org.apache.cxf
+ cxf-rt-frontend-jaxws
+ provided
+
+
+ org.apache.cxf
+ cxf-rt-frontend-jaxrs
+ provided
+
+
+ org.apache.cxf
+ cxf-rt-transports-http
+ provided
+
+
+
+
+ org.eclipse.paho
+ mqtt-client
+ provided
+
+
+
+
+ org.apache.httpcomponents
+ httpasyncclient
+ 4.1
+ provided
+
+
+ org.wso2.carbon.devicemgt-plugins
+ org.wso2.carbon.device.mgt.iot
+ provided
+
+
+ org.wso2.carbon.devicemgt-plugins
+ org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl
+ provided
+
+
+
+
+ org.codehaus.jackson
+ jackson-core-asl
+
+
+ org.codehaus.jackson
+ jackson-jaxrs
+
+
+ javax
+ javaee-web-api
+ provided
+
+
+ javax.ws.rs
+ jsr311-api
+ provided
+
+
+ commons-httpclient.wso2
+ commons-httpclient
+ provided
+
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+ provided
+
+
+ org.bouncycastle.wso2
+ bcprov-jdk15on
+
+
+ org.wso2.carbon
+ org.wso2.carbon.user.api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.queuing
+
+
+ org.wso2.carbon
+ org.wso2.carbon.base
+
+
+ org.apache.axis2.wso2
+ axis2
+
+
+ org.igniterealtime.smack.wso2
+ smack
+
+
+ org.igniterealtime.smack.wso2
+ smackx
+
+
+ jaxen
+ jaxen
+
+
+ commons-fileupload.wso2
+ commons-fileupload
+
+
+ org.apache.ant.wso2
+ ant
+
+
+ org.apache.ant.wso2
+ ant
+
+
+ commons-httpclient.wso2
+ commons-httpclient
+
+
+ org.eclipse.equinox
+ javax.servlet
+
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.api
+
+
+
+
+
+ commons-codec
+ commons-codec
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.apimgt.annotations
+ provided
+
+
+
+ org.igniterealtime.smack.wso2
+ smack
+ provided
+
+
+ org.igniterealtime.smack.wso2
+ smackx
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.apimgt.webapp.publisher
+ provided
+
+
+
+
+
+
+
+
+ maven-compiler-plugin
+
+ UTF-8
+
+ ${wso2.maven.compiler.target}
+
+
+
+ maven-war-plugin
+
+ virtual_firealarm_mgt
+
+
+
+
+
+
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
new file mode 100644
index 0000000000..1f08a15dff
--- /dev/null
+++ 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
@@ -0,0 +1,501 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.apimgt.webapp.publisher.KeyGenerationUtil;
+import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse;
+import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
+import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
+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;
+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;
+import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord;
+import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
+import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
+import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.dto.DeviceJSON;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmMQTTConnector;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmXMPPConnector;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VerificationManager;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.scep.ContentType;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.scep.SCEPOperation;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+@API(name = "virtual_firealarm", version = "1.0.0", context = "/virtual_firealarm")
+public class VirtualFireAlarmService {
+
+ private static Log log = LogFactory.getLog(VirtualFireAlarmService.class);
+
+ //TODO; replace this tenant domain
+ private static final String SUPER_TENANT = "carbon.super";
+
+ @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
+ */
+ public void setVerificationManager(
+ VerificationManager verificationManager) {
+ this.verificationManager = verificationManager;
+ verificationManager.initVerificationManager();
+ }
+
+ /**
+ * @param virtualFireAlarmXMPPConnector
+ */
+ public void setVirtualFireAlarmXMPPConnector(
+ final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) {
+ this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector;
+
+ 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();
+ } else {
+ log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started.");
+ }
+ }
+
+ /**
+ * @param virtualFireAlarmMQTTConnector
+ */
+ public void setVirtualFireAlarmMQTTConnector(
+ final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) {
+ this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector;
+ if (XmppConfig.getInstance().isEnabled()) {
+ virtualFireAlarmMQTTConnector.connect();
+ } else {
+ log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started.");
+ }
+ }
+
+ /**
+ * @return
+ */
+ public VerificationManager getVerificationManager() {
+ return verificationManager;
+ }
+
+ /**
+ * @return
+ */
+ public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() {
+ return virtualFireAlarmXMPPConnector;
+ }
+
+ /**
+ * @return
+ */
+ public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() {
+ return virtualFireAlarmMQTTConnector;
+ }
+
+ /* ---------------------------------------------------------------------------------------
+ Device management specific APIs
+ Also contains utility methods required for the execution of these APIs
+ --------------------------------------------------------------------------------------- */
+
+ /**
+ * @param deviceId
+ * @param name
+ * @param owner
+ * @return
+ */
+ @Path("manager/device/register")
+ @PUT
+ public boolean register(@QueryParam("deviceId") String deviceId,
+ @QueryParam("name") String name, @QueryParam("owner") String owner) {
+
+ DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
+
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(deviceId);
+ deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
+ try {
+ if (deviceManagement.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
+ response.setStatus(Response.Status.CONFLICT.getStatusCode());
+ return false;
+ }
+ Device device = new Device();
+ device.setDeviceIdentifier(deviceId);
+ EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
+
+ enrolmentInfo.setDateOfEnrolment(new Date().getTime());
+ enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
+ enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
+ enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
+
+ device.setName(name);
+ device.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
+ enrolmentInfo.setOwner(owner);
+ device.setEnrolmentInfo(enrolmentInfo);
+ boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device);
+
+ if (added) {
+ response.setStatus(Response.Status.OK.getStatusCode());
+ } else {
+ response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
+ }
+
+ return added;
+ } catch (DeviceManagementException e) {
+ response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ return false;
+ } finally {
+ deviceManagement.endTenantFlow();
+ }
+ }
+
+ /**
+ * @param deviceId
+ * @param response
+ */
+ @Path("manager/device/remove/{device_id}")
+ @DELETE
+ public void removeDevice(@PathParam("device_id") String deviceId, @Context HttpServletResponse response) {
+
+ DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(deviceId);
+ deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
+ try {
+ boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(
+ deviceIdentifier);
+ if (removed) {
+ response.setStatus(Response.Status.OK.getStatusCode());
+ } else {
+ response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
+ }
+ } catch (DeviceManagementException e) {
+ response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ } finally {
+ deviceManagement.endTenantFlow();
+ }
+
+ }
+
+ /**
+ * @param deviceId
+ * @param name
+ * @param response
+ * @return
+ */
+ @Path("manager/device/update/{device_id}")
+ @POST
+ public boolean updateDevice(@PathParam("device_id") String deviceId,
+ @QueryParam("name") String name,
+ @Context HttpServletResponse response) {
+
+ DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
+
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(deviceId);
+ deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
+ try {
+ Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
+ device.setDeviceIdentifier(deviceId);
+
+ // device.setDeviceTypeId(deviceTypeId);
+ device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
+
+ device.setName(name);
+ device.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
+
+ boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device);
+
+ if (updated) {
+ response.setStatus(Response.Status.OK.getStatusCode());
+ } else {
+ response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
+ }
+ return updated;
+ } catch (DeviceManagementException e) {
+ response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ return false;
+ } finally {
+ deviceManagement.endTenantFlow();
+ }
+
+ }
+
+ /**
+ * @param deviceId
+ * @return
+ */
+ @Path("manager/device/{device_id}")
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Device getDevice(@PathParam("device_id") String deviceId) {
+
+ DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(deviceId);
+ deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
+
+ try {
+ return deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
+
+ } catch (DeviceManagementException e) {
+ response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ return null;
+ } finally {
+ deviceManagement.endTenantFlow();
+ }
+
+ }
+
+ /**
+ * @param username
+ * @return
+ */
+ @Path("manager/devices/{username}")
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Device[] getFirealarmDevices(@PathParam("username") String username) {
+
+ DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
+
+ try {
+ List userDevices =
+ deviceManagement.getDeviceManagementService().getDevicesOfUser(
+ username);
+ ArrayList userDevicesforFirealarm = new ArrayList<>();
+ for (Device device : userDevices) {
+
+ if (device.getType().equals(VirtualFireAlarmConstants.DEVICE_TYPE) &&
+ device.getEnrolmentInfo().getStatus().equals(
+ EnrolmentInfo.Status.ACTIVE)) {
+ userDevicesforFirealarm.add(device);
+
+ }
+ }
+
+ return userDevicesforFirealarm.toArray(new Device[]{});
+ } catch (DeviceManagementException e) {
+ response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ return null;
+ } finally {
+ deviceManagement.endTenantFlow();
+ }
+ }
+
+ /**
+ * @param owner
+ * @param customDeviceName
+ * @param sketchType
+ * @return
+ */
+ //TODO:: Needs to go to "common.war" cz all the devices have this
+ @Path("manager/device/{sketch_type}/download")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response downloadSketch(@QueryParam("owner") String owner,
+ @QueryParam("deviceName") String customDeviceName,
+ @PathParam("sketch_type") String sketchType) {
+ try {
+ ZipArchive zipFile = createDownloadFile(owner, customDeviceName, sketchType);
+ Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
+ response.type("application/zip");
+ response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
+ return response.build();
+
+ } catch (IllegalArgumentException ex) {
+ return Response.status(400).entity(ex.getMessage()).build();//bad request
+ } catch (DeviceManagementException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (AccessTokenException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (DeviceControllerException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (IOException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ }
+ }
+
+ /**
+ * @param owner
+ * @param customDeviceName
+ * @param sketchType
+ * @return
+ */
+ @Path("manager/device/{sketch_type}/generate_link")
+ @GET
+ public Response generateSketchLink(@QueryParam("owner") String owner,
+ @QueryParam("deviceName") String customDeviceName,
+ @PathParam("sketch_type") String sketchType) {
+
+ try {
+ ZipArchive zipFile = createDownloadFile(owner, customDeviceName, sketchType);
+ Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
+ return rb.build();
+ } catch (IllegalArgumentException ex) {
+ return Response.status(400).entity(ex.getMessage()).build();//bad request
+ } catch (DeviceManagementException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (AccessTokenException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (DeviceControllerException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ }
+ }
+
+ /**
+ * @param owner
+ * @param customDeviceName
+ * @param sketchType
+ * @return
+ * @throws DeviceManagementException
+ * @throws AccessTokenException
+ * @throws DeviceControllerException
+ */
+ private ZipArchive createDownloadFile(String owner, String customDeviceName, String sketchType)
+ throws DeviceManagementException, AccessTokenException, DeviceControllerException {
+ if (owner == null) {
+ throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
+ }
+
+ //create new device id
+ String deviceId = shortUUID();
+
+ KeyGenerationUtil.createApplicationKeys("virtual_firealarm");
+
+ TokenClient accessTokenClient = new TokenClient(VirtualFireAlarmConstants.DEVICE_TYPE);
+ AccessTokenInfo accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId);
+
+ //create token
+ String accessToken = accessTokenInfo.getAccess_token();
+ String refreshToken = accessTokenInfo.getRefresh_token();
+ //adding registering data
+
+ XmppAccount newXmppAccount = new XmppAccount();
+ newXmppAccount.setAccountName(owner + "_" + deviceId);
+ newXmppAccount.setUsername(deviceId);
+ newXmppAccount.setPassword(accessToken);
+ newXmppAccount.setEmail(deviceId + "@wso2.com");
+
+ XmppServerClient xmppServerClient = new XmppServerClient();
+ xmppServerClient.initControlQueue();
+ boolean status;
+
+ if (XmppConfig.getInstance().isEnabled()) {
+ status = xmppServerClient.createXMPPAccount(newXmppAccount);
+ if (!status) {
+ String msg =
+ "XMPP Account was not created for device - " + deviceId + " of owner - " + owner +
+ ".XMPP might have been disabled in org.wso2.carbon.device.mgt.iot" +
+ ".common.config.server.configs";
+ log.warn(msg);
+ throw new DeviceManagementException(msg);
+ }
+ }
+
+ //Register the device with CDMF
+ String deviceName = customDeviceName + "_" + deviceId;
+ status = register(deviceId, deviceName, owner);
+
+ if (!status) {
+ String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner;
+ throw new DeviceManagementException(msg);
+ }
+
+
+ ZipUtil ziputil = new ZipUtil();
+ ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName,
+ accessToken, refreshToken);
+ zipFile.setDeviceId(deviceId);
+ return zipFile;
+ }
+
+ /**
+ * @return
+ */
+ private static String shortUUID() {
+ UUID uuid = UUID.randomUUID();
+ long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong();
+ return Long.toString(l, Character.MAX_RADIX);
+ }
+
+}
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/dto/DeviceJSON.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/dto/DeviceJSON.java
new file mode 100644
index 0000000000..3d86d79bb1
--- /dev/null
+++ 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/dto/DeviceJSON.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.dto;
+
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class DeviceJSON {
+ @XmlElement(required = true) public String owner;
+ @XmlElement(required = true) public String deviceId;
+ @XmlElement(required = true) public String reply;
+ @XmlElement public Long time;
+ @XmlElement public String key;
+ @XmlElement public float value;
+}
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/exception/VirtualFireAlarmException.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/exception/VirtualFireAlarmException.java
new file mode 100644
index 0000000000..9f9ca0253f
--- /dev/null
+++ 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/exception/VirtualFireAlarmException.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception;
+
+public class VirtualFireAlarmException extends Exception {
+ private static final long serialVersionUID = 118512086957330189L;
+
+ public VirtualFireAlarmException(String errorMessage) {
+ super(errorMessage);
+ }
+
+ public VirtualFireAlarmException(String errorMessage, Throwable throwable) {
+ super(errorMessage, throwable);
+ }
+}
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/transport/VirtualFireAlarmMQTTConnector.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/transport/VirtualFireAlarmMQTTConnector.java
new file mode 100644
index 0000000000..74c850b0ea
--- /dev/null
+++ 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/transport/VirtualFireAlarmMQTTConnector.java
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.paho.client.mqttv3.MqttException;
+import org.eclipse.paho.client.mqttv3.MqttMessage;
+import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager;
+import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
+import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
+import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
+import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VerificationManager;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.util.Calendar;
+import java.util.UUID;
+
+@SuppressWarnings("no JAX-WS annotation")
+public class VirtualFireAlarmMQTTConnector extends MQTTTransportHandler {
+ private static Log log = LogFactory.getLog(VirtualFireAlarmMQTTConnector.class);
+
+ private static String serverName = DeviceManagementConfigurationManager.getInstance().
+ getDeviceManagementServerInfo().getName();
+
+ private static String subscribeTopic = serverName + File.separator + "+" + File.separator +
+ VirtualFireAlarmConstants.DEVICE_TYPE + File.separator + "+" + File.separator + "publisher";
+
+ private static String iotServerSubscriber = UUID.randomUUID().toString().substring(0, 5);
+
+ private VirtualFireAlarmMQTTConnector() {
+ super(iotServerSubscriber, VirtualFireAlarmConstants.DEVICE_TYPE,
+ MqttConfig.getInstance().getMqttQueueEndpoint(), subscribeTopic);
+ }
+
+ @Override
+ public void connect() {
+ Runnable connector = new Runnable() {
+ public void run() {
+ while (!isConnected()) {
+ try {
+ connectToQueue();
+ subscribeToQueue();
+ } catch (TransportHandlerException e) {
+ log.warn("Connection/Subscription to MQTT Broker at: " + mqttBrokerEndPoint + " failed");
+ try {
+ Thread.sleep(timeoutInterval);
+ } catch (InterruptedException ex) {
+ log.error("MQTT-Subscriber: Thread Sleep Interrupt Exception.", ex);
+ }
+ }
+ }
+ }
+ };
+
+ Thread connectorThread = new Thread(connector);
+ connectorThread.setDaemon(true);
+ connectorThread.start();
+ }
+
+ @Override
+ public void processIncomingMessage(MqttMessage mqttMessage, String... messageParams) {
+ String topic = messageParams[0];
+ String ownerAndId = topic.replace(serverName + File.separator, "");
+ ownerAndId = ownerAndId.replace(File.separator + VirtualFireAlarmConstants.DEVICE_TYPE + File.separator, ":");
+ ownerAndId = ownerAndId.replace(File.separator + "publisher", "");
+
+ String owner = ownerAndId.split(":")[0];
+ String deviceId = ownerAndId.split(":")[1];
+
+ if (log.isDebugEnabled()) {
+ log.debug("Received MQTT message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}");
+ }
+
+ String actualMessage;
+
+ try {
+ PublicKey clientPublicKey = VirtualFireAlarmServiceUtils.getDevicePublicKey(deviceId);
+ PrivateKey serverPrivateKey = VerificationManager.getServerPrivateKey();
+ actualMessage = VirtualFireAlarmServiceUtils.extractMessageFromPayload(mqttMessage.toString(),
+ serverPrivateKey, clientPublicKey);
+ if (log.isDebugEnabled()) {
+ log.debug("MQTT: Received Message [" + actualMessage + "] topic: [" + topic + "]");
+ }
+
+ if (actualMessage.contains("PUBLISHER")) {
+ float temperature = Float.parseFloat(actualMessage.split(":")[2]);
+
+ if (!VirtualFireAlarmServiceUtils.publishToDAS(owner, deviceId, temperature)) {
+ log.error("MQTT Subscriber: Publishing data to DAS failed.");
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("MQTT Subscriber: Published data to DAS successfully.");
+ }
+
+ } else if (actualMessage.contains("TEMPERATURE")) {
+ String temperatureValue = actualMessage.split(":")[1];
+ SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP,
+ temperatureValue,
+ Calendar.getInstance().getTimeInMillis());
+ }
+ } catch (VirtualFireAlarmException e) {
+ String errorMsg =
+ "CertificateManagementService failure oo Signature-Verification/Decryption was unsuccessful.";
+ log.error(errorMsg, e);
+ }
+ }
+
+ @Override
+ public void publishDeviceData(String... publishData) throws TransportHandlerException {
+ if (publishData.length != 4) {
+ String errorMsg = "Incorrect number of arguments received to SEND-MQTT Message. " +
+ "Need to be [owner, deviceId, resource{BULB/TEMP}, state{ON/OFF or null}]";
+ log.error(errorMsg);
+ throw new TransportHandlerException(errorMsg);
+ }
+
+ String deviceOwner = publishData[0];
+ String deviceId = publishData[1];
+ String resource = publishData[2];
+ String state = publishData[3];
+
+ MqttMessage pushMessage = new MqttMessage();
+ String publishTopic =
+ serverName + File.separator + deviceOwner + File.separator +
+ VirtualFireAlarmConstants.DEVICE_TYPE + File.separator + deviceId;
+
+ try {
+ PublicKey devicePublicKey = VirtualFireAlarmServiceUtils.getDevicePublicKey(deviceId);
+ PrivateKey serverPrivateKey = VerificationManager.getServerPrivateKey();
+
+ String actualMessage = resource + ":" + state;
+ String encryptedMsg = VirtualFireAlarmServiceUtils.prepareSecurePayLoad(actualMessage,
+ devicePublicKey,
+ serverPrivateKey);
+
+ pushMessage.setPayload(encryptedMsg.getBytes(StandardCharsets.UTF_8));
+ pushMessage.setQos(DEFAULT_MQTT_QUALITY_OF_SERVICE);
+ pushMessage.setRetained(false);
+
+ publishToQueue(publishTopic, pushMessage);
+
+ } catch (VirtualFireAlarmException e) {
+ String errorMsg = "Preparing Secure payload failed for device - [" + deviceId + "] of owner - " +
+ "[" + deviceOwner + "].";
+ log.error(errorMsg);
+ throw new TransportHandlerException(errorMsg, e);
+ }
+ }
+
+
+ @Override
+ public void disconnect() {
+ Runnable stopConnection = new Runnable() {
+ public void run() {
+ while (isConnected()) {
+ try {
+ closeConnection();
+ } catch (MqttException e) {
+ if (log.isDebugEnabled()) {
+ log.warn("Unable to 'STOP' MQTT connection at broker at: " + mqttBrokerEndPoint
+ + " for device-type - " + VirtualFireAlarmConstants.DEVICE_TYPE, e);
+ }
+
+ try {
+ Thread.sleep(timeoutInterval);
+ } catch (InterruptedException e1) {
+ log.error("MQTT-Terminator: Thread Sleep Interrupt Exception at device-type - " +
+ VirtualFireAlarmConstants.DEVICE_TYPE, e1);
+ }
+ }
+ }
+ }
+ };
+
+ Thread terminatorThread = new Thread(stopConnection);
+ terminatorThread.setDaemon(true);
+ terminatorThread.start();
+ }
+
+
+ @Override
+ public void publishDeviceData() {
+ // nothing to do
+ }
+
+ @Override
+ public void publishDeviceData(MqttMessage publishData) throws TransportHandlerException {
+ // nothing to do
+ }
+
+
+ @Override
+ public void processIncomingMessage() {
+ // nothing to do
+ }
+
+ @Override
+ public void processIncomingMessage(MqttMessage message) throws TransportHandlerException {
+ // nothing to do
+ }
+}
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/transport/VirtualFireAlarmXMPPConnector.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/transport/VirtualFireAlarmXMPPConnector.java
new file mode 100644
index 0000000000..b5ddf93dfd
--- /dev/null
+++ 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/transport/VirtualFireAlarmXMPPConnector.java
@@ -0,0 +1,287 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.paho.client.mqttv3.MqttMessage;
+import org.jivesoftware.smack.packet.Message;
+import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager;
+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;
+import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
+import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
+import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
+import org.wso2.carbon.device.mgt.iot.transport.xmpp.XMPPTransportHandler;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VerificationManager;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.util.Calendar;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+@SuppressWarnings("no JAX-WS annotation")
+public class VirtualFireAlarmXMPPConnector extends XMPPTransportHandler {
+ private static Log log = LogFactory.getLog(VirtualFireAlarmXMPPConnector.class);
+
+ private static String xmppServerIP;
+ private static String xmppVFireAlarmAdminUsername;
+ private static String xmppVFireAlarmAdminAccountJID;
+ private static final String V_FIREALARM_XMPP_PASSWORD = "vfirealarm@123";
+ private ScheduledFuture> connectorServiceHandler;
+ private ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
+
+ private VirtualFireAlarmXMPPConnector() {
+ super(XmppConfig.getInstance().getXmppServerIP(), XmppConfig.getInstance().getSERVER_CONNECTION_PORT());
+ }
+
+ public void initConnector() {
+ String serverName =
+ DeviceManagementConfigurationManager.getInstance().getDeviceManagementServerInfo().getName();
+ xmppVFireAlarmAdminUsername = serverName + "_" + VirtualFireAlarmConstants.DEVICE_TYPE;
+
+ xmppServerIP = XmppConfig.getInstance().getXmppServerIP();
+ xmppVFireAlarmAdminAccountJID = xmppVFireAlarmAdminUsername + "@" + xmppServerIP;
+ createXMPPAccountForDeviceType();
+ }
+
+ public void createXMPPAccountForDeviceType() {
+ boolean accountExists = false;
+ 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);
+ }
+ } 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);
+ }
+ }
+ }
+
+
+ @Override
+ public void connect() {
+ Runnable connector = new Runnable() {
+ public void run() {
+ if (!isConnected()) {
+ try {
+ connectToServer();
+ loginToServer(xmppVFireAlarmAdminUsername, V_FIREALARM_XMPP_PASSWORD, null);
+ setFilterOnReceiver(xmppVFireAlarmAdminAccountJID);
+
+ } catch (TransportHandlerException e) {
+ if (log.isDebugEnabled()) {
+ log.warn("Connection/Login to XMPP server at: " + server + " as " +
+ xmppVFireAlarmAdminUsername + " failed for device-type [" +
+ VirtualFireAlarmConstants.DEVICE_TYPE + "].", e);
+ }
+ }
+ }
+ }
+ };
+
+ connectorServiceHandler = service.scheduleAtFixedRate(connector, 0, timeoutInterval, TimeUnit.MILLISECONDS);
+ }
+
+ @Override
+ public void processIncomingMessage(Message xmppMessage) throws TransportHandlerException {
+ String from = xmppMessage.getFrom();
+ String subject = xmppMessage.getSubject();
+ String message = xmppMessage.getBody();
+
+ int indexOfAt = from.indexOf("@");
+ int indexOfSlash = from.indexOf("/");
+
+ if (indexOfAt != -1 && indexOfSlash != -1) {
+ String deviceId = from.substring(0, indexOfAt);
+ String owner = from.substring(indexOfSlash + 1, from.length());
+
+ if (log.isDebugEnabled()) {
+ log.debug("Received XMPP message for: [OWNER-" + owner + "] & [DEVICE.ID-" + deviceId + "]");
+ }
+
+ try {
+ PublicKey clientPublicKey = VirtualFireAlarmServiceUtils.getDevicePublicKey(deviceId);
+ PrivateKey serverPrivateKey = VerificationManager.getServerPrivateKey();
+ String actualMessage = VirtualFireAlarmServiceUtils.extractMessageFromPayload(message, serverPrivateKey,
+ clientPublicKey);
+ if (log.isDebugEnabled()) {
+ log.debug("XMPP: Received Message [" + actualMessage + "] from: [" + from + "]");
+ }
+
+ if (subject != null) {
+ switch (subject) {
+ case "PUBLISHER":
+ float temperature = Float.parseFloat(actualMessage.split(":")[1]);
+ if (!VirtualFireAlarmServiceUtils.publishToDAS(owner, deviceId, temperature)) {
+ log.error("XMPP Connector: Publishing VirtualFirealarm data to DAS failed.");
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("XMPP: Publisher Message [" + actualMessage + "] from [" + from + "] " +
+ "was successfully published to DAS");
+ }
+ break;
+
+ case "CONTROL-REPLY":
+ String tempVal = actualMessage.split(":")[1];
+ SensorDataManager.getInstance().setSensorRecord(deviceId,
+ VirtualFireAlarmConstants.SENSOR_TEMP,
+ tempVal,
+ Calendar.getInstance().getTimeInMillis());
+ break;
+
+ default:
+ if (log.isDebugEnabled()) {
+ log.warn("Unknown XMPP Message [" + actualMessage + "] from [" + from + "] received");
+ }
+ break;
+ }
+ }
+ } catch (VirtualFireAlarmException e) {
+ String errorMsg =
+ "CertificateManagementService failure oo Signature-Verification/Decryption was unsuccessful.";
+ log.error(errorMsg, e);
+ }
+ } else {
+ log.warn("Received XMPP message from client with unexpected JID [" + from + "].");
+ }
+ }
+
+ @Override
+ public void publishDeviceData(String... publishData) throws TransportHandlerException {
+ if (publishData.length != 4) {
+ String errorMsg = "Incorrect number of arguments received to SEND-MQTT Message. " +
+ "Need to be [owner, deviceId, resource{BULB/TEMP}, state{ON/OFF or null}]";
+ log.error(errorMsg);
+ throw new TransportHandlerException(errorMsg);
+ }
+
+ String deviceOwner = publishData[0];
+ String deviceId = publishData[1];
+ String resource = publishData[2];
+ String state = publishData[3];
+
+ try {
+ PublicKey devicePublicKey = VirtualFireAlarmServiceUtils.getDevicePublicKey(deviceId);
+ PrivateKey serverPrivateKey = VerificationManager.getServerPrivateKey();
+
+ String actualMessage = resource + ":" + state;
+ String encryptedMsg = VirtualFireAlarmServiceUtils.prepareSecurePayLoad(actualMessage,
+ devicePublicKey,
+ serverPrivateKey);
+
+ String clientToConnect = deviceId + "@" + xmppServerIP + File.separator + deviceOwner;
+ sendXMPPMessage(clientToConnect, encryptedMsg, "CONTROL-REQUEST");
+
+ } catch (VirtualFireAlarmException e) {
+ String errorMsg = "Preparing Secure payload failed for device - [" + deviceId + "] of owner - " +
+ "[" + deviceOwner + "].";
+ log.error(errorMsg);
+ throw new TransportHandlerException(errorMsg, e);
+ }
+ }
+
+
+ @Override
+ public void disconnect() {
+ Runnable stopConnection = new Runnable() {
+ public void run() {
+ while (isConnected()) {
+ connectorServiceHandler.cancel(true);
+ closeConnection();
+ if (log.isDebugEnabled()) {
+ log.warn("Unable to 'STOP' connection to XMPP server at: " + server +
+ " for user - " + xmppVFireAlarmAdminUsername);
+ }
+
+ try {
+ Thread.sleep(timeoutInterval);
+ } catch (InterruptedException e1) {
+ log.error("XMPP-Terminator: Thread Sleep Interrupt Exception for "
+ + VirtualFireAlarmConstants.DEVICE_TYPE + " type.", e1);
+ }
+
+ }
+ }
+ };
+
+ Thread terminatorThread = new Thread(stopConnection);
+ terminatorThread.setDaemon(true);
+ terminatorThread.start();
+ }
+
+
+ @Override
+ public void processIncomingMessage(Message message, String... messageParams) throws TransportHandlerException {
+ // nothing to do
+ }
+
+ @Override
+ public void processIncomingMessage() throws TransportHandlerException {
+ // nothing to do
+ }
+
+ @Override
+ public void publishDeviceData() throws TransportHandlerException {
+ // nothing to do
+ }
+
+ @Override
+ public void publishDeviceData(Message publishData) throws TransportHandlerException {
+ // nothing to do
+ }
+}
+
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/util/VerificationManager.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/util/VerificationManager.java
new file mode 100644
index 0000000000..07bd72ffb1
--- /dev/null
+++ 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/util/VerificationManager.java
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
+import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+
+
+public class VerificationManager {
+ private static final Log log = LogFactory.getLog(VerificationManager.class);
+
+ private static PrivateKey serverPrivateKey;
+ private static final String SIGNATURE_ALG = "SHA1withRSA";
+ private static final String CIPHER_PADDING = "RSA/ECB/PKCS1Padding";
+
+ private VerificationManager() {
+
+ }
+
+ public void initVerificationManager() {
+ serverPrivateKey = retrievePrivateKey(ConfigurationUtil.CA_CERT_ALIAS,
+ ConfigurationUtil.KEYSTORE_CA_CERT_PRIV_PASSWORD);
+ }
+
+ public static PrivateKey retrievePrivateKey(String alias, String password){
+ PrivateKey privateKey = null;
+ InputStream inputStream = null;
+ KeyStore keyStore;
+
+ try {
+ keyStore = KeyStore.getInstance(ConfigurationUtil.getConfigEntry(ConfigurationUtil.CERTIFICATE_KEYSTORE));
+ inputStream = new FileInputStream(ConfigurationUtil.getConfigEntry(
+ ConfigurationUtil.PATH_CERTIFICATE_KEYSTORE));
+
+ keyStore.load(inputStream, ConfigurationUtil.getConfigEntry(ConfigurationUtil.CERTIFICATE_KEYSTORE_PASSWORD)
+ .toCharArray());
+
+ privateKey = (PrivateKey) (keyStore.getKey(ConfigurationUtil.getConfigEntry(alias),
+ ConfigurationUtil.getConfigEntry(password).toCharArray()));
+
+ } catch (KeyStoreException e) {
+ String errorMsg = "Could not load KeyStore of given type in [certificate-config.xml] file." ;
+ log.error(errorMsg, e);
+ } catch (FileNotFoundException e) {
+ String errorMsg = "KeyStore file could not be loaded from path given in [certificate-config.xml] file.";
+ log.error(errorMsg, e);
+ } catch (NoSuchAlgorithmException e) {
+ String errorMsg = "Algorithm not found when loading KeyStore";
+ log.error(errorMsg, e);
+ } catch (CertificateException e) {
+ String errorMsg = "CertificateException when loading KeyStore";
+ log.error(errorMsg, e);
+ } catch (IOException e) {
+ String errorMsg = "Input output issue occurred when loading KeyStore";
+ log.error(errorMsg, e);
+ } catch (KeystoreException e) {
+ String errorMsg = "An error occurred whilst trying load Configs for KeyStoreReader";
+ log.error(errorMsg, e);
+ } catch (UnrecoverableKeyException e) {
+ String errorMsg = "Key is unrecoverable when retrieving CA private key";
+ log.error(errorMsg, e);
+ } finally {
+ try {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ } catch (IOException e) {
+ log.error("Error closing KeyStore input stream", e);
+ }
+ }
+
+ return privateKey;
+ }
+
+ public static PrivateKey getServerPrivateKey() {
+ return serverPrivateKey;
+ }
+
+ public static String encryptMessage(String message, Key encryptionKey) throws VirtualFireAlarmException {
+ Cipher encrypter;
+ byte[] cipherData;
+
+ try {
+ encrypter = Cipher.getInstance(CIPHER_PADDING);
+ encrypter.init(Cipher.ENCRYPT_MODE, encryptionKey);
+ cipherData = encrypter.doFinal(message.getBytes(StandardCharsets.UTF_8));
+
+ } catch (NoSuchAlgorithmException e) {
+ String errorMsg = "Algorithm not found exception occurred for Cipher instance of [" + CIPHER_PADDING + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (NoSuchPaddingException e) {
+ String errorMsg = "No Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (InvalidKeyException e) {
+ String errorMsg = "InvalidKey exception occurred for encryptionKey \n[\n" + encryptionKey + "\n]\n";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (BadPaddingException e) {
+ String errorMsg = "Bad Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (IllegalBlockSizeException e) {
+ String errorMsg = "Illegal blockSize error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ }
+
+ return Base64.encodeBase64String(cipherData);
+ }
+
+
+ public static String signMessage(String encryptedData, PrivateKey signatureKey) throws VirtualFireAlarmException {
+
+ Signature signature;
+ String signedEncodedString;
+
+ try {
+ signature = Signature.getInstance(SIGNATURE_ALG);
+ signature.initSign(signatureKey);
+ signature.update(Base64.decodeBase64(encryptedData));
+
+ byte[] signatureBytes = signature.sign();
+ signedEncodedString = Base64.encodeBase64String(signatureBytes);
+
+ } catch (NoSuchAlgorithmException e) {
+ String errorMsg = "Algorithm not found exception occurred for Signature instance of [" + SIGNATURE_ALG + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (SignatureException e) {
+ String errorMsg = "Signature exception occurred for Signature instance of [" + SIGNATURE_ALG + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (InvalidKeyException e) {
+ String errorMsg = "InvalidKey exception occurred for signatureKey \n[\n" + signatureKey + "\n]\n";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ }
+
+ return signedEncodedString;
+ }
+
+
+ public static boolean verifySignature(String data, String signedData, PublicKey verificationKey)
+ throws VirtualFireAlarmException {
+
+ Signature signature;
+ boolean verified;
+
+ try {
+ signature = Signature.getInstance(SIGNATURE_ALG);
+ signature.initVerify(verificationKey);
+ signature.update(Base64.decodeBase64(data));
+
+ verified = signature.verify(Base64.decodeBase64(signedData));
+
+ } catch (NoSuchAlgorithmException e) {
+ String errorMsg = "Algorithm not found exception occurred for Signature instance of [" + SIGNATURE_ALG + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (SignatureException e) {
+ String errorMsg = "Signature exception occurred for Signature instance of [" + SIGNATURE_ALG + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (InvalidKeyException e) {
+ String errorMsg = "InvalidKey exception occurred for signatureKey \n[\n" + verificationKey + "\n]\n";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ }
+
+ return verified;
+ }
+
+
+ public static String decryptMessage(String encryptedMessage, Key decryptKey) throws VirtualFireAlarmException {
+
+ Cipher decrypter;
+ String decryptedMessage;
+
+ try {
+
+ decrypter = Cipher.getInstance(CIPHER_PADDING);
+ decrypter.init(Cipher.DECRYPT_MODE, decryptKey);
+ decryptedMessage = new String(decrypter.doFinal(Base64.decodeBase64(encryptedMessage)), StandardCharsets.UTF_8);
+
+ } catch (NoSuchAlgorithmException e) {
+ String errorMsg = "Algorithm not found exception occurred for Cipher instance of [" + CIPHER_PADDING + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (NoSuchPaddingException e) {
+ String errorMsg = "No Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (InvalidKeyException e) {
+ String errorMsg = "InvalidKey exception occurred for encryptionKey \n[\n" + decryptKey + "\n]\n";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (BadPaddingException e) {
+ String errorMsg = "Bad Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (IllegalBlockSizeException e) {
+ String errorMsg = "Illegal blockSize error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ }
+
+ return decryptedMessage;
+ }
+
+
+}
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/util/VirtualFireAlarmServiceUtils.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/util/VirtualFireAlarmServiceUtils.java
new file mode 100644
index 0000000000..b2e60c1484
--- /dev/null
+++ 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/util/VirtualFireAlarmServiceUtils.java
@@ -0,0 +1,312 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.concurrent.FutureCallback;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.apache.http.impl.nio.client.HttpAsyncClients;
+import org.json.JSONObject;
+import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
+import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException;
+import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException;
+
+import javax.ws.rs.HttpMethod;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.ProtocolException;
+import java.net.URL;
+import java.security.Key;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Future;
+
+public class VirtualFireAlarmServiceUtils {
+ private static final Log log = LogFactory.getLog(VirtualFireAlarmServiceUtils.class);
+
+ //TODO; replace this tenant domain
+ private static final String SUPER_TENANT = "carbon.super";
+ private static final String TEMPERATURE_STREAM_DEFINITION = "org.wso2.iot.devices.temperature";
+ private static final String JSON_MESSAGE_KEY = "Msg";
+ private static final String JSON_SIGNATURE_KEY = "Sig";
+
+ public static CertificateManagementService getCertificateManagementService() throws
+ VirtualFireAlarmException {
+
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ CertificateManagementService certificateManagementService = (CertificateManagementService)
+ ctx.getOSGiService(CertificateManagementService.class, null);
+
+ if (certificateManagementService == null) {
+ String msg = "EnrollmentService is not initialized";
+ log.error(msg);
+ throw new VirtualFireAlarmException(msg);
+ }
+
+ return certificateManagementService;
+ }
+
+
+ public static String sendCommandViaHTTP(final String deviceHTTPEndpoint, String urlContext,
+ boolean fireAndForgot) throws DeviceManagementException {
+
+ String responseMsg = "";
+ String urlString = VirtualFireAlarmConstants.URL_PREFIX + deviceHTTPEndpoint + urlContext;
+
+ if (log.isDebugEnabled()) {
+ log.debug(urlString);
+ }
+
+ if (!fireAndForgot) {
+ HttpURLConnection httpConnection = getHttpConnection(urlString);
+
+ try {
+ httpConnection.setRequestMethod(HttpMethod.GET);
+ } catch (ProtocolException e) {
+ String errorMsg =
+ "Protocol specific error occurred when trying to set method to GET" +
+ " for:" + urlString;
+ log.error(errorMsg);
+ throw new DeviceManagementException(errorMsg, e);
+ }
+
+ responseMsg = readResponseFromGetRequest(httpConnection);
+
+ } else {
+ CloseableHttpAsyncClient httpclient = null;
+ try {
+
+ httpclient = HttpAsyncClients.createDefault();
+ httpclient.start();
+ HttpGet request = new HttpGet(urlString);
+ final CountDownLatch latch = new CountDownLatch(1);
+ Future future = httpclient.execute(
+ request, new FutureCallback() {
+ @Override
+ public void completed(HttpResponse httpResponse) {
+ latch.countDown();
+ }
+
+ @Override
+ public void failed(Exception e) {
+ latch.countDown();
+ }
+
+ @Override
+ public void cancelled() {
+ latch.countDown();
+ }
+ });
+
+ latch.await();
+
+ } catch (InterruptedException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Sync Interrupted");
+ }
+ } finally {
+ try {
+ if (httpclient != null) {
+ httpclient.close();
+
+ }
+ } catch (IOException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Failed on close");
+ }
+ }
+ }
+ }
+
+ return responseMsg;
+ }
+
+ /* ---------------------------------------------------------------------------------------
+ Utility methods relevant to creating and sending http requests
+ --------------------------------------------------------------------------------------- */
+
+ /* This methods creates and returns a http connection object */
+
+ public static HttpURLConnection getHttpConnection(String urlString) throws
+ DeviceManagementException {
+
+ URL connectionUrl = null;
+ HttpURLConnection httpConnection;
+
+ try {
+ connectionUrl = new URL(urlString);
+ httpConnection = (HttpURLConnection) connectionUrl.openConnection();
+ } catch (MalformedURLException e) {
+ String errorMsg =
+ "Error occured whilst trying to form HTTP-URL from string: " + urlString;
+ log.error(errorMsg);
+ throw new DeviceManagementException(errorMsg, e);
+ } catch (IOException e) {
+ String errorMsg = "Error occured whilst trying to open a connection to: " +
+ connectionUrl.toString();
+ log.error(errorMsg);
+ throw new DeviceManagementException(errorMsg, e);
+ }
+
+ return httpConnection;
+ }
+
+ /* This methods reads and returns the response from the connection */
+
+ public static String readResponseFromGetRequest(HttpURLConnection httpConnection)
+ throws DeviceManagementException {
+ BufferedReader bufferedReader;
+ try {
+ bufferedReader = new BufferedReader(new InputStreamReader(
+ httpConnection.getInputStream()));
+ } catch (IOException e) {
+ String errorMsg =
+ "There is an issue with connecting the reader to the input stream at: " +
+ httpConnection.getURL();
+ log.error(errorMsg);
+ throw new DeviceManagementException(errorMsg, e);
+ }
+
+ String responseLine;
+ StringBuilder completeResponse = new StringBuilder();
+
+ try {
+ while ((responseLine = bufferedReader.readLine()) != null) {
+ completeResponse.append(responseLine);
+ }
+ } catch (IOException e) {
+ String errorMsg =
+ "Error occured whilst trying read from the connection stream at: " +
+ httpConnection.getURL();
+ log.error(errorMsg);
+ throw new DeviceManagementException(errorMsg, e);
+ }
+ try {
+ bufferedReader.close();
+ } catch (IOException e) {
+ log.error(
+ "Could not succesfully close the bufferedReader to the connection at: " +
+ httpConnection.getURL());
+ }
+
+ return completeResponse.toString();
+ }
+
+ public static boolean publishToDAS(String owner, String deviceId, float temperature) {
+ PrivilegedCarbonContext.startTenantFlow();
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantDomain(SUPER_TENANT, true);
+ DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx.getOSGiService(
+ DeviceAnalyticsService.class, null);
+ Object metdaData[] = {owner, VirtualFireAlarmConstants.DEVICE_TYPE, deviceId,
+ System.currentTimeMillis()};
+ Object payloadData[] = {temperature};
+
+ try {
+ deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0", metdaData,
+ new Object[0], payloadData);
+ } catch (DataPublisherConfigurationException e) {
+ return false;
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ return true;
+ }
+
+
+
+ public static String prepareSecurePayLoad(String message, Key encryptionKey, PrivateKey signatureKey)
+ throws VirtualFireAlarmException {
+ String encryptedMsg = VerificationManager.encryptMessage(message, encryptionKey);
+ String signedPayload = VerificationManager.signMessage(encryptedMsg, signatureKey);
+
+ JSONObject jsonPayload = new JSONObject();
+ jsonPayload.put(JSON_MESSAGE_KEY, encryptedMsg);
+ jsonPayload.put(JSON_SIGNATURE_KEY, signedPayload);
+
+ return jsonPayload.toString();
+ }
+
+
+ public static String extractMessageFromPayload(String message, Key decryptionKey, PublicKey verifySignatureKey)
+ throws VirtualFireAlarmException {
+ String actualMessage;
+
+ JSONObject jsonPayload = new JSONObject(message);
+ Object encryptedMessage = jsonPayload.get(JSON_MESSAGE_KEY);
+ Object signedPayload = jsonPayload.get(JSON_SIGNATURE_KEY);
+
+ if (encryptedMessage != null && signedPayload != null) {
+ if (VerificationManager.verifySignature(
+ encryptedMessage.toString(), signedPayload.toString(), verifySignatureKey)) {
+ actualMessage = VerificationManager.decryptMessage(encryptedMessage.toString(), decryptionKey);
+ } else {
+ String errorMsg = "The message was not signed by a valid client. Could not verify signature on payload";
+ throw new VirtualFireAlarmException(errorMsg);
+ }
+ } else {
+ String errorMsg = "The received message is in an INVALID format. " +
+ "Need to be JSON - {\"Msg\":\"\", \"Sig\":\"\"}.";
+ throw new VirtualFireAlarmException(errorMsg);
+ }
+
+ return actualMessage;
+ }
+
+
+ public static PublicKey getDevicePublicKey(String deviceId) throws VirtualFireAlarmException {
+ PublicKey clientPublicKey;
+ String alias = "";
+
+ try {
+ alias += deviceId.hashCode();
+
+ CertificateManagementService certificateManagementService =
+ VirtualFireAlarmServiceUtils.getCertificateManagementService();
+ X509Certificate clientCertificate = (X509Certificate) certificateManagementService.getCertificateByAlias(
+ alias);
+ clientPublicKey = clientCertificate.getPublicKey();
+
+ } catch (VirtualFireAlarmException e) {
+ String errorMsg = "Could not retrieve CertificateManagementService from the runtime.";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ } catch (KeystoreException e) {
+ String errorMsg = "An error occurred whilst trying to retrieve certificate for deviceId [" + deviceId +
+ "] with alias: [" + alias + "]";
+ log.error(errorMsg);
+ throw new VirtualFireAlarmException(errorMsg, e);
+ }
+ return clientPublicKey;
+ }
+
+}
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/util/scep/ContentType.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/util/scep/ContentType.java
new file mode 100644
index 0000000000..db84c48811
--- /dev/null
+++ 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/util/scep/ContentType.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.scep;
+
+public class ContentType {
+ public static final String X_PKI_MESSAGE = "application/x-pki-message";
+ public static final String X_X509_CA_CERT = "application/x-x509-ca-cert";
+ public static final String X_X509_CA_RA_CERT = "application/x-x509-ca-ra-cert";
+}
+
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/util/scep/SCEPOperation.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/util/scep/SCEPOperation.java
new file mode 100644
index 0000000000..9ad390e5d8
--- /dev/null
+++ 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/util/scep/SCEPOperation.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.scep;
+
+public enum SCEPOperation {
+ GET_CA_CERT("GetCACert"),
+ GET_CA_CAPS("GetCACaps"),
+ PKI_OPERATION("PKIOperation");
+
+ private String value;
+
+ private SCEPOperation(String value) {
+ this.setValue(value);
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/META-INF/resources.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/META-INF/resources.xml
new file mode 100644
index 0000000000..fecdf716a4
--- /dev/null
+++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/META-INF/resources.xml
@@ -0,0 +1,105 @@
+
+
+
+
+
+
+
+ Any
+ PUT
+ http://localhost:9763/virtual_firealarm/manager/device/register
+ /manager/device/register/*
+
+
+ Any
+ DELETE
+ http://localhost:9763/virtual_firealarm/manager/device/remove
+ /manager/device/remove/*
+
+
+ Any
+ POST
+ http://localhost:9763/virtual_firealarm/manager/device/update
+ /manager/device/update/*
+
+
+ Any
+ GET
+ http://localhost:9763/virtual_firealarm/manager/device
+ /manager/device/*
+
+
+ Any
+ GET
+ http://localhost:9763/virtual_firealarm/manager/devices
+ /manager/devices/*
+
+
+ Any
+ GET
+ http://localhost:9763/virtual_firealarm/manager/device/{sketch_type}/download
+ /manager/device/{sketch_type}/download
+
+
+ Any
+ GET
+ http://localhost:9763/virtual_firealarm/manager/device/{sketch_type}/generate_link
+ /manager/device/{sketch_type}/generate_link
+
+
+
+ Any
+ POST
+ http://localhost:9763/virtual_firealarm/controller/register/{owner}/{deviceId}/{ip}/{port}
+ /controller/register/{owner}/{deviceId}/{ip}/{port}
+
+
+ Any
+ POST
+ http://localhost:9763/virtual_firealarm/controller/controller/bulb/{state}
+ /controller/bulb/{state}
+
+
+ Any
+ GET
+ http://localhost:9763/virtual_firealarm/controller/controller/readhumidity
+ /controller/readhumidity
+
+
+ Any
+ GET
+ http://localhost:9763/virtual_firealarm/controller/controller/readtemperature
+ /controller/readtemperature
+
+
+ Any
+ POST
+ http://localhost:9763/virtual_firealarm/controller/controller/push_temperature
+ /controller/push_temperature
+
+
\ No newline at end of file
diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/META-INF/webapp-classloading.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/META-INF/webapp-classloading.xml
new file mode 100644
index 0000000000..fa44619195
--- /dev/null
+++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/META-INF/webapp-classloading.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+ false
+
+
+ CXF,Carbon
+
diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml
new file mode 100644
index 0000000000..7f231b47b7
--- /dev/null
+++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000000..7ac9b312ab
--- /dev/null
+++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.impl/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,66 @@
+
+
+ WSO2 IoT Server
+ WSO2 IoT Server
+
+
+ CXFServlet
+ org.apache.cxf.transport.servlet.CXFServlet
+ 1
+
+
+
+
+ CXFServlet
+ /*
+
+
+
+ isAdminService
+ false
+
+
+ doAuthentication
+ false
+
+
+
+
+
+ managed-api-enabled
+ false
+
+
+ managed-api-owner
+ admin
+
+
+ managed-api-context-template
+ /virtual_firealarm/{version}
+
+
+ managed-api-application
+ virtual_firealarm
+
+
+ managed-api-isSecured
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt-iot-virtualfirealarm/pom.xml b/components/device-mgt-iot-virtualfirealarm/pom.xml
index e4a50fa0d0..090e580ff6 100644
--- a/components/device-mgt-iot-virtualfirealarm/pom.xml
+++ b/components/device-mgt-iot-virtualfirealarm/pom.xml
@@ -37,7 +37,8 @@
org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl
- org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl
+ org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl
+ org.wso2.carbon.device.mgt.iot.virtualfirealarm.mgt.service.implorg.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.implorg.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl
diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/apimgt/TokenClient.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/apimgt/TokenClient.java
index 4450707214..7ff23b3f9f 100644
--- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/apimgt/TokenClient.java
+++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/apimgt/TokenClient.java
@@ -63,7 +63,7 @@ public class TokenClient {
grantType = DeviceManagementConfigurationManager.getInstance().getDeviceCloudMgtConfig()
.getApiManager()
.getDeviceGrantType();
- scope = apiManagerConfig.getDeviceScopes();
+ scope = "device_scope";
appToken = ApisAppClient.getInstance().getBase64EncodedConsumerKeyAndSecret(deviceType);
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() {
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.h b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.h
index c8ac26e914..3a1fe1ab9d 100644
--- a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.h
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.h
@@ -30,14 +30,14 @@
#define WLAN_SSID "SSID" // cannot be longer than 32 characters!
#define WLAN_PASS "password"
-#define WLAN_SECURITY WLAN_SEC_WPA
+#define WLAN_SECURITY WLAN_SEC_WPA2
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define IDLE_TIMEOUT_MS 3000
#define DEVICE_OWNER "${DEVICE_OWNER}"
#define DEVICE_ID "${DEVICE_ID}"
#define DEVICE_TOKEN "${DEVICE_TOKEN}"
-#define REFRESH_DEVICE_TOKEN "${REFRESH_DEVICE_TOKEN}"
+#define REFRESH_DEVICE_TOKEN "${DEVICE_REFRESH_TOKEN}"
#define SERVICE_PORT 9763
diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.hbs
index 9b41cbfb39..e6c39b7d06 100644
--- a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.hbs
+++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.hbs
@@ -1,4 +1,5 @@
{{unit "uuf.unit.lib.form-validation"}}
+
Register
@@ -51,6 +52,7 @@
-{{#zone "bottomLoginJs"}}
+
+{{#zone "bottomJs"}}
{{js "js/validate-register.js"}}
{{/zone}}
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryStats.log b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryStats.log
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/sketch.properties b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/sketch.properties
new file mode 100644
index 0000000000..f061050473
--- /dev/null
+++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/sketch.properties
@@ -0,0 +1,2 @@
+templates=deviceConfig.properties
+zipfilename=RaspberryPiAgent.zip
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/deviceConfig.properties b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/deviceConfig.properties
deleted file mode 100644
index 2e9a652b05..0000000000
--- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/deviceConfig.properties
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-#
-[Device-Configurations]
-owner=admin
-deviceId=u856bjb7z4fr
-device-name=rsdghoooooooooooooooooooooooooooooooooooooo_u856bjb7z4fr
-controller-context=/raspberrypi/controller
-https-ep=https://192.168.237.1:9443
-http-ep=http://192.168.237.1:9763
-apim-ep=http://192.168.237.1:9763
-mqtt-ep=tcp://204.232.188.214:1883
-xmpp-ep=http://204.232.188.215:5222
-auth-method=token
-auth-token=a568d7110ec2f4f4f51623cfbf62b67b
-refresh-token=d8d1feb54fb2b2fed5436299c64ceaef
-push-interval=15
-
-
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/wso2IoTsServer b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/wso2IoTsServer
deleted file mode 100644
index 2e6850ff28..0000000000
--- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/wso2IoTsServer
+++ /dev/null
@@ -1,32 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIFkzCCA3sCBAKkVfcwDQYJKoZIhvcNAQEFBQAwgY0xCzAJBgNVBAYTAlNMMRAw
-DgYDVQQIEwdXZXN0ZXJuMRAwDgYDVQQHEwdDb2xvbWJvMQ0wCwYDVQQKEwRXU08y
-MRQwEgYDVQQLEwtFbmdpbmVlcmluZzESMBAGA1UEAxMJbG9jYWxob3N0MSEwHwYJ
-KoZIhvcNAQkBFhJpb3RzZXJ2ZXJAd3NvMi5jb20wHhcNMTUxMjE3MTMxMTA0WhcN
-MTcxMjE2MTMxMTA0WjCBjTELMAkGA1UEBhMCU0wxEDAOBgNVBAgTB1dlc3Rlcm4x
-EDAOBgNVBAcTB0NvbG9tYm8xDTALBgNVBAoTBFdTTzIxFDASBgNVBAsTC0VuZ2lu
-ZWVyaW5nMRIwEAYDVQQDEwlsb2NhbGhvc3QxITAfBgkqhkiG9w0BCQEWEmlvdHNl
-cnZlckB3c28yLmNvbTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBALki
-GVQ9tZOKIi/gD/toV+enq+neqOBGYQ8Fq/ABOWnK2QpGWm81+Rets5GbQ6W//D8C
-5TOBGqK7z+LAgdmILr1XLkvrXWoan0GPdDJ1wpc2/6XDZvM5f7Y8cmRqVPJv7AF+
-ImgF9dqv97gYCiujy+nNHd5Nk/60pco2LBV5SyLqqrzKXEnSGrS4zoYWpPeJ9YrX
-PEkW7A6AxTQK0yU9Ej4TktgafbTueythrLomKiZJj4wPxm2lA2lAZscDdws9NWrI
-5z/LUVLbUMxrY10Nig1liX5b1mrUk5bb1d2tqwkPrpRILKoOBJtI674SQS3GziiU
-iCJGIO/EGGRn1AJsC/SvnnEez3WKY/DgJ6102MWK/yWtY8NYHUX2anwMBS7UpT5A
-4BXdsfBz3R+iPF99FxdAGGsS4GQuuPocZaycLqoPCxpTSSxBsKMUcKpn3yaiQRd6
-uDuiTNt7odDOQj0Tno7uokh/HILgbzvj9EExDOsdwLVvqYmUHBPeLmiICWXfi4ky
-H/twPOZtV9eVnfWYx5Kwg+2Y4fIb3q4ABr0hzxaMYHQo6NOukSH1BcdAWiQIXbSF
-FaTZD8p6OfiZpHcQ59HT/Z8GBlCFL2xkYJFmOhXI/Cu+xrcwqEIInv7d8w3eiNQ7
-MneomEptLbBk9+kMsP0ubo34oOGHR9qk3Lj580c/AgMBAAEwDQYJKoZIhvcNAQEF
-BQADggIBADw70g2/wrgzrAM8OXBlthGbCEaXZpKwq9IJN0qu+/l+PNwF7csQhj+q
-W+zMrWaH1DGWJroaei1+NFFrj/pvp61rF/ZeTPGVJd7puCq++SevqIrzKyAEBtwt
-pXmcFhBpV/FrQAv3ODOJ3bN2wSRPZHUvARTBB3RaUI06g1jCaBzjDEGoMfSxdr5/
-Ty2WxTI9u9RlIs3Q52AiOmROtLPiEQZQIqfNO3cxCEWojHxPqVEZA/kQYy+rryj4
-H0zzSrj7QFlQhsMDw5j8bv9AcvTEGmwp29avsgnceDWinI6lwtd8zqh0ZW9QJdH0
-BRNCM/EkTlTUHeEg04/sOgOrlWcvEfVxDqNEtbUzU9UFxl0lkQkuRn1UdxZlvhWa
-Fnel5iRC9b7OZvi2mkVujLyxEWlJB1tuyMLQxu6PfabBVODP5V8/+uyiiK/gwrB5
-rYl8RHxGoznJnI1Y3HVzKlA849CrMBaY5vnhE03cNja7QroPzLmmuXBLk2LbI1lu
-5nJAqKpBUPMI/IU3pF4Q7VTD2ZANI+ktGgGlM8AK4OJHWOhj8W289pWTHVjG8syP
-LTsaYkhgLjzZl/g9cUwn/96NJNvzd3dkT+7VgE+BJOLofq25CjZcN1M7MhWdl3vb
-WNj9vzL0+FCnwca8UecfvFS39PIekIvqbtP+Gw8NiYOUGIllZ0JH
------END CERTIFICATE-----
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/public/images/schematicsGuide.png b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/public/images/schematicsGuide.png
new file mode 100644
index 0000000000..e2a8c544c8
Binary files /dev/null and b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/public/images/schematicsGuide.png differ
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs
index 0db0bd5ebc..1b71dba6e4 100644
--- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs
+++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs
@@ -1,180 +1,218 @@
-
-
-
RaspberryPi
-
-
Connect your RaspberryPi device to the WSO2 IoT Server.