Merge pull request #141 from Shabirmean/IoTS-1.0.0-M1

Fixing JIRA: https://wso2.org/jira/browse/IOTS-12
Ruwan 9 years ago
commit 0d97a5846b

@ -84,18 +84,6 @@ public class AgentConstants {
/* ---------------------------------------------------------------------------------------
Default values for the Device/Agent specific configurations listed above
--------------------------------------------------------------------------------------- */
public static final String DEFAULT_SERVER_NAME = "WSO2IoTServer";
public static final String DEFAULT_DEVICE_OWNER = "admin";
public static final String DEFAULT_DEVICE_ID = "1234567890";
public static final String DEFAULT_DEVICE_NAME = "admin_1234567890";
public static final String DEFAULT_HTTPS_SERVER_EP = "https://localhost:9443";
public static final String DEFAULT_HTTP_SERVER_EP = "http://localhost:9763";
public static final String DEFAULT_APIM_GATEWAY_EP = "http://127.0.0.1:8281";
public static final String DEFAULT_MQTT_BROKER_EP = "tcp://127.0.0.1:1883";
public static final String DEFAULT_XMPP_SERVER_EP = "http://127.0.0.1:9061";
public static final String DEFAULT_AUTH_METHOD = "token";
public static final String DEFAULT_AUTH_TOKEN = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0987654321";
public static final String DEFAULT_REFRESH_TOKEN = "1234567890ZYXWVUTSRQPONMKLJIHGFEDCBA";
public static final String DEFAULT_NETWORK_INTERFACE = "en0";
public static final int DEFAULT_DATA_PUBLISH_INTERVAL = 15; // seconds
public static final String DEFAULT_PROTOCOL = "MQTT";

@ -76,7 +76,13 @@ public class AgentManager {
agentCommunicator = new HashMap<>();
// Read IoT-Server specific configurations from the 'deviceConfig.properties' file
this.agentConfigs = AgentUtilOperations.readIoTServerConfigs();
try {
this.agentConfigs = AgentUtilOperations.readIoTServerConfigs();
} catch (AgentCoreOperationException e) {
log.error("Reading device configuration from configd file failed:\n");
log.error(e);
System.exit(0);
}
// Initialise IoT-Server URL endpoints from the configuration read from file
AgentUtilOperations.initializeServerEndPoints();
@ -153,7 +159,7 @@ public class AgentManager {
EnrollmentManager.getInstance().beginEnrollmentFlow();
} catch (AgentCoreOperationException e) {
log.error("Device Enrollment Failed:\n");
e.printStackTrace();
log.error(e);
System.exit(0);
}

@ -26,11 +26,14 @@ import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.exception.AgentCore
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.transport.CommunicationUtils;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.transport.TransportHandlerException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Properties;
@ -56,7 +59,7 @@ public class AgentUtilOperations {
* @return an object of type 'AgentConfiguration' which contains all the necessary
* configuration attributes
*/
public static AgentConfiguration readIoTServerConfigs() {
public static AgentConfiguration readIoTServerConfigs() throws AgentCoreOperationException {
AgentManager agentManager = AgentManager.getInstance();
AgentConfiguration iotServerConfigs = new AgentConfiguration();
Properties properties = new Properties();
@ -67,14 +70,14 @@ public class AgentUtilOperations {
ClassLoader loader = AgentUtilOperations.class.getClassLoader();
URL path = loader.getResource(propertiesFileName);
System.out.println(path);
String root = path.getPath().replace(
"wso2-firealarm-virtual-agent.jar!/deviceConfig.properties",
"").replace("jar:", "").replace("file:", "");
String root = path.getPath().replace("wso2-firealarm-virtual-agent.jar!/deviceConfig.properties", "")
.replace("jar:", "").replace("file:", "");
root = URLDecoder.decode(root, StandardCharsets.UTF_8.toString());
agentManager.setRootPath(root);
propertiesInputStream = new FileInputStream(
root + AgentConstants.AGENT_PROPERTIES_FILE_NAME);
String deviceConfigFilePath = root + AgentConstants.AGENT_PROPERTIES_FILE_NAME;
propertiesInputStream = new FileInputStream(deviceConfigFilePath);
//load a properties file from class path, inside static method
properties.load(propertiesInputStream);
@ -137,16 +140,15 @@ public class AgentUtilOperations {
iotServerConfigs.getDataPushInterval());
} catch (FileNotFoundException ex) {
log.error(AgentConstants.LOG_APPENDER + "Unable to find " + propertiesFileName +
" file at: " + AgentConstants.PROPERTIES_FILE_PATH);
iotServerConfigs = setDefaultDeviceConfigs();
String errorMsg = "[" + propertiesFileName + "] file not found at: " + AgentConstants.PROPERTIES_FILE_PATH;
log.error(AgentConstants.LOG_APPENDER + errorMsg);
throw new AgentCoreOperationException(errorMsg);
} catch (IOException ex) {
log.error(AgentConstants.LOG_APPENDER + "Error occurred whilst trying to fetch '" +
propertiesFileName + "' from: " +
AgentConstants.PROPERTIES_FILE_PATH);
iotServerConfigs = setDefaultDeviceConfigs();
String errorMsg = "Error occurred whilst trying to fetch [" + propertiesFileName + "] from: " +
AgentConstants.PROPERTIES_FILE_PATH;
log.error(AgentConstants.LOG_APPENDER + errorMsg);
throw new AgentCoreOperationException(errorMsg);
} finally {
if (propertiesInputStream != null) {
try {
@ -161,36 +163,6 @@ public class AgentUtilOperations {
return iotServerConfigs;
}
/**
* Sets the default Device specific configurations listed in the 'AgentConstants' class.
*
* @return an object of AgentConfiguration class including all default device specific configs.
*/
private static AgentConfiguration setDefaultDeviceConfigs() {
log.warn(AgentConstants.LOG_APPENDER +
"Default Values are being set to all Agent specific configurations");
AgentConfiguration iotServerConfigs = new AgentConfiguration();
iotServerConfigs.setDeviceOwner(AgentConstants.DEFAULT_SERVER_NAME);
iotServerConfigs.setDeviceOwner(AgentConstants.DEFAULT_DEVICE_OWNER);
iotServerConfigs.setDeviceId(AgentConstants.DEFAULT_DEVICE_ID);
iotServerConfigs.setDeviceName(AgentConstants.DEFAULT_DEVICE_NAME);
iotServerConfigs.setControllerContext(AgentConstants.DEVICE_CONTROLLER_API_EP);
iotServerConfigs.setHTTPS_ServerEndpoint(AgentConstants.DEFAULT_HTTPS_SERVER_EP);
iotServerConfigs.setHTTP_ServerEndpoint(AgentConstants.DEFAULT_HTTP_SERVER_EP);
iotServerConfigs.setApimGatewayEndpoint(AgentConstants.DEFAULT_APIM_GATEWAY_EP);
iotServerConfigs.setMqttBrokerEndpoint(AgentConstants.DEFAULT_MQTT_BROKER_EP);
iotServerConfigs.setXmppServerEndpoint(AgentConstants.DEFAULT_XMPP_SERVER_EP);
iotServerConfigs.setAuthMethod(AgentConstants.DEFAULT_AUTH_METHOD);
iotServerConfigs.setAuthToken(AgentConstants.DEFAULT_AUTH_TOKEN);
iotServerConfigs.setRefreshToken(AgentConstants.DEFAULT_REFRESH_TOKEN);
iotServerConfigs.setDataPushInterval(AgentConstants.DEFAULT_DATA_PUBLISH_INTERVAL);
return iotServerConfigs;
}
/**
* This method constructs the URLs for each of the API Endpoints called by the device agent
* Ex: Register API, Push-Data API

@ -27,6 +27,7 @@ import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttSecurityException;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.iot.transport.TransportHandler;
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
@ -315,6 +316,13 @@ public abstract class MQTTTransportHandler
log.debug("Got an MQTT message '" + mqttMessage.toString() + "' for topic '" + topic + "'.");
}
try {
throw new DeviceManagementException("Test Exception");
} catch (DeviceManagementException e) {
e.printStackTrace();
}
Thread messageProcessorThread = new Thread() {
public void run() {
try {

Loading…
Cancel
Save