forked from community/device-mgt-plugins
Merge pull request #158 from GPrathap/IoTS-1.0.0-M1
separated APIs into manager and controllerIoTS-1.0.0-M1
commit
ca4b07b9b7
6
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 → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneRealTimeService.java
6
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 → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneRealTimeService.java
@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.droneanalyzer.service;
|
||||
|
||||
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.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.droneanalyzer.plugin.constants.DroneConstants;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.DroneController;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.impl.DroneControllerImpl;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.exception.DroneAnalyzerException;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.util.DroneAnalyzerServiceUtils;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.util.scep.ContentType;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.util.scep.SCEPOperation;
|
||||
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.util.ZipArchive;
|
||||
import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@API( name="drone_analyzer", version="1.0.0", context="/drone_analyzer")
|
||||
@DeviceType( value = "drone_analyzer")
|
||||
public class DroneService {
|
||||
|
||||
private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneService.class);
|
||||
private static final String SUPER_TENANT = "carbon.super";
|
||||
@Context //injected response proxy supporting multiple thread
|
||||
private HttpServletResponse response;
|
||||
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
||||
private DroneController droneController = new DroneControllerImpl();
|
||||
|
||||
/* ---------------------------------------------------------------------------------------
|
||||
Device specific APIs - Control APIs + Data-Publishing APIs
|
||||
Also contains utility methods required for the execution of these APIs
|
||||
--------------------------------------------------------------------------------------- */
|
||||
@Path("controller/register/{owner}/{deviceId}/{ip}/{port}")
|
||||
@POST
|
||||
public String registerDeviceIP(@PathParam("owner") String owner, @PathParam("deviceId") String deviceId,
|
||||
@PathParam("ip") String deviceIP,
|
||||
@PathParam("port") String devicePort,
|
||||
@Context HttpServletResponse response,
|
||||
@Context HttpServletRequest request) {
|
||||
String result;
|
||||
log.info("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId +
|
||||
" of owner: " + owner);
|
||||
String deviceHttpEndpoint = deviceIP + ":" + devicePort;
|
||||
deviceToIpMap.put(deviceId, deviceHttpEndpoint);
|
||||
result = "Device-IP Registered";
|
||||
response.setStatus(Response.Status.OK.getStatusCode());
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(result);
|
||||
}
|
||||
log.info(owner + deviceId + deviceIP + devicePort );
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Path("controller/send_command")
|
||||
@POST
|
||||
@Feature( code="send_command", name="Send Command", type="operation",
|
||||
description="Send Commands to Drone")
|
||||
public Response droneController(@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId,
|
||||
@QueryParam("action") String action, @QueryParam("duration") String duration,
|
||||
@QueryParam("speed") String speed){
|
||||
try {
|
||||
DeviceValidator deviceValidator = new DeviceValidator();
|
||||
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId,
|
||||
DroneConstants.DEVICE_TYPE))) {
|
||||
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("DeviceValidation Failed for deviceId: " + deviceId + " of user: " + owner);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||
}
|
||||
try {
|
||||
DroneAnalyzerServiceUtils.sendControlCommand(droneController, deviceId, action, Double.valueOf(speed),
|
||||
Double.valueOf(duration));
|
||||
return Response.status(Response.Status.ACCEPTED).build();
|
||||
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Drone command didn't success. Try again, \n"+ e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("controller/scep")
|
||||
public Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Invoking SCEP operation " + operation);
|
||||
}
|
||||
if (SCEPOperation.GET_CA_CERT.getValue().equals(operation)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Invoking GetCACert");
|
||||
}
|
||||
try {
|
||||
CertificateManagementService certificateManagementService =
|
||||
DroneAnalyzerServiceUtils.getCertificateManagementService();
|
||||
SCEPResponse scepResponse = certificateManagementService.getCACertSCEP();
|
||||
Response.ResponseBuilder responseBuilder;
|
||||
switch (scepResponse.getResultCriteria()) {
|
||||
case CA_CERT_FAILED:
|
||||
log.error("CA cert failed");
|
||||
responseBuilder = Response.serverError();
|
||||
break;
|
||||
case CA_CERT_RECEIVED:
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("CA certificate received in GetCACert");
|
||||
}
|
||||
responseBuilder = Response.ok(scepResponse.getEncodedResponse(),
|
||||
ContentType.X_X509_CA_CERT);
|
||||
break;
|
||||
case CA_RA_CERT_RECEIVED:
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("CA and RA certificates received in GetCACert");
|
||||
}
|
||||
responseBuilder = Response.ok(scepResponse.getEncodedResponse(),
|
||||
ContentType.X_X509_CA_RA_CERT);
|
||||
break;
|
||||
default:
|
||||
log.error("Invalid SCEP request");
|
||||
responseBuilder = Response.serverError();
|
||||
break;
|
||||
}
|
||||
return responseBuilder.build();
|
||||
} catch (DroneAnalyzerException e) {
|
||||
log.error("Error occurred while enrolling the drone device", e);
|
||||
} catch (KeystoreException e) {
|
||||
log.error("Keystore error occurred while enrolling the drone device", e);
|
||||
}
|
||||
|
||||
} else if (SCEPOperation.GET_CA_CAPS.getValue().equals(operation)) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Invoking GetCACaps");
|
||||
}
|
||||
|
||||
try {
|
||||
CertificateManagementService certificateManagementService = DroneAnalyzerServiceUtils.
|
||||
getCertificateManagementService();
|
||||
byte caCaps[] = certificateManagementService.getCACapsSCEP();
|
||||
return Response.ok(caCaps, MediaType.TEXT_PLAIN).build();
|
||||
} catch (DroneAnalyzerException e) {
|
||||
log.error("Error occurred while enrolling the device", e);
|
||||
}
|
||||
|
||||
} else {
|
||||
log.error("Invalid SCEP operation " + operation);
|
||||
}
|
||||
|
||||
return Response.serverError().build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("controller/scep")
|
||||
public Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Invoking SCEP operation " + operation);
|
||||
}
|
||||
|
||||
if (SCEPOperation.PKI_OPERATION.getValue().equals(operation)) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Invoking PKIOperation");
|
||||
}
|
||||
try {
|
||||
CertificateManagementService certificateManagementService = DroneAnalyzerServiceUtils.
|
||||
getCertificateManagementService();
|
||||
byte pkiMessage[] = certificateManagementService.getPKIMessageSCEP(inputStream);
|
||||
return Response.ok(pkiMessage, ContentType.X_PKI_MESSAGE).build();
|
||||
|
||||
} catch (DroneAnalyzerException e) {
|
||||
log.error("Error occurred while enrolling the device", e);
|
||||
} catch (KeystoreException e) {
|
||||
log.error("Keystore error occurred while enrolling the device", e);
|
||||
}
|
||||
}
|
||||
return Response.serverError().build();
|
||||
}
|
||||
}
|
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/exception/DroneAnalyzerException.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/exception/DroneAnalyzerException.java
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/exception/DroneAnalyzerException.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/exception/DroneAnalyzerException.java
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/transport/DroneAnalyzerXMPPConnector.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/transport/DroneAnalyzerXMPPConnector.java
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/transport/DroneAnalyzerXMPPConnector.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/transport/DroneAnalyzerXMPPConnector.java
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/trasformer/MessageTransformer.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/trasformer/MessageTransformer.java
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/trasformer/MessageTransformer.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/trasformer/MessageTransformer.java
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/DroneAnalyzerServiceUtils.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/DroneAnalyzerServiceUtils.java
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/DroneAnalyzerServiceUtils.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/DroneAnalyzerServiceUtils.java
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/scep/ContentType.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/scep/ContentType.java
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/scep/ContentType.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/scep/ContentType.java
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/scep/SCEPOperation.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/scep/SCEPOperation.java
0
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/scep/SCEPOperation.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/util/scep/SCEPOperation.java
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
|
||||
<jaxrs:server id="DroneAnalyzer" address="/">
|
||||
<jaxrs:features>
|
||||
<cxf:logging/>
|
||||
</jaxrs:features>
|
||||
<jaxrs:serviceBeans>
|
||||
<bean id="DroneService" class="org.wso2.carbon.device.mgt.iot.droneanalyzer.service.DroneService">
|
||||
<!--<property name="DroneXMPPConnector" ref="xmppConnectorBean"/>-->
|
||||
</bean>
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
|
||||
</jaxrs:providers>
|
||||
</jaxrs:server>
|
||||
</beans>
|
||||
|
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<web-app version="2.5"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
metadata-complete="true">
|
||||
<display-name>WSO2 IoT Server</display-name>
|
||||
<description>WSO2 IoT Server</description>
|
||||
<servlet>
|
||||
<servlet-name>CXFServlet</servlet-name>
|
||||
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>CXFServlet</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<context-param>
|
||||
<param-name>isAdminService</param-name>
|
||||
<param-value>false</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>doAuthentication</param-name>
|
||||
<param-value>false</param-value>
|
||||
</context-param>
|
||||
|
||||
<!--publish to apim-->
|
||||
<context-param>
|
||||
<param-name>managed-api-enabled</param-name>
|
||||
<param-value>true</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>managed-api-owner</param-name>
|
||||
<param-value>admin</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>managed-api-context-template</param-name>
|
||||
<param-value>/drone_analyzer/{version}</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>managed-api-application</param-name>
|
||||
<param-value>drone_analyzer</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>managed-api-isSecured</param-name>
|
||||
<param-value>true</param-value>
|
||||
</context-param>
|
||||
</web-app>
|
@ -0,0 +1,253 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>device-mgt-iot-droneanalyzer</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||
<version>1.9.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.mgt.iot.droneanalyzer.mgt.api</artifactId>
|
||||
<version>1.9.2-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>WSO2 Carbon - IoT Server Drone Analyzer Manager API</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<dependencies>
|
||||
<!-- CDM -->
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.axis2.wso2</groupId>
|
||||
<artifactId>axis2-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.analytics</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.axis2.wso2</groupId>
|
||||
<artifactId>axis2-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-codec.wso2</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--CXF -->
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-transports-http</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--MQTT -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>mqtt-client</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--Spring -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--IOT -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpasyncclient</artifactId>
|
||||
<version>4.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.iot</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.iot.droneanalyzer</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--JAX-RS -->
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-core-asl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-jaxrs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-web-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-httpclient.wso2</groupId>
|
||||
<artifactId>commons-httpclient</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle.wso2</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.user.api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.queuing</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.base</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.axis2.wso2</groupId>
|
||||
<artifactId>axis2</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.igniterealtime.smack.wso2</groupId>
|
||||
<artifactId>smack</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.igniterealtime.smack.wso2</groupId>
|
||||
<artifactId>smackx</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>jaxen</groupId>
|
||||
<artifactId>jaxen</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>commons-fileupload.wso2</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.ant.wso2</groupId>
|
||||
<artifactId>ant</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.ant.wso2</groupId>
|
||||
<artifactId>ant</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>commons-httpclient.wso2</groupId>
|
||||
<artifactId>commons-httpclient</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.equinox</groupId>
|
||||
<artifactId>javax.servlet</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.registry.api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.igniterealtime.smack.wso2</groupId>
|
||||
<artifactId>smack</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.igniterealtime.smack.wso2</groupId>
|
||||
<artifactId>smackx</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>4.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>${wso2.maven.compiler.source}</source>
|
||||
<target>${wso2.maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
|
||||
<warName>drone_analyzer_mgt</warName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
64
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneService.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneService.java
64
components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneService.java → components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneService.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.droneanalyzer.service.exception;
|
||||
|
||||
public class DroneAnalyzerException extends Exception {
|
||||
private static final long serialVersionUID = 118512086958330189L;
|
||||
|
||||
public DroneAnalyzerException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
public DroneAnalyzerException(String errorMessage, Throwable throwable) {
|
||||
super(errorMessage, throwable);
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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.droneanalyzer.service.transport;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
|
||||
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConnector;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.trasformer.MessageTransformer;
|
||||
|
||||
public class DroneAnalyzerXMPPConnector extends XmppConnector {
|
||||
private static Log log = LogFactory.getLog(DroneAnalyzerXMPPConnector.class);
|
||||
|
||||
private static String xmppServerIP;
|
||||
private static int xmppServerPort;
|
||||
private static String xmppAdminUsername;
|
||||
private static String xmppAdminPassword;
|
||||
private static String xmppAdminAccountJID;
|
||||
private MessageTransformer messageTransformer;
|
||||
|
||||
public DroneAnalyzerXMPPConnector(MessageTransformer messageTransformer) {
|
||||
super(XmppConfig.getInstance().getXmppServerIP(),
|
||||
XmppConfig.getInstance().getSERVER_CONNECTION_PORT());
|
||||
this.messageTransformer = messageTransformer;
|
||||
|
||||
}
|
||||
|
||||
public void initConnector() {
|
||||
xmppServerIP = XmppConfig.getInstance().getXmppServerIP();
|
||||
xmppAdminUsername = XmppConfig.getInstance().getXmppUsername();
|
||||
xmppAdminPassword = XmppConfig.getInstance().getXmppPassword();
|
||||
xmppAdminAccountJID = xmppAdminUsername + "@" + xmppServerIP;
|
||||
}
|
||||
|
||||
public void connectAndLogin() {
|
||||
try {
|
||||
super.connectAndLogin(xmppAdminUsername, xmppAdminPassword, null);
|
||||
super.setMessageFilterOnReceiver(xmppAdminAccountJID);
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Connect/Login attempt to XMPP Server at: " + xmppServerIP + " failed");
|
||||
retryXMPPConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMessageFilterOnReceiver(String receiver){
|
||||
super.setMessageFilterOnReceiver( receiver+ "@" + xmppServerIP);
|
||||
}
|
||||
|
||||
public void connectLoginAndSetFilterOnReceiver(){
|
||||
initConnector();
|
||||
connectAndLogin();
|
||||
setMessageFilterOnReceiver(DroneConstants.DEVICE_ID);
|
||||
}
|
||||
|
||||
public void disconnect(){
|
||||
super.closeConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processXMPPMessage(Message xmppMessage) {
|
||||
String from = xmppMessage.getFrom();
|
||||
String subject = xmppMessage.getSubject();
|
||||
String inbound_message = xmppMessage.getBody();
|
||||
int indexOfAt = from.indexOf("@");
|
||||
int indexOfSlash = from.indexOf("/");
|
||||
String deviceId = from.substring(0, indexOfAt);
|
||||
String resource = from.substring(indexOfSlash + 1, from.length());
|
||||
|
||||
|
||||
|
||||
if ((inbound_message != null)&&(resource.equals(DroneConstants.MESSAGE_RESOURCE)) ){
|
||||
messageTransformer.messageTranslater(inbound_message);
|
||||
}
|
||||
else {
|
||||
log.error("Message is empty or it is not belongs to "+ DroneConstants.DEVICE_ID);
|
||||
}
|
||||
}
|
||||
|
||||
private void retryXMPPConnection() {
|
||||
Thread retryToConnect = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
if (!isConnected()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Re-trying to reach XMPP Server....");
|
||||
}
|
||||
try {
|
||||
DroneAnalyzerXMPPConnector.super.connectAndLogin(xmppAdminUsername, xmppAdminPassword, null);
|
||||
DroneAnalyzerXMPPConnector.super.setMessageFilterOnReceiver(xmppAdminAccountJID);
|
||||
} catch (DeviceManagementException e1) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Attempt to re-connect to XMPP-Server failed");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e1) {
|
||||
log.error("XMPP: Thread Sleep Interrupt Exception");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
retryToConnect.setDaemon(true);
|
||||
retryToConnect.start();
|
||||
}
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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.droneanalyzer.service.trasformer;
|
||||
|
||||
|
||||
import org.apache.commons.collections4.queue.CircularFifoQueue;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.codehaus.jackson.JsonNode;
|
||||
import org.codehaus.jackson.JsonProcessingException;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.MessageConfig;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class MessageTransformer {
|
||||
|
||||
private Log log = LogFactory.getLog(MessageTransformer.class);
|
||||
private CircularFifoQueue<String> sharedQueue;
|
||||
|
||||
private String outbound_message_format_for_simulator = "{\"quatanium_val\":[%f, %f, %f, %f]," +
|
||||
"\"basicParam\":{\"velocity\":[%f, %f, %f], \"global_location\":[%f, %f, %f]},\"battery_level\":%f, \"device_type\":\"IRIS_DRONE\"}";
|
||||
private String outbound_message_format_for_iris_drone = "{\"quatanium_val\":[%f, %f, %f]," +
|
||||
"\"basicParam\":{\"velocity\":[%f, %f, %f], \"global_location\":[%f, %f, %f]},\"battery_level\":%f," +
|
||||
"\"device_type\":\"SIMULATOR\"}";
|
||||
|
||||
public MessageTransformer(){
|
||||
sharedQueue = new CircularFifoQueue<String>(DroneConstants.MAXIMUM_BUFFERE_SIZE_OF_SHARED_QUEUE);
|
||||
}
|
||||
|
||||
private void messageTranslaterForSimulator(JsonNode inbound_message){
|
||||
JsonNode node = inbound_message;
|
||||
String outbound_message;
|
||||
|
||||
try {
|
||||
JsonNode velocity = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(MessageConfig.OUT_BASIC_PARAM_VELOCITY);
|
||||
JsonNode global_location = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(
|
||||
MessageConfig.OUT_BASIC_PARAM_GLOBAL_LOCATION);
|
||||
JsonNode quatanium_vals = node.get(MessageConfig.OUT_QUATANNIM_VAL);
|
||||
JsonNode battery_level = node.get(MessageConfig.OUT_BATTERY_LEVEL);
|
||||
outbound_message = String.format(outbound_message_format_for_simulator, sTd(quatanium_vals.get(0)),
|
||||
sTd(quatanium_vals.get(1)), sTd(quatanium_vals.get(2)), sTd(quatanium_vals.get(0)),
|
||||
sTd(velocity.get(0)), sTd(velocity.get(1)), sTd(velocity.get(2)), sTd(global_location.get(0)),
|
||||
sTd(global_location.get(1)), sTd(global_location.get(2)), sTd(battery_level));
|
||||
sharedQueue.add(outbound_message);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage()+",\n"+ e);
|
||||
}
|
||||
}
|
||||
|
||||
private void messageTranslaterForIRISDrone(JsonNode inbound_message){
|
||||
JsonNode node = inbound_message;
|
||||
String outbound_message;
|
||||
try {
|
||||
|
||||
JsonNode velocity = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(MessageConfig.OUT_BASIC_PARAM_VELOCITY);
|
||||
JsonNode global_location = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(
|
||||
MessageConfig.OUT_BASIC_PARAM_GLOBAL_LOCATION);
|
||||
JsonNode quatanium_vals = node.get(MessageConfig.OUT_QUATANNIM_VAL);
|
||||
JsonNode battery_level = node.get(MessageConfig.OUT_BATTERY_LEVEL);
|
||||
outbound_message = String.format(outbound_message_format_for_iris_drone, sTd(quatanium_vals.get(0)),
|
||||
sTd(quatanium_vals.get(1)), sTd(quatanium_vals.get(2)), sTd(velocity.get(0)),
|
||||
sTd(velocity.get(1)), sTd(velocity.get(2)), sTd(global_location.get(0)),
|
||||
sTd(global_location.get(1)), sTd(global_location.get(2)), sTd(battery_level));
|
||||
sharedQueue.add(outbound_message);
|
||||
|
||||
}catch (Exception e) {
|
||||
log.error(e.getMessage()+",\n"+ e);
|
||||
}
|
||||
}
|
||||
|
||||
public void messageTranslater(String inbound_message){
|
||||
JsonNode actualMessage = null;
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
try {
|
||||
actualMessage = objectMapper.readValue(inbound_message, JsonNode.class);
|
||||
JsonNode deviceType = actualMessage.get(MessageConfig.IN_DEVICE_TYPE);
|
||||
switch (deviceType.getTextValue()) {
|
||||
|
||||
case MessageConfig.IN_IRIS_DRONE:
|
||||
messageTranslaterForIRISDrone(actualMessage);
|
||||
break;
|
||||
case MessageConfig.IN_SIMULATOR:
|
||||
messageTranslaterForSimulator(actualMessage);
|
||||
break;
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Incoming message might be corrupted, "+ e);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private double sTd(JsonNode s)
|
||||
{
|
||||
return Double.parseDouble(s.toString());
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
try{
|
||||
if(sharedQueue.isEmpty() || sharedQueue == null){
|
||||
return "";
|
||||
}
|
||||
return sharedQueue.remove();
|
||||
}catch(Exception e) {
|
||||
log.error("There is no more messages to send or internal server error has been occurred, \n"+ e );
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmptyQueue(){
|
||||
return sharedQueue != null? sharedQueue.isEmpty():false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
|
||||
/*
|
||||
* 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.droneanalyzer.service.util;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
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.controlqueue.xmpp.XmppConfig;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.DroneController;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.impl.DroneControllerImpl;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.exception.DroneAnalyzerException;
|
||||
import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.transport.DroneAnalyzerXMPPConnector;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DroneAnalyzerServiceUtils {
|
||||
|
||||
private static final String SUPER_TENANT = "carbon.super";
|
||||
private static final String TEMPERATURE_STREAM_DEFINITION = "org.wso2.iot.devices.temperature";
|
||||
private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneAnalyzerServiceUtils.class);
|
||||
|
||||
public static void sendCommandViaXMPP(String deviceOwner, String deviceId, String resource,
|
||||
String state, DroneAnalyzerXMPPConnector droneXMPPConnector)
|
||||
throws DeviceManagementException {
|
||||
|
||||
String xmppServerDomain = XmppConfig.getInstance().getXmppEndpoint();
|
||||
int indexOfChar = xmppServerDomain.lastIndexOf(File.separator);
|
||||
if (indexOfChar != -1) {
|
||||
xmppServerDomain = xmppServerDomain.substring((indexOfChar + 1),
|
||||
xmppServerDomain.length());
|
||||
}
|
||||
indexOfChar = xmppServerDomain.indexOf(":");
|
||||
if (indexOfChar != -1) {
|
||||
xmppServerDomain = xmppServerDomain.substring(0, indexOfChar);
|
||||
}
|
||||
String clientToConnect = deviceId + "@" + xmppServerDomain + File.separator + deviceOwner;
|
||||
String message = resource.replace("/", "") + ":" + state;
|
||||
droneXMPPConnector.sendXMPPMessage(clientToConnect, message, "CONTROL-REQUEST");
|
||||
|
||||
}
|
||||
|
||||
public static boolean sendControlCommand(DroneController controller, String deviceId, String action, double speed, double duration)
|
||||
throws DeviceManagementException {
|
||||
boolean control_state = false;
|
||||
try{
|
||||
switch (action){
|
||||
case DroneConstants.TAKE_OFF:
|
||||
control_state = controller.takeoff();
|
||||
break;
|
||||
case DroneConstants.LAND:
|
||||
control_state = controller.land();
|
||||
break;
|
||||
case DroneConstants.BACK:
|
||||
control_state = controller.back(speed, duration);
|
||||
break;
|
||||
case DroneConstants.CLOCK_WISE:
|
||||
control_state = controller.clockwise(speed, duration);
|
||||
break;
|
||||
case DroneConstants.COUNTER_CLOCKWISE:
|
||||
control_state = controller.conterClockwise(speed, duration);
|
||||
break;
|
||||
case DroneConstants.DOWN:
|
||||
control_state = controller.down(speed, duration);
|
||||
break;
|
||||
case DroneConstants.FRONT:
|
||||
control_state = controller.back(speed, duration);
|
||||
break;
|
||||
case DroneConstants.FORWARD:
|
||||
control_state = controller.clockwise(speed, duration);
|
||||
break;
|
||||
case DroneConstants.UP:
|
||||
control_state = controller.up(speed, duration);
|
||||
break;
|
||||
}
|
||||
}catch(Exception e){
|
||||
log.error(e.getMessage()+ "\n"+ e);
|
||||
}
|
||||
return control_state;
|
||||
}
|
||||
|
||||
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, DroneConstants.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 CertificateManagementService getCertificateManagementService() throws
|
||||
DroneAnalyzerException {
|
||||
|
||||
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 DroneAnalyzerException(msg);
|
||||
}
|
||||
|
||||
return certificateManagementService;
|
||||
}
|
||||
|
||||
}
|
@ -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.droneanalyzer.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";
|
||||
}
|
||||
|
@ -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.droneanalyzer.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;
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<!-- This file contains the list of permissions that are associated with URL end points
|
||||
of the web app. Each permission should contain the name, permission path ,API path
|
||||
(URL) , HTTP method and OAUTH2 authorization scope (not-required).
|
||||
When defining dynamic paths for APIs, path variables are denoted by '*' notation.
|
||||
For ex:
|
||||
Actual API endpoint: mdm-admin/1.0.0/devices/{device-id}
|
||||
URL to be represented here: /devices/*
|
||||
NOTE: All the endpoints of the web app should be available in this file. Otherwise
|
||||
it will result 403 error at the runtime.
|
||||
-->
|
||||
<ResourceConfiguration>
|
||||
<!-- Device related APIs -->
|
||||
<Resource>
|
||||
<AuthType>Any</AuthType>
|
||||
<HttpVerb>PUT</HttpVerb>
|
||||
<Uri>http://localhost:9763/drone_analyzer/manager/device/register</Uri>
|
||||
<UriTemplate>/manager/device/register/*</UriTemplate>
|
||||
</Resource>
|
||||
<Resource>
|
||||
<AuthType>Any</AuthType>
|
||||
<HttpVerb>DELETE</HttpVerb>
|
||||
<Uri>http://localhost:9763/drone_analyzer/manager/device/remove</Uri>
|
||||
<UriTemplate>/manager/device/remove/*</UriTemplate>
|
||||
</Resource>
|
||||
<Resource>
|
||||
<AuthType>Any</AuthType>
|
||||
<HttpVerb>POST</HttpVerb>
|
||||
<Uri>http://localhost:9763/drone_analyzer/manager/device/update</Uri>
|
||||
<UriTemplate>/manager/device/update/*</UriTemplate>
|
||||
</Resource>
|
||||
<Resource>
|
||||
<AuthType>Any</AuthType>
|
||||
<HttpVerb>GET</HttpVerb>
|
||||
<Uri>http://localhost:9763/drone_analyzer/manager/device</Uri>
|
||||
<UriTemplate>/manager/device/*</UriTemplate>
|
||||
</Resource>
|
||||
<Resource>
|
||||
<AuthType>Any</AuthType>
|
||||
<HttpVerb>GET</HttpVerb>
|
||||
<Uri>http://localhost:9763/drone_analyzer/manager/devices</Uri>
|
||||
<UriTemplate>/manager/devices/*</UriTemplate>
|
||||
</Resource>
|
||||
<Resource>
|
||||
<AuthType>Any</AuthType>
|
||||
<HttpVerb>GET</HttpVerb>
|
||||
<Uri>http://localhost:9763/drone_analyzer/manager/device/{sketch_type}/download</Uri>
|
||||
<UriTemplate>/manager/device/{sketch_type}/download</UriTemplate>
|
||||
</Resource>
|
||||
<Resource>
|
||||
<AuthType>Any</AuthType>
|
||||
<HttpVerb>GET</HttpVerb>
|
||||
<Uri>http://localhost:9763/drone_analyzer/manager/device/{sketch_type}/generate_link</Uri>
|
||||
<UriTemplate>/manager/device/{sketch_type}/generate_link</UriTemplate>
|
||||
</Resource>
|
||||
|
||||
<Resource>
|
||||
<AuthType>Any</AuthType>
|
||||
<HttpVerb>POST</HttpVerb>
|
||||
<Uri>http://localhost:9763/drone_analyzer/controller/register/{owner}/{deviceId}/{ip}/{port}</Uri>
|
||||
<UriTemplate>/controller/register/{owner}/{deviceId}/{ip}/{port}</UriTemplate>
|
||||
</Resource>
|
||||
<Resource>
|
||||
<AuthType>Any</AuthType>
|
||||
<HttpVerb>GET</HttpVerb>
|
||||
<Uri>http://localhost:9763/drone_analyzer/controller/send_command</Uri>
|
||||
<UriTemplate>/controller/send_command</UriTemplate>
|
||||
</Resource>
|
||||
</ResourceConfiguration>
|
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!--
|
||||
~ Copyright 2005-2013 WSO2, Inc. (http://wso2.com)
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<!--
|
||||
This file defines class loading policy of the whole container. But this behaviour can be overridden by individual webapps by putting this file into the META-INF/ directory.
|
||||
-->
|
||||
<Classloading xmlns="http://wso2.org/projects/as/classloading">
|
||||
|
||||
<!-- Parent-first or child-first. Default behaviour is child-first.-->
|
||||
<ParentFirst>false</ParentFirst>
|
||||
|
||||
<!--
|
||||
Default environments that contains provides to all the webapps. This can be overridden by individual webapps by specifing required environments
|
||||
Tomcat environment is the default and every webapps gets it even if they didn't specify it.
|
||||
e.g. If a webapps requires CXF, they will get both Tomcat and CXF.
|
||||
-->
|
||||
<Environments>CXF,Carbon</Environments>
|
||||
</Classloading>
|
Loading…
Reference in new issue