From 188d32e19e92e90176a9945f89e2bc40598df580 Mon Sep 17 00:00:00 2001 From: Ace Date: Wed, 23 Dec 2015 13:27:17 +0530 Subject: [PATCH] decoupling mgt/controller functions for digital display --- .../pom.xml | 2 +- .../api/DigitalDisplayControllerService.java | 0 .../digitaldisplay/api/dto/DeviceJSON.java | 0 .../exception/DigitalDisplayException.java | 0 .../api/transport/CommunicationHandler.java | 0 .../CommunicationHandlerException.java | 0 .../transport/MQTTCommunicationHandler.java | 0 ...igitalDisplayMqttCommunicationHandler.java | 0 ...DigitalDisplayWebSocketServerEndPoint.java | 0 .../webapp/META-INF/webapp-classloading.xml | 0 .../src/main/webapp/WEB-INF/cxf-servlet.xml | 11 - .../src/main/webapp/WEB-INF/web.xml | 0 .../pom.xml | 239 ++++++++++++ .../api/DigitalDisplayManagerService.java | 1 - .../digitaldisplay/api/dto/DeviceJSON.java | 33 ++ .../exception/DigitalDisplayException.java | 44 +++ .../api/transport/CommunicationHandler.java | 15 + .../CommunicationHandlerException.java | 38 ++ .../transport/MQTTCommunicationHandler.java | 345 ++++++++++++++++++ ...igitalDisplayMqttCommunicationHandler.java | 141 +++++++ ...DigitalDisplayWebSocketServerEndPoint.java | 74 ++++ .../webapp/META-INF/webapp-classloading.xml | 33 ++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 44 +++ .../src/main/webapp/WEB-INF/web.xml | 60 +++ .../device-mgt-iot-digitaldisplay/pom.xml | 3 +- .../database/AndroidSenseDM_DB.h2.db | Bin 16384 -> 16384 bytes .../resources/database/ArduinoDM_DB.h2.db | Bin 16384 -> 16384 bytes .../pom.xml | 19 +- .../database/DigitalDisplayDM_DB.h2.db | Bin 16384 -> 16384 bytes .../database/DroneAnalyzerDM_DB.h2.db | Bin 16384 -> 16384 bytes .../resources/database/RaspberryPiDM_DB.h2.db | Bin 16384 -> 16384 bytes .../database/VirtualFireAlarmDM_DB.h2.db | Bin 16384 -> 16384 bytes .../database/WSO2MobileAndroid_DB.h2.db | Bin 18432 -> 18432 bytes .../database/WSO2MobileWindows_DB.h2.db | Bin 12288 -> 12288 bytes pom.xml | 8 +- 35 files changed, 1093 insertions(+), 17 deletions(-) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/pom.xml (98%) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayControllerService.java (100%) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/dto/DeviceJSON.java (100%) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/exception/DigitalDisplayException.java (100%) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandler.java (100%) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandlerException.java (100%) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/MQTTCommunicationHandler.java (100%) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/util/DigitalDisplayMqttCommunicationHandler.java (100%) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/websocket/DigitalDisplayWebSocketServerEndPoint.java (100%) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/src/main/webapp/META-INF/webapp-classloading.xml (100%) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/src/main/webapp/WEB-INF/cxf-servlet.xml (80%) rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api}/src/main/webapp/WEB-INF/web.xml (100%) create mode 100644 components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml rename components/device-mgt-iot-digitaldisplay/{org.wso2.carbon.device.mgt.iot.digitaldisplay.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api}/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java (99%) create mode 100644 components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/dto/DeviceJSON.java create mode 100644 components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/exception/DigitalDisplayException.java create mode 100644 components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandler.java create mode 100644 components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandlerException.java create mode 100644 components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/MQTTCommunicationHandler.java create mode 100644 components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/util/DigitalDisplayMqttCommunicationHandler.java create mode 100644 components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/websocket/DigitalDisplayWebSocketServerEndPoint.java create mode 100644 components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/META-INF/webapp-classloading.xml create mode 100644 components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml create mode 100644 components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/pom.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/pom.xml similarity index 98% rename from components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/pom.xml rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/pom.xml index 10593233a1..adf7c5eb4f 100644 --- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/pom.xml +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/pom.xml @@ -11,7 +11,7 @@ 4.0.0 - org.wso2.carbon.device.mgt.iot.digitaldisplay.api + org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api 1.9.2-SNAPSHOT war WSO2 Carbon - IoT Server DigitalDisplay API 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.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayControllerService.java similarity index 100% rename from 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 rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayControllerService.java 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/dto/DeviceJSON.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/dto/DeviceJSON.java similarity index 100% rename from components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/dto/DeviceJSON.java rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/dto/DeviceJSON.java 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/exception/DigitalDisplayException.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/exception/DigitalDisplayException.java similarity index 100% rename from components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/exception/DigitalDisplayException.java rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/exception/DigitalDisplayException.java 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/transport/CommunicationHandler.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandler.java similarity index 100% rename from components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandler.java rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandler.java 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/transport/CommunicationHandlerException.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandlerException.java similarity index 100% rename from components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandlerException.java rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandlerException.java 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/transport/MQTTCommunicationHandler.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/MQTTCommunicationHandler.java similarity index 100% rename from components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/MQTTCommunicationHandler.java rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/MQTTCommunicationHandler.java 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.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/util/DigitalDisplayMqttCommunicationHandler.java similarity index 100% rename from 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 rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/util/DigitalDisplayMqttCommunicationHandler.java 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/websocket/DigitalDisplayWebSocketServerEndPoint.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/websocket/DigitalDisplayWebSocketServerEndPoint.java similarity index 100% rename from components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/websocket/DigitalDisplayWebSocketServerEndPoint.java rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/websocket/DigitalDisplayWebSocketServerEndPoint.java diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/META-INF/webapp-classloading.xml similarity index 100% rename from components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/META-INF/webapp-classloading.xml rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/META-INF/webapp-classloading.xml diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml similarity index 80% rename from components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/cxf-servlet.xml rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml index cf04c1c49c..8217ddfcea 100644 --- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -36,17 +36,6 @@ - - - - - - - - - - diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/web.xml rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/WEB-INF/web.xml diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml new file mode 100644 index 0000000000..f27cac0a5d --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml @@ -0,0 +1,239 @@ + + + + + device-mgt-iot-digitaldisplay + org.wso2.carbon.devicemgt-plugins + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api + 1.9.2-SNAPSHOT + war + WSO2 Carbon - IoT Server DigitalDisplay API + WSO2 Carbon - Digital Display Service 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.digitaldisplay + 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.igniterealtime.smack.wso2 + smack + provided + + + org.igniterealtime.smack.wso2 + smackx + provided + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + provided + + + + + + + + maven-compiler-plugin + + UTF-8 + ${wso2.maven.compiler.source} + ${wso2.maven.compiler.target} + + + + maven-war-plugin + + digital_display_mgt + + + + + + \ No newline at end of file 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/DigitalDisplayManagerService.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java similarity index 99% rename from components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java rename to components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java index 10d1e5f624..9ae0445f2a 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/DigitalDisplayManagerService.java +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java @@ -40,7 +40,6 @@ import java.util.Date; import java.util.UUID; @WebService -@API( name="digital_display", version="1.0.0", context="/digital_display") public class DigitalDisplayManagerService { private static Log log = LogFactory.getLog(DigitalDisplayManagerService.class); diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/dto/DeviceJSON.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/dto/DeviceJSON.java new file mode 100644 index 0000000000..08979a267b --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/dto/DeviceJSON.java @@ -0,0 +1,33 @@ +/* + * 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.digitaldisplay.api.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; +} diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/exception/DigitalDisplayException.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/exception/DigitalDisplayException.java new file mode 100644 index 0000000000..d5c33a6346 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/exception/DigitalDisplayException.java @@ -0,0 +1,44 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.exception; + +/** + * Created by nuwan on 12/2/15. + */ +public class DigitalDisplayException extends Exception { + + private static final long serialVersionUID = 2736466230451105441L; + + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public DigitalDisplayException(String msg, DigitalDisplayException nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public DigitalDisplayException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public DigitalDisplayException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public DigitalDisplayException() { + super(); + } + + public DigitalDisplayException(Throwable cause) { + super(cause); + } + + +} diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandler.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandler.java new file mode 100644 index 0000000000..9c165fef62 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandler.java @@ -0,0 +1,15 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport; + +public interface CommunicationHandler { + int DEFAULT_TIMEOUT_INTERVAL = 5000; // millis ~ 10 sec + + void connect(); + + boolean isConnected(); + + void processIncomingMessage(T message, String... messageParams); + + void processIncomingMessage(); + + void disconnect(); +} diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandlerException.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandlerException.java new file mode 100644 index 0000000000..447ae6f1b1 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/CommunicationHandlerException.java @@ -0,0 +1,38 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport; + +public class CommunicationHandlerException extends Exception { + private static final long serialVersionUID = 2736466230451105440L; + + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public CommunicationHandlerException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public CommunicationHandlerException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public CommunicationHandlerException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public CommunicationHandlerException() { + super(); + } + + public CommunicationHandlerException(Throwable cause) { + super(cause); + } +} diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/MQTTCommunicationHandler.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/MQTTCommunicationHandler.java new file mode 100644 index 0000000000..c441f892c5 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/transport/MQTTCommunicationHandler.java @@ -0,0 +1,345 @@ +/* + * 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.digitaldisplay.api.transport; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.paho.client.mqttv3.*; + +import java.io.File; +import java.nio.charset.StandardCharsets; + +/** + * This class contains the IoT-Server specific implementation for all the MQTT functionality. + * This includes connecting to a MQTT Broker & subscribing to the appropriate MQTT-topic, action + * plan upon losing connection or successfully delivering a message to the broker and processing + * incoming messages. Makes use of the 'Paho-MQTT' library provided by Eclipse Org. + *

+ * It is an abstract class that implements the common interface "CommunicationHandler" and the + * "MqttCallback". Whilst providing some methods which handle key MQTT relevant tasks, this class + * implements only the most generic methods of the "CommunicationHandler" interface. The rest of + * the methods are left for any extended concrete-class to implement as per its need. + */ +public abstract class MQTTCommunicationHandler + implements MqttCallback, CommunicationHandler { + private static final Log log = LogFactory.getLog(MQTTCommunicationHandler.class); + + public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0; + + private MqttClient client; + private String clientId; + private MqttConnectOptions options; + private String clientWillTopic; + + protected String mqttBrokerEndPoint; + protected int timeoutInterval; + protected String subscribeTopic; + + /** + * Constructor for the MQTTCommunicationHandler which takes in the owner, type of the device + * and the MQTT Broker URL and the topic to subscribe. + * + * @param deviceOwner the owner of the device. + * @param deviceType the CDMF Device-Type of the device. + * @param mqttBrokerEndPoint the IP/URL of the MQTT broker endpoint. + * @param subscribeTopic the MQTT topic to which the client is to be subscribed + */ + protected MQTTCommunicationHandler(String deviceOwner, String deviceType, + String mqttBrokerEndPoint, + String subscribeTopic) { + this.clientId = deviceOwner + ":" + deviceType; + this.subscribeTopic = subscribeTopic; + this.clientWillTopic = deviceType + File.separator + "disconnection"; + this.mqttBrokerEndPoint = mqttBrokerEndPoint; + this.timeoutInterval = DEFAULT_TIMEOUT_INTERVAL; + this.initSubscriber(); + } + + /** + * Constructor for the MQTTCommunicationHandler which takes in the owner, type of the device + * and the MQTT Broker URL and the topic to subscribe. Additionally this constructor takes in + * the reconnection-time interval between successive attempts to connect to the broker. + * + * @param deviceOwner the owner of the device. + * @param deviceType the CDMF Device-Type of the device. + * @param mqttBrokerEndPoint the IP/URL of the MQTT broker endpoint. + * @param subscribeTopic the MQTT topic to which the client is to be subscribed + * @param intervalInMillis the time interval in MILLI-SECONDS between successive + * attempts to connect to the broker. + */ + protected MQTTCommunicationHandler(String deviceOwner, String deviceType, + String mqttBrokerEndPoint, String subscribeTopic, + int intervalInMillis) { + this.clientId = deviceOwner + ":" + deviceType; + this.subscribeTopic = subscribeTopic; + this.clientWillTopic = deviceType + File.separator + "disconnection"; + this.mqttBrokerEndPoint = mqttBrokerEndPoint; + this.timeoutInterval = intervalInMillis; + this.initSubscriber(); + } + + public void setTimeoutInterval(int timeoutInterval) { + this.timeoutInterval = timeoutInterval; + } + + /** + * Initializes the MQTT-Client. Creates a client using the given MQTT-broker endpoint and the + * clientId (which is constructed by a concatenation of [deviceOwner]:[deviceType]). Also sets + * the client's options parameter with the clientWillTopic (in-case of connection failure) and + * other info. Also sets the call-back this current class. + */ + private void initSubscriber() { + try { + + client = new MqttClient(this.mqttBrokerEndPoint, clientId, null); + log.info("MQTT subscriber was created with ClientID : " + clientId); + } catch (MqttException ex) { + String errorMsg = "MQTT Client Error\n" + "\tReason: " + ex.getReasonCode() + + "\n\tMessage: " + ex.getMessage() + "\n\tLocalMsg: " + + ex.getLocalizedMessage() + "\n\tCause: " + ex.getCause() + + "\n\tException: " + ex; + log.error(errorMsg); + } + + options = new MqttConnectOptions(); + options.setCleanSession(false); + options.setWill(clientWillTopic, "Connection-Lost".getBytes(StandardCharsets.UTF_8), 2, + true); + client.setCallback(this); + } + + /** + * Checks whether the connection to the MQTT-Broker persists. + * + * @return true if the client is connected to the MQTT-Broker, else false. + */ + @Override + public boolean isConnected() { + return client.isConnected(); + } + + + /** + * Connects to the MQTT-Broker and if successfully established connection. + * + * @throws CommunicationHandlerException in the event of 'Connecting to' the MQTT broker fails. + */ + protected void connectToQueue() throws CommunicationHandlerException { + try { + client.connect(options); + + if (log.isDebugEnabled()) { + log.debug("Subscriber connected to queue at: " + this.mqttBrokerEndPoint); + } + } catch (MqttSecurityException ex) { + String errorMsg = "MQTT Security Exception when connecting to queue\n" + "\tReason: " + + " " + + ex.getReasonCode() + "\n\tMessage: " + ex.getMessage() + + "\n\tLocalMsg: " + ex.getLocalizedMessage() + "\n\tCause: " + + ex.getCause() + "\n\tException: " + ex; + if (log.isDebugEnabled()) { + log.debug(errorMsg); + } + throw new CommunicationHandlerException(errorMsg, ex); + + } catch (MqttException ex) { + String errorMsg = "MQTT Exception when connecting to queue\n" + "\tReason: " + + ex.getReasonCode() + "\n\tMessage: " + ex.getMessage() + + "\n\tLocalMsg: " + ex.getLocalizedMessage() + "\n\tCause: " + + ex.getCause() + "\n\tException: " + ex; + if (log.isDebugEnabled()) { + log.debug(errorMsg); + } + throw new CommunicationHandlerException(errorMsg, ex); + } + } + + /** + * Subscribes to the MQTT-Topic specific to this MQTT Client. (The MQTT-Topic specific to the + * device is taken in as a constructor parameter of this class) . + * + * @throws CommunicationHandlerException in the event of 'Subscribing to' the MQTT broker + * fails. + */ + protected void subscribeToQueue() throws CommunicationHandlerException { + try { + client.subscribe(subscribeTopic, 0); + log.info("Subscriber '" + clientId + "' subscribed to topic: " + subscribeTopic); + } catch (MqttException ex) { + String errorMsg = "MQTT Exception when trying to subscribe to topic: " + + subscribeTopic + "\n\tReason: " + ex.getReasonCode() + + "\n\tMessage: " + ex.getMessage() + "\n\tLocalMsg: " + + ex.getLocalizedMessage() + "\n\tCause: " + ex.getCause() + + "\n\tException: " + ex; + if (log.isDebugEnabled()) { + log.debug(errorMsg); + } + + throw new CommunicationHandlerException(errorMsg, ex); + } + } + + + /** + * This method is used to publish reply-messages for the control signals received. + * Invocation of this method calls its overloaded-method with a QoS equal to that of the + * default value. + * + * @param topic the topic to which the reply message is to be published. + * @param payLoad the reply-message (payload) of the MQTT publish action. + */ + protected void publishToQueue(String topic, String payLoad) + throws CommunicationHandlerException { + publishToQueue(topic, payLoad, DEFAULT_MQTT_QUALITY_OF_SERVICE, false); + } + + /** + * This is an overloaded method that publishes MQTT reply-messages for control signals + * received form the IoT-Server. + * + * @param topic the topic to which the reply message is to be published + * @param payLoad the reply-message (payload) of the MQTT publish action. + * @param qos the Quality-of-Service of the current publish action. + * Could be 0(At-most once), 1(At-least once) or 2(Exactly once) + */ + protected void publishToQueue(String topic, String payLoad, int qos, boolean retained) + throws CommunicationHandlerException { + try { + client.publish(topic, payLoad.getBytes(StandardCharsets.UTF_8), qos, retained); + if (log.isDebugEnabled()) { + log.debug("Message: " + payLoad + " to MQTT topic [" + topic + + "] published successfully"); + } + } catch (MqttException ex) { + String errorMsg = + "MQTT Client Error" + "\n\tReason: " + ex.getReasonCode() + "\n\tMessage: " + + ex.getMessage() + "\n\tLocalMsg: " + ex.getLocalizedMessage() + + "\n\tCause: " + ex.getCause() + "\n\tException: " + ex; + log.info(ex); + throw new CommunicationHandlerException(errorMsg, ex); + } + } + + + protected void publishToQueue(String topic, MqttMessage message) + throws CommunicationHandlerException { + try { + client.publish(topic, message); + if (log.isDebugEnabled()) { + log.debug("Message: " + message.toString() + " to MQTT topic [" + topic + + "] published successfully"); + } + } catch (MqttException ex) { + String errorMsg = + "MQTT Client Error" + "\n\tReason: " + ex.getReasonCode() + "\n\tMessage: " + + ex.getMessage() + "\n\tLocalMsg: " + ex.getLocalizedMessage() + + "\n\tCause: " + ex.getCause() + "\n\tException: " + ex; + log.info(errorMsg); + throw new CommunicationHandlerException(errorMsg, ex); + } + } + + + /** + * Callback method which is triggered once the MQTT client losers its connection to the broker. + * Spawns a new thread that executes necessary actions to try and reconnect to the endpoint. + * + * @param throwable a Throwable Object containing the details as to why the failure occurred. + */ + @Override + public void connectionLost(Throwable throwable) { + log.warn("Lost Connection for client: " + this.clientId + + " to " + this.mqttBrokerEndPoint + ".\nThis was due to - " + + throwable.getMessage()); + + + Thread reconnectThread = new Thread() { + public void run() { + connect(); + } + }; + reconnectThread.setDaemon(true); + reconnectThread.start(); + } + + /** + * Callback method which is triggered upon receiving a MQTT Message from the broker. Spawns a + * new thread that executes any actions to be taken with the received message. + * + * @param topic the MQTT-Topic to which the received message was published to and the + * client was subscribed to. + * @param mqttMessage the actual MQTT-Message that was received from the broker. + */ + @Override + public void messageArrived(final String topic, final MqttMessage mqttMessage) { + if (log.isDebugEnabled()) { + log.info("Got an MQTT message '" + mqttMessage.toString() + "' for topic '" + topic + + "'."); + } + + Thread messageProcessorThread = new Thread() { + public void run() { + processIncomingMessage(mqttMessage, topic); + } + }; + messageProcessorThread.setDaemon(true); + messageProcessorThread.start(); + } + + /** + * Callback method which gets triggered upon successful completion of a message delivery to + * the broker. + * + * @param iMqttDeliveryToken the MQTT-DeliveryToken which includes the details about the + * specific message delivery. + */ + @Override + public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) { + String message = ""; + try { + if (iMqttDeliveryToken.isComplete()) { + if (iMqttDeliveryToken.getMessage() != null){ + message = iMqttDeliveryToken.getMessage().toString(); + } + } else { + log.error("MQTT Message not delivered"); + } + } catch (MqttException e) { + log.error( + "Error occurred whilst trying to read the message from the MQTT delivery token."); + } + String topic = iMqttDeliveryToken.getTopics()[0]; + String client = iMqttDeliveryToken.getClient().getClientId(); + + if (log.isDebugEnabled()) { + log.debug("Message - '" + message + "' of client [" + client + "] for the topic (" + + topic + ") was delivered successfully."); + } + } + + /** + * Closes the connection to the MQTT Broker. + */ + public void closeConnection() throws MqttException { + if (client != null && isConnected()) { + client.disconnect(); + } + } +} + diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.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.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/util/DigitalDisplayMqttCommunicationHandler.java new file mode 100644 index 0000000000..66529a9e0d --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/util/DigitalDisplayMqttCommunicationHandler.java @@ -0,0 +1,141 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.util; + +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.controlqueue.mqtt.MqttConfig; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport.CommunicationHandlerException; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport.MQTTCommunicationHandler; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.websocket.DigitalDisplayWebSocketServerEndPoint; + +import java.io.File; +import java.util.UUID; +import java.util.concurrent.ScheduledFuture; + + +public class DigitalDisplayMqttCommunicationHandler extends MQTTCommunicationHandler { + + private static Log log = LogFactory.getLog(DigitalDisplayMqttCommunicationHandler.class); + + private static final String subscribeTopic = + "wso2"+ File.separator+"iot"+File.separator+"+"+File.separator+ + DigitalDisplayConstants.DEVICE_TYPE+File.separator+"+"+File.separator+ + "digital_display_publisher"; + + private static String iotServerSubscriber = UUID.randomUUID().toString().substring(0,5); + + private ScheduledFuture dataPushServiceHandler; + + private DigitalDisplayMqttCommunicationHandler() { + super(iotServerSubscriber, DigitalDisplayConstants.DEVICE_TYPE, + MqttConfig.getInstance().getMqttQueueEndpoint(), subscribeTopic); + } + + public ScheduledFuture getDataPushServiceHandler() { + return dataPushServiceHandler; + } + + @Override + public void connect() { + Runnable connect = new Runnable() { + @Override + public void run() { + while (!isConnected()){ + try { + log.info("Trying to Connect.."); + connectToQueue(); + subscribeToQueue(); + + } catch (CommunicationHandlerException 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"); + } + } + } + + log.info("Connected.."); + + } + }; + + Thread connectorThread = new Thread(connect); + connectorThread.setDaemon(true); + connectorThread.start(); + + } + + @Override + public void processIncomingMessage(MqttMessage message, String... messageParams) { + + String topic = messageParams[0]; + + String ownerAndId = topic.replace("wso2"+File.separator+"iot"+File.separator,""); + ownerAndId = ownerAndId.replace(File.separator+ DigitalDisplayConstants.DEVICE_TYPE+File.separator,":"); + ownerAndId = ownerAndId.replace(File.separator+"digital_display_publisher",""); + + String owner = ownerAndId.split(":")[0]; + String deviceId = ownerAndId.split(":")[1]; + + String [] messageData = message.toString().split(":"); + + + log.info("Received MQTT message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}"); + + if(messageData.length == 3){ + String randomId = messageData[0]; + String requestMessage = messageData[1]; + String result = messageData[2]; + log.info("Return result " + result + " for Request " + requestMessage); + DigitalDisplayWebSocketServerEndPoint.sendMessage(randomId, result); + } + + } + + @Override + public void processIncomingMessage() { + + } + + public void publishToDigitalDisplay(String topic, String payLoad, int qos, boolean retained) throws CommunicationHandlerException { + log.info(topic + " " + payLoad); + publishToQueue(topic, payLoad, qos, retained); + } + + @Override + public void disconnect() { + Runnable stopConnection = new Runnable() { + public void run() { + while (isConnected()) { + try { + dataPushServiceHandler.cancel(true); + closeConnection(); + + } catch (MqttException e) { + if (log.isDebugEnabled()) { + log.warn("Unable to 'STOP' MQTT connection at broker at: " + + mqttBrokerEndPoint); + } + + try { + Thread.sleep(timeoutInterval); + } catch (InterruptedException e1) { + log.error("MQTT-Terminator: Thread Sleep Interrupt Exception"); + } + } + } + } + }; + + Thread terminatorThread = new Thread(stopConnection); + terminatorThread.setDaemon(true); + terminatorThread.start(); + } + +} diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/websocket/DigitalDisplayWebSocketServerEndPoint.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/websocket/DigitalDisplayWebSocketServerEndPoint.java new file mode 100644 index 0000000000..da49ebe17b --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/websocket/DigitalDisplayWebSocketServerEndPoint.java @@ -0,0 +1,74 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.websocket; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.inject.Singleton; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + + +@ServerEndpoint(value = "/digital-display-server-end-point") +@Singleton +public class DigitalDisplayWebSocketServerEndPoint { + + private static Log log = LogFactory.getLog(DigitalDisplayWebSocketServerEndPoint.class); + + private static Map clientSessions = new HashMap<>(); + + /** + * This method will be invoked when a client requests for a + * WebSocket connection. + * + * @param userSession the userSession which is opened. + */ + @OnOpen + public void onOpen(Session userSession){ + UUID uuid = UUID.randomUUID(); + log.info("Generated Random Id " + uuid.toString()); + log.info(" Connected with Session Id : " + userSession.getId()); + clientSessions.put(uuid.toString() , userSession); + userSession.getAsyncRemote().sendText("RandomID:" + uuid.toString()); + } + + /** + * This method will be invoked when a client closes a WebSocket + * connection. + * + * @param userSession the userSession which is opened. + */ + @OnClose + public void onClose(Session userSession){ + log.info("Client disconnected - Session Id : " + userSession.getId()); + clientSessions.values().remove(userSession); + + } + + @OnError + public void onError(Throwable t){ + log.error("Error occurred " + t ); + } + + /** + * This method will be invoked when a message received from device + * to send client. + * + * @param randomId the client of message to be sent. + * @param message the message sent by device to client + */ + public static void sendMessage(String randomId , String message){ + if(clientSessions.keySet().contains(randomId)){ + clientSessions.get(randomId).getAsyncRemote().sendText(message); + log.info("Message : " + message + " send to Session Id : " + randomId); + }else { + log.error("Client already disconnected."); + } + } + +} diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/META-INF/webapp-classloading.xml new file mode 100644 index 0000000000..fa44619195 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/META-INF/webapp-classloading.xml @@ -0,0 +1,33 @@ + + + + + + + + + false + + + CXF,Carbon + diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml new file mode 100644 index 0000000000..09e7f4b066 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..cd571f07d1 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,60 @@ + + + + Digital-Display-Agent-Webapp + + JAX-WS/JAX-RS MDM Android Endpoint + JAX-WS/JAX-RS Servlet + CXFServlet + + org.apache.cxf.transport.servlet.CXFServlet + + 1 + + + CXFServlet + /* + + + + + managed-api-enabled + false + + + managed-api-owner + admin + + + managed-api-context-template + /digital_display/{version} + + + managed-api-application + digital_display + + + managed-api-isSecured + true + + + diff --git a/components/device-mgt-iot-digitaldisplay/pom.xml b/components/device-mgt-iot-digitaldisplay/pom.xml index 945e867aa8..4a1d693dac 100644 --- a/components/device-mgt-iot-digitaldisplay/pom.xml +++ b/components/device-mgt-iot-digitaldisplay/pom.xml @@ -19,7 +19,8 @@ org.wso2.carbon.device.mgt.iot.digitaldisplay - org.wso2.carbon.device.mgt.iot.digitaldisplay.api + org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api + org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/database/AndroidSenseDM_DB.h2.db b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/database/AndroidSenseDM_DB.h2.db index b5fd6aa336049ae1d217587369bafe8c16965e74..7e93cc95738ee811270e30a321fac0a633264d68 100644 GIT binary patch delta 53 mcmZo@U~Fh$T)@HerKDvE0~km&Z5HHs&pt7L6|3MP2@L?PhYv{r delta 53 mcmZo@U~Fh$T)@F&Isf!h1~A}p+bqcOo_%5fD^|fp5*h%EcMd54 diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/database/ArduinoDM_DB.h2.db b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/database/ArduinoDM_DB.h2.db index 83aac0e4f97efba62cd0a2d92d5b18e8b875a3ab..2b5150d83d92c0ebac1cac9bfaad5dc8a5023888 100644 GIT binary patch delta 53 mcmZo@U~Fh$T)@GT)_VU80~m*Dh org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.digitaldisplay.api + org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api + 1.9.2-SNAPSHOT + war + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api 1.9.2-SNAPSHOT war @@ -79,7 +85,16 @@ org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.digitaldisplay.api + org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api + + war + true + ${basedir}/src/main/resources/webapps/ + digital_display_mgt.war + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api war true diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/database/DigitalDisplayDM_DB.h2.db b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/database/DigitalDisplayDM_DB.h2.db index 99cf2894804672c3454a8be01f592cde2688ea93..48ff20b776e655bb235802bff4a6579840884086 100644 GIT binary patch delta 53 mcmZo@U~Fh$T)@Gzm$fjR0SpA9HVbmRXP+3ridArtga!a-Jq-N- delta 53 mcmZo@U~Fh$T)@Gzq~eS_0~l}^Z5HHs&pt7L6|3MP2@L>*Dh*Dh*DhaRCQUqw2B63}7HqxLJ_nJ^RD}R;+@HBn$wJ{|-d} delta 53 mcmZpez}PT>aRCR9xczEw1~A|--7LuQo_%5fD^|fp5(WT4J`1k^ diff --git a/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/database/WSO2MobileWindows_DB.h2.db b/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/database/WSO2MobileWindows_DB.h2.db index ca0bd4ed551961dc3f5fd47572f5880f019b6946..1b6b8cb9545acaab18ce4242ab6401ebf6849ee6 100644 GIT binary patch delta 51 kcmZojXh>MV!SmwAp)U+zAd<0JkmEi3!~j;Tf{P?10MQl@hX4Qo delta 51 kcmZojXh>MV!Bcl=eGCH_aOi9n org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.digitaldisplay.api + org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api + ${carbon.iot.device.mgt.version} + war + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api ${carbon.iot.device.mgt.version} war