Refactored VirtualFirealarm Service pertaining to the Service APIs of this device-type

Shabirmean 9 years ago
parent bd924c530f
commit 2e0bb166d2

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
@ -11,48 +11,36 @@
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service; package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.device.DeviceType; import org.wso2.carbon.apimgt.annotations.device.DeviceType;
import org.wso2.carbon.apimgt.annotations.device.feature.Feature; 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.dto.SCEPResponse;
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; 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.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; 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.DeviceValidator;
import org.wso2.carbon.device.mgt.iot.apimgt.AccessTokenInfo;
import org.wso2.carbon.device.mgt.iot.apimgt.TokenClient;
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient;
import org.wso2.carbon.device.mgt.iot.exception.AccessTokenException;
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord;
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.dto.DeviceJSON; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.dto.DeviceJSON;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmMQTTConnector; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmMQTTConnector;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmXMPPConnector; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmXMPPConnector;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VerificationManager; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.SecurityManager;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.scep.ContentType; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.scep.ContentType;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.scep.SCEPOperation; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.scep.SCEPOperation;
@ -60,12 +48,10 @@ import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.scep.SCEPOpe
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam; import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
@ -73,21 +59,21 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/**
* This class consists the functions/APIs specific to the "actions" of the VirtualFirealarm device-type. These APIs
* include the ones that are used by the [Device] to contact the server (i.e: Enrollment & Publishing Data) and the
* ones used by the [Server/Owner] to contact the [Device] (i.e: sending control signals). This class also initializes
* the transport 'Connectors' [XMPP & MQTT] specific to the VirtualFirealarm device-type in order to communicate with
* such devices and to receive messages form it.
*/
@API(name = "virtual_firealarm", version = "1.0.0", context = "/virtual_firealarm") @API(name = "virtual_firealarm", version = "1.0.0", context = "/virtual_firealarm")
@DeviceType(value = "virtual_firealarm") @DeviceType(value = "virtual_firealarm")
@SuppressWarnings("Non-Annoted WebService")
public class VirtualFireAlarmService { public class VirtualFireAlarmService {
private static Log log = LogFactory.getLog(VirtualFireAlarmService.class); private static Log log = LogFactory.getLog(VirtualFireAlarmService.class);
//TODO; replace this tenant domain //TODO; replace this tenant domain
@ -95,30 +81,39 @@ public class VirtualFireAlarmService {
@Context //injected response proxy supporting multiple thread @Context //injected response proxy supporting multiple thread
private HttpServletResponse response; private HttpServletResponse response;
private static final String XMPP_PROTOCOL = "XMPP";
private static final String HTTP_PROTOCOL = "HTTP";
private static final String MQTT_PROTOCOL = "MQTT";
public static final String XMPP_PROTOCOL = "XMPP"; // consists of utility methods related to encrypting and decrypting messages
public static final String HTTP_PROTOCOL = "HTTP"; private SecurityManager securityManager;
public static final String MQTT_PROTOCOL = "MQTT"; // connects to the given MQTT broker and handles MQTT communication
private VerificationManager verificationManager;
private VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector; private VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector;
// connects to the given XMPP server and handles XMPP communication
private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector; private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector;
// holds a mapping of the IP addresses to Device-IDs for HTTP communication
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>(); private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
/** /**
* @param verificationManager * Sets the `securityManager` variable of this VirtualFirealarm controller service.
*
* @param securityManager a 'SecurityManager' object that handles the encryption, decryption, signing and validation
* of incoming messages from VirtualFirealarm device-types.
*/ */
public void setVerificationManager( @SuppressWarnings("Unused")
VerificationManager verificationManager) { public void setSecurityManager(SecurityManager securityManager) {
this.verificationManager = verificationManager; this.securityManager = securityManager;
verificationManager.initVerificationManager(); securityManager.initVerificationManager();
} }
/** /**
* @param virtualFireAlarmXMPPConnector * Sets the `virtualFireAlarmXMPPConnector` variable of this VirtualFirealarm controller service.
*
* @param virtualFireAlarmXMPPConnector a 'VirtualFireAlarmXMPPConnector' object that handles all XMPP related
* communications of any connected VirtualFirealarm device-type
*/ */
public void setVirtualFireAlarmXMPPConnector( @SuppressWarnings("Unused")
final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) { public void setVirtualFireAlarmXMPPConnector(final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) {
this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector; this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector;
if (XmppConfig.getInstance().isEnabled()) { if (XmppConfig.getInstance().isEnabled()) {
@ -134,72 +129,88 @@ public class VirtualFireAlarmService {
xmppStarterThread.setDaemon(true); xmppStarterThread.setDaemon(true);
xmppStarterThread.start(); xmppStarterThread.start();
} else { } else {
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started."); log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started.");
} }
} }
/** /**
* @param virtualFireAlarmMQTTConnector * Sets the `virtualFireAlarmMQTTConnector` variable of this VirtualFirealarm controller service.
*
* @param virtualFireAlarmMQTTConnector a 'VirtualFireAlarmMQTTConnector' object that handles all MQTT related
* communications of any connected VirtualFirealarm device-type
*/ */
@SuppressWarnings("Unused")
public void setVirtualFireAlarmMQTTConnector( public void setVirtualFireAlarmMQTTConnector(
final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) { final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) {
this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector; this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector;
if (MqttConfig.getInstance().isEnabled()) { if (MqttConfig.getInstance().isEnabled()) {
virtualFireAlarmMQTTConnector.connect(); virtualFireAlarmMQTTConnector.connect();
} else { } else {
log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started."); log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started.");
} }
} }
/** /**
* @return * Fetches the `SecurityManager` specific to this VirtualFirealarm controller service.
*
* @return the 'SecurityManager' instance bound to the 'securityManager' variable of this service.
*/ */
public VerificationManager getVerificationManager() { @SuppressWarnings("Unused")
return verificationManager; public SecurityManager getSecurityManager() {
return securityManager;
} }
/** /**
* @return * Fetches the `VirtualFireAlarmXMPPConnector` specific to this VirtualFirealarm controller service.
*
* @return the 'VirtualFireAlarmXMPPConnector' instance bound to the 'virtualFireAlarmXMPPConnector' variable of
* this service.
*/ */
@SuppressWarnings("Unused")
public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() { public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() {
return virtualFireAlarmXMPPConnector; return virtualFireAlarmXMPPConnector;
} }
/** /**
* @return * Fetches the `VirtualFireAlarmMQTTConnector` specific to this VirtualFirealarm controller service.
*
* @return the 'VirtualFireAlarmMQTTConnector' instance bound to the 'virtualFireAlarmMQTTConnector' variable of
* this service.
*/ */
@SuppressWarnings("Unused")
public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() { public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() {
return virtualFireAlarmMQTTConnector; return virtualFireAlarmMQTTConnector;
} }
/* ---------------------------------------------------------------------------------------
Device specific APIs - Control APIs + Data-Publishing APIs
Also contains utility methods required for the execution of these APIs
--------------------------------------------------------------------------------------- */
/** /**
* @param owner * This is an API used/called by the device. It registers the IP of a VirtualFirealarm device against its DeviceID
* @param deviceId * when the device connects with the server for the first time. This DeviceID to IP mapping is necessary only for
* @param deviceIP * cases where HTTP communication is to be used. At such instances, this mapping is used by the server to
* @param devicePort * identify the IP of the device to which it has some message to be sent. This method becomes useful only in
* @param response * scenarios where HTTP communication is used in a setup where the IoT-Server and the devices communicating with it
* @param request * are in the same IP network.
* @return *
* @param owner the name of the owner(username) of the device from which this register-IP call was initiated.
* @param deviceId the ID of the VirtualFirealarm device from which this register-IP call was initiated.
* @param deviceIP the IP of the VirtualFirealarm device which has sent this register-IP request.
* @param devicePort the PORT on the VirtualFirealarm device (on this IP) that's open for HTTP communication.
* @param request the HTTP servlet request object received by default as part of the HTTP call to this API.
* @param response the HTTP servlet response object received by default as part of the HTTP call to this API.
* @return a custom message indicating whether the DeviceID to IP mapping was successful.
*/ */
@Path("controller/register/{owner}/{deviceId}/{ip}/{port}")
@POST @POST
@Path("controller/register/{owner}/{deviceId}/{ip}/{port}")
public String registerDeviceIP(@PathParam("owner") String owner, public String registerDeviceIP(@PathParam("owner") String owner,
@PathParam("deviceId") String deviceId, @PathParam("deviceId") String deviceId,
@PathParam("ip") String deviceIP, @PathParam("ip") String deviceIP,
@PathParam("port") String devicePort, @PathParam("port") String devicePort,
@Context HttpServletResponse response, @Context HttpServletRequest request,
@Context HttpServletRequest request) { @Context HttpServletResponse response) {
//TODO:: Need to get IP from the request itself and have a mapping to owner
//TODO:: Need to get IP from the request itself
String result; String result;
if (log.isDebugEnabled()) {
log.info("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + " of owner: " + owner);
" of owner: " + owner); }
String deviceHttpEndpoint = deviceIP + ":" + devicePort; String deviceHttpEndpoint = deviceIP + ":" + devicePort;
deviceToIpMap.put(deviceId, deviceHttpEndpoint); deviceToIpMap.put(deviceId, deviceHttpEndpoint);
@ -214,20 +225,22 @@ public class VirtualFireAlarmService {
return result; return result;
} }
/* Service to switch "ON" and "OFF" the Virtual FireAlarm bulb
Called by an external client intended to control the Virtual FireAlarm bulb */
/** /**
* @param owner * This is an API called/used from within the Server(Front-End) or by a device Owner. It sends a control command to
* @param deviceId * the VirtualFirealarm device to switch `ON` or `OFF` its buzzer. The method also takes in the protocol to be used
* @param protocol * to connect-to and send the command to the device.
* @param state *
* @param response * @param owner the name of the owner(username) of the device to which the control-command is to be sent.
* @param deviceId the ID of the VirtualFirealarm device on which the buzzer needs to switched `ON` or `OFF`.
* @param protocol the protocol (HTTP, MQTT, XMPP) to be used to connect-to & send the message to the device.
* @param state the state to which the buzzer on the device needs to be changed. Either "ON" or "OFF".
* (Case-Insensitive String)
* @param response the HTTP servlet response object received by default as part of the HTTP call to this API.
*/ */
@Path("controller/buzzer")
@POST @POST
@Feature( code="buzzer", name="Buzzer On / Off", type="operation", @Path("controller/buzzer")
description="Switch on/off Virtual Fire Alarm Buzzer. (On / Off)") @Feature(code = "buzzer", name = "Buzzer On / Off", type = "operation",
description = "Switch on/off Virtual Fire Alarm Buzzer. (On / Off)")
public void switchBulb(@HeaderParam("owner") String owner, public void switchBulb(@HeaderParam("owner") String owner,
@HeaderParam("deviceId") String deviceId, @HeaderParam("deviceId") String deviceId,
@HeaderParam("protocol") String protocol, @HeaderParam("protocol") String protocol,
@ -236,9 +249,8 @@ public class VirtualFireAlarmService {
try { try {
DeviceValidator deviceValidator = new DeviceValidator(); DeviceValidator deviceValidator = new DeviceValidator();
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId, if (!deviceValidator.isExist(owner, SUPER_TENANT,
VirtualFireAlarmConstants new DeviceIdentifier(deviceId, VirtualFireAlarmConstants.DEVICE_TYPE))) {
.DEVICE_TYPE))) {
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
return; return;
} }
@ -302,22 +314,28 @@ public class VirtualFireAlarmService {
/** /**
* @param owner * This is an API called/used from within the Server(Front-End) or by a device Owner. It sends a control command
* @param deviceId * to the VirtualFirealarm device to 'tell what's its current humidity reading'. The method also takes in the
* @param protocol * protocol to be used to connect-to and send the command to the device.
* @param response *
* @return * @param owner the name of the owner(username) of the device to which the control-command is to be sent.
* @param deviceId the ID of the VirtualFirealarm device on which the humidity reading is be read-from.
* @param protocol the protocol (HTTP, MQTT, XMPP) to be used to connect-to & send the message to the device.
* @param response the HTTP servlet response object received by default as part of the HTTP call to this API.
* @return an instance of the 'SensorRecord' object that holds the last updated humidity of the VirtualFirealarm
* whose humidity reading was requested.
*/ */
@Path("controller/readhumidity")
@GET @GET
@Path("controller/readhumidity")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Feature(code = "readhumidity", name = "Humidity", type = "monitor", @Feature(code = "readhumidity", name = "Humidity", type = "monitor",
description = "Read Humidity Readings from Virtual Fire Alarm") description = "Read Humidity Readings from Virtual Fire Alarm")
public SensorRecord requestHumidity(@HeaderParam("owner") String owner, public SensorRecord requestHumidity(@HeaderParam("owner") String owner,
@HeaderParam("deviceId") String deviceId, @HeaderParam("deviceId") String deviceId,
@HeaderParam("protocol") String protocol, @HeaderParam("protocol") String protocol,
@Context HttpServletResponse response) { @Context HttpServletResponse response) {
//TODO::Need to use Web-Sockets to reply messages.
SensorRecord sensorRecord = null; SensorRecord sensorRecord = null;
DeviceValidator deviceValidator = new DeviceValidator(); DeviceValidator deviceValidator = new DeviceValidator();
try { try {
@ -344,7 +362,8 @@ public class VirtualFireAlarmService {
} }
String humidityValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, String humidityValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint,
VirtualFireAlarmConstants.HUMIDITY_CONTEXT, VirtualFireAlarmConstants
.HUMIDITY_CONTEXT,
false); false);
SensorDataManager.getInstance().setSensorRecord(deviceId, SensorDataManager.getInstance().setSensorRecord(deviceId,
VirtualFireAlarmConstants.SENSOR_TEMP, VirtualFireAlarmConstants.SENSOR_TEMP,
@ -376,18 +395,23 @@ public class VirtualFireAlarmService {
} }
/** /**
* @param owner * This is an API called/used from within the Server(Front-End) or by a device Owner. It sends a control command
* @param deviceId * to the VirtualFirealarm device to 'tell what's its current temperature reading'. The method also takes in the
* @param protocol * protocol to be used to connect-to and send the command to the device.
* @param response *
* @return * @param owner the name of the owner(username) of the device to which the control-command is to be sent.
* @param deviceId the ID of the VirtualFirealarm device on which the temperature reading is be read-from.
* @param protocol the protocol (HTTP, MQTT, XMPP) to be used to connect-to & send the message to the device.
* @param response the HTTP servlet response object received by default as part of the HTTP call to this API.
* @return an instance of the 'SensorRecord' object that holds the last updated temperature of the VirtualFirealarm
* whose temperature reading was requested.
*/ */
@Path("controller/readtemperature")
@GET @GET
@Path("controller/readtemperature")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Feature( code="readtemperature", name="Temperature", type="monitor", @Feature(code = "readtemperature", name = "Temperature", type = "monitor",
description="Request Temperature reading from Virtual Fire Alarm") description = "Request Temperature reading from Virtual Fire Alarm")
public SensorRecord requestTemperature(@HeaderParam("owner") String owner, public SensorRecord requestTemperature(@HeaderParam("owner") String owner,
@HeaderParam("deviceId") String deviceId, @HeaderParam("deviceId") String deviceId,
@HeaderParam("protocol") String protocol, @HeaderParam("protocol") String protocol,
@ -454,14 +478,17 @@ public class VirtualFireAlarmService {
} }
/** /**
* @param dataMsg * This is an API called/used by the VirtualFirealarm device to publish its temperature to the IoT-Server. The
* @param response * received data from the device is stored in a 'DeviceRecord' under the device's ID in the 'SensorDataManager'
* of the Server.
*
* @param dataMsg the temperature data received from the device in JSON format complying to type 'DeviceJSON'.
* @param response the HTTP servlet response object received by default as part of the HTTP call to this API.
*/ */
@Path("controller/push_temperature")
@POST @POST
@Path("controller/push_temperature")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public void pushTemperatureData(final DeviceJSON dataMsg, public void pushTemperatureData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {
@Context HttpServletResponse response) {
String deviceId = dataMsg.deviceId; String deviceId = dataMsg.deviceId;
String deviceIp = dataMsg.reply; String deviceIp = dataMsg.reply;
float temperature = dataMsg.value; float temperature = dataMsg.value;
@ -491,9 +518,18 @@ public class VirtualFireAlarmService {
/** /**
* @param operation * This is an API called/used by the SCEP Client of the VirtualFirealarm device in its SCEP enrollment process.
* @param message * This acts as the endpoint exposed as part of the SCEP-Server for use by a SCEP Client. This is one of the two
* @return * method-signatures that takes different parameters according to the SCEP-Operation executed by the SCEP-Client
* of the enrolling device. The API supports 2 SCEP Operations [GetCACert] and [GetCACaps].
* <p/>
* Operation [GetCACert] returns the CA cert of the SCEP-Server for the device to verify its authenticity.
* Operation [GetCACaps] returns the CA Capabilities of the SCEP-Server.
*
* @param operation the SCEP operation requested by the client. [GetCACert] or [GetCACaps]
* @param message any messages pertaining to the requested SCEP Operation.
*
* @return an HTTP Response object with either the CA-Cert or the CA-Capabilities according to the operation.
*/ */
@GET @GET
@Path("controller/scep") @Path("controller/scep")
@ -573,9 +609,17 @@ public class VirtualFireAlarmService {
} }
/** /**
* @param operation * This is an API called/used by the SCEP Client of the VirtualFirealarm device in its SCEP enrollment process.
* @param inputStream * This acts as the endpoint exposed as part of the SCEP-Server for use by a SCEP Client. This is one of the two
* @return * method-signatures that takes different parameters according to the SCEP-Operation executed by the SCEP-Client
* of the enrolling device. This API supports the SCEP Operation [PKIOperation].
*
* Operation [PKIOperation] returns a certificate generated by the SCEP-Server for the enrolling device.
*
* @param operation the final SCEP operation executed in the enrollment process - which is [PKIOperation]
* @param inputStream an input stream consisting of the Certificate-Signing-Request (CSR) from the device.
*
* @return an HTTP Response object with the signed certificate for the device by the CA of the SCEP Server.
*/ */
@POST @POST
@Path("controller/scep") @Path("controller/scep")

Loading…
Cancel
Save