resolved xmpp issues in virtual fire alarm

revert-dabc3590
ayyoob 9 years ago
parent f5442384d1
commit bb0b10f14c

@ -62,7 +62,7 @@ public class AndroidSenseManagerServiceImpl implements AndroidSenseManagerServic
androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain()); androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain());
String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint(); String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint();
if (mqttEndpoint.contains(Constants.LOCALHOST)) { if (mqttEndpoint.contains(Constants.LOCALHOST)) {
mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getHostName()); mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getServerUrl());
} }
androidConfiguration.setMqttEndpoint(mqttEndpoint); androidConfiguration.setMqttEndpoint(mqttEndpoint);
return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(androidConfiguration.toString()) return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(androidConfiguration.toString())
@ -85,7 +85,7 @@ public class AndroidSenseManagerServiceImpl implements AndroidSenseManagerServic
androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain()); androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain());
String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint(); String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint();
if (mqttEndpoint.contains(Constants.LOCALHOST)) { if (mqttEndpoint.contains(Constants.LOCALHOST)) {
mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getHostName()); mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getServerUrl());
} }
androidConfiguration.setMqttEndpoint(mqttEndpoint); androidConfiguration.setMqttEndpoint(mqttEndpoint);
return Response.ok(androidConfiguration.toString()).build(); return Response.ok(androidConfiguration.toString()).build();

@ -47,7 +47,7 @@ public class ZipUtil {
String iotServerIP; String iotServerIP;
try { try {
iotServerIP = Utils.getHostName(); iotServerIP = Utils.getServerUrl();
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY); String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
Map<String, String> contextParams = new HashMap<>(); Map<String, String> contextParams = new HashMap<>();

@ -55,7 +55,7 @@ public class Utils {
public static final String HOST_NAME = "HostName"; public static final String HOST_NAME = "HostName";
private static final Log log = LogFactory.getLog(Utils.class); private static final Log log = LogFactory.getLog(Utils.class);
public static String getHostName() { public static String getServerUrl() {
String hostName = ServerConfiguration.getInstance().getFirstProperty(HOST_NAME); String hostName = ServerConfiguration.getInstance().getFirstProperty(HOST_NAME);
try { try {
if (hostName == null) { if (hostName == null) {

@ -52,7 +52,7 @@ public class ZipUtil {
String iotServerIP; String iotServerIP;
try { try {
iotServerIP = Utils.getHostName(); iotServerIP = Utils.getServerUrl();
String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY); String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY);
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY); String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort; String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort;

@ -68,11 +68,8 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler {
final AgentManager agentManager = AgentManager.getInstance(); final AgentManager agentManager = AgentManager.getInstance();
username = agentManager.getAgentConfigs().getDeviceId(); username = agentManager.getAgentConfigs().getDeviceId();
password = agentManager.getAgentConfigs().getAuthToken(); password = agentManager.getAgentConfigs().getAuthToken();
resource = agentManager.getAgentConfigs().getDeviceOwner(); xmppDeviceJID = username + "@" + agentManager.getAgentConfigs().getXmppServerName();
xmppAdminJID = "wso2admin_" + AgentConstants.DEVICE_TYPE + "@" + agentManager.getAgentConfigs().getXmppServerName();
xmppDeviceJID = username + "@" + server;
xmppAdminJID = "wso2_" + AgentConstants.DEVICE_TYPE + "@" + server;
Runnable connect = new Runnable() { Runnable connect = new Runnable() {
public void run() { public void run() {

@ -39,6 +39,7 @@ public class AgentConfiguration {
private String authToken; private String authToken;
private String refreshToken; private String refreshToken;
private int dataPushInterval; private int dataPushInterval;
private String xmppServerName;
public String getTenantDomain() { public String getTenantDomain() {
return tenantDomain; return tenantDomain;
@ -159,6 +160,14 @@ public class AgentConfiguration {
public void setScepContext(String scepContext) { public void setScepContext(String scepContext) {
this.scepContext = scepContext; this.scepContext = scepContext;
} }
public String getXmppServerName() {
return xmppServerName;
}
public void setXmppServerName(String xmppServerName) {
this.xmppServerName = xmppServerName;
}
} }

@ -134,4 +134,6 @@ public class AgentConstants {
"select deviceID, temp\n" + "select deviceID, temp\n" +
"insert into bulbOffStream;"; "insert into bulbOffStream;";
public static final String XMPP_SERVER_NAME_PROPERTY = "xmpp-server-name";
} }

@ -102,6 +102,8 @@ public class AgentUtilOperations {
AgentConstants.MQTT_BROKER_EP_PROPERTY)); AgentConstants.MQTT_BROKER_EP_PROPERTY));
iotServerConfigs.setXmppServerEndpoint(properties.getProperty( iotServerConfigs.setXmppServerEndpoint(properties.getProperty(
AgentConstants.XMPP_SERVER_EP_PROPERTY)); AgentConstants.XMPP_SERVER_EP_PROPERTY));
iotServerConfigs.setXmppServerName(properties.getProperty(
AgentConstants.XMPP_SERVER_NAME_PROPERTY));
iotServerConfigs.setAuthMethod(properties.getProperty( iotServerConfigs.setAuthMethod(properties.getProperty(
AgentConstants.AUTH_METHOD_PROPERTY)); AgentConstants.AUTH_METHOD_PROPERTY));
iotServerConfigs.setAuthToken(properties.getProperty( iotServerConfigs.setAuthToken(properties.getProperty(
@ -138,6 +140,8 @@ public class AgentUtilOperations {
iotServerConfigs.getRefreshToken()); iotServerConfigs.getRefreshToken());
log.info(AgentConstants.LOG_APPENDER + "Data Push Interval: " + log.info(AgentConstants.LOG_APPENDER + "Data Push Interval: " +
iotServerConfigs.getDataPushInterval()); iotServerConfigs.getDataPushInterval());
log.info(AgentConstants.LOG_APPENDER + "XMPP Server Name: " +
iotServerConfigs.getXmppServerName());
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
log.error(AgentConstants.LOG_APPENDER + "Unable to find " + propertiesFileName + log.error(AgentConstants.LOG_APPENDER + "Unable to find " + propertiesFileName +

@ -32,3 +32,4 @@ auth-token=79d68b50ae5f5a06e812889979b3453
refresh-token=8bdda6359dddad218cff3354d5a8cb3b refresh-token=8bdda6359dddad218cff3354d5a8cb3b
network-interface=en0 network-interface=en0
push-interval=14 push-interval=14
xmpp-server-name=localhost

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.communication.xmpp
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.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentConfiguration;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentConstants; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentConstants;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentManager; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentManager;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentUtilOperations; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentUtilOperations;
@ -68,11 +69,8 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler {
final AgentManager agentManager = AgentManager.getInstance(); final AgentManager agentManager = AgentManager.getInstance();
username = agentManager.getAgentConfigs().getDeviceId(); username = agentManager.getAgentConfigs().getDeviceId();
password = agentManager.getAgentConfigs().getAuthToken(); password = agentManager.getAgentConfigs().getAuthToken();
resource = agentManager.getAgentConfigs().getDeviceOwner(); xmppDeviceJID = username + "@" + agentManager.getAgentConfigs().getXmppServerName();
xmppAdminJID = "wso2admin_" + AgentConstants.DEVICE_TYPE + "@" + agentManager.getAgentConfigs().getXmppServerName();
xmppDeviceJID = username + "@" + server;
xmppAdminJID = "wso2_" + AgentConstants.DEVICE_TYPE + "@" + server;
Runnable connect = new Runnable() { Runnable connect = new Runnable() {
public void run() { public void run() {

@ -39,6 +39,7 @@ public class AgentConfiguration {
private String authToken; private String authToken;
private String refreshToken; private String refreshToken;
private int dataPushInterval; private int dataPushInterval;
private String xmppServerName;
public String getTenantDomain() { public String getTenantDomain() {
return tenantDomain; return tenantDomain;
@ -159,6 +160,14 @@ public class AgentConfiguration {
public void setScepContext(String scepContext) { public void setScepContext(String scepContext) {
this.scepContext = scepContext; this.scepContext = scepContext;
} }
public String getXmppServerName() {
return xmppServerName;
}
public void setXmppServerName(String xmppServerName) {
this.xmppServerName = xmppServerName;
}
} }

@ -77,6 +77,7 @@ public class AgentConstants {
public static final String APIM_GATEWAY_EP_PROPERTY = "apim-ep"; public static final String APIM_GATEWAY_EP_PROPERTY = "apim-ep";
public static final String MQTT_BROKER_EP_PROPERTY = "mqtt-ep"; public static final String MQTT_BROKER_EP_PROPERTY = "mqtt-ep";
public static final String XMPP_SERVER_EP_PROPERTY = "xmpp-ep"; public static final String XMPP_SERVER_EP_PROPERTY = "xmpp-ep";
public static final String XMPP_SERVER_NAME_PROPERTY = "xmpp-server-name";
public static final String AUTH_METHOD_PROPERTY = "auth-method"; public static final String AUTH_METHOD_PROPERTY = "auth-method";
public static final String AUTH_TOKEN_PROPERTY = "auth-token"; public static final String AUTH_TOKEN_PROPERTY = "auth-token";
public static final String REFRESH_TOKEN_PROPERTY = "refresh-token"; public static final String REFRESH_TOKEN_PROPERTY = "refresh-token";

@ -106,6 +106,8 @@ public class AgentUtilOperations {
AgentConstants.MQTT_BROKER_EP_PROPERTY)); AgentConstants.MQTT_BROKER_EP_PROPERTY));
iotServerConfigs.setXmppServerEndpoint(properties.getProperty( iotServerConfigs.setXmppServerEndpoint(properties.getProperty(
AgentConstants.XMPP_SERVER_EP_PROPERTY)); AgentConstants.XMPP_SERVER_EP_PROPERTY));
iotServerConfigs.setXmppServerName(properties.getProperty(
AgentConstants.XMPP_SERVER_NAME_PROPERTY));
iotServerConfigs.setAuthMethod(properties.getProperty( iotServerConfigs.setAuthMethod(properties.getProperty(
AgentConstants.AUTH_METHOD_PROPERTY)); AgentConstants.AUTH_METHOD_PROPERTY));
iotServerConfigs.setAuthToken(properties.getProperty( iotServerConfigs.setAuthToken(properties.getProperty(
@ -142,6 +144,8 @@ public class AgentUtilOperations {
iotServerConfigs.getRefreshToken()); iotServerConfigs.getRefreshToken());
log.info(AgentConstants.LOG_APPENDER + "Data Push Interval: " + log.info(AgentConstants.LOG_APPENDER + "Data Push Interval: " +
iotServerConfigs.getDataPushInterval()); iotServerConfigs.getDataPushInterval());
log.info(AgentConstants.LOG_APPENDER + "XMPP Server Name: " +
iotServerConfigs.getXmppServerName());
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
String errorMsg = "[" + propertiesFileName + "] file not found at: " + AgentConstants.PROPERTIES_FILE_PATH; String errorMsg = "[" + propertiesFileName + "] file not found at: " + AgentConstants.PROPERTIES_FILE_PATH;

@ -32,3 +32,4 @@ auth-token=79d68b50ae5f5a06e812889979b3453
refresh-token=8bdda6359dddad218cff3354d5a8cb3b refresh-token=8bdda6359dddad218cff3354d5a8cb3b
network-interface=en0 network-interface=en0
push-interval=14 push-interval=14
xmpp-server-name=localhost

@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorization
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
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.plugin.impl.util.VirtualFirealarmSecurityManager; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFirealarmSecurityManager;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppConfig;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.SensorRecord; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.SensorRecord;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.APIUtil;
@ -83,7 +84,8 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
Map<String, String> dynamicProperties = new HashMap<>(); Map<String, String> dynamicProperties = new HashMap<>();
switch (protocolString) { switch (protocolString) {
case XMPP_PROTOCOL: case XMPP_PROTOCOL:
dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, deviceId); dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY,
deviceId + "@" + XmppConfig.getInstance().getXmppServerName());
dynamicProperties.put(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "CONTROL-REQUEST"); dynamicProperties.put(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "CONTROL-REQUEST");
dynamicProperties.put(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY, dynamicProperties.put(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY,
VirtualFireAlarmConstants.CHAT_PROPERTY_KEY); VirtualFireAlarmConstants.CHAT_PROPERTY_KEY);
@ -91,7 +93,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
dynamicProperties, encryptedMsg); dynamicProperties, encryptedMsg);
break; break;
default: default:
String publishTopic = APIUtil.getTenantDomainOftheUser() + "/" String publishTopic = APIUtil.getTenantDomainOftheUser() + "/"
+ VirtualFireAlarmConstants.DEVICE_TYPE + "/" + deviceId; + VirtualFireAlarmConstants.DEVICE_TYPE + "/" + deviceId;
dynamicProperties.put(VirtualFireAlarmConstants.ADAPTER_TOPIC_PROPERTY, publishTopic); dynamicProperties.put(VirtualFireAlarmConstants.ADAPTER_TOPIC_PROPERTY, publishTopic);
@ -131,7 +132,8 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
Map<String, String> dynamicProperties = new HashMap<>(); Map<String, String> dynamicProperties = new HashMap<>();
switch (protocolString) { switch (protocolString) {
case XMPP_PROTOCOL: case XMPP_PROTOCOL:
dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, deviceId); dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY,
deviceId + "@" + XmppConfig.getInstance().getXmppServerName());
dynamicProperties.put(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "POLICTY-REQUEST"); dynamicProperties.put(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "POLICTY-REQUEST");
dynamicProperties.put(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY, dynamicProperties.put(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY,
VirtualFireAlarmConstants.CHAT_PROPERTY_KEY); VirtualFireAlarmConstants.CHAT_PROPERTY_KEY);

@ -53,7 +53,7 @@ public class ZipUtil {
String iotServerIP; String iotServerIP;
try { try {
iotServerIP = Utils.getHostName(); iotServerIP = Utils.getServerUrl();
String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY); String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY);
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY); String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort; String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort;
@ -80,7 +80,7 @@ public class ZipUtil {
contextParams.put("XMPP_EP", "XMPP:" + xmppEndpoint); contextParams.put("XMPP_EP", "XMPP:" + xmppEndpoint);
contextParams.put("DEVICE_TOKEN", token); contextParams.put("DEVICE_TOKEN", token);
contextParams.put("DEVICE_REFRESH_TOKEN", refreshToken); contextParams.put("DEVICE_REFRESH_TOKEN", refreshToken);
contextParams.put("SERVER_NAME", XmppConfig.getInstance().getXmppServerName());
ZipArchive zipFile; ZipArchive zipFile;
zipFile = Utils.getSketchArchive(archivesPath, templateSketchPath, contextParams, deviceName); zipFile = Utils.getSketchArchive(archivesPath, templateSketchPath, contextParams, deviceName);
return zipFile; return zipFile;

@ -80,11 +80,12 @@ public class VirtualFireAlarmConstants {
public static final String IS_ENABLED_KEY = "enabled"; public static final String IS_ENABLED_KEY = "enabled";
public static final String HOST_KEY = "host"; public static final String HOST_KEY = "host";
public static final String PORT_KEY = "port"; public static final String PORT_KEY = "port";
public static final String CONNECTION_PORT = "connection.port";
public static final String ADMIN_USERNAME = "admin.username"; public static final String ADMIN_USERNAME = "admin.username";
public static final String ADMIN_PASSWORD = "admin.password"; public static final String ADMIN_PASSWORD = "admin.password";
public static final String XMPP_SERVER_PASSWORD = "admin@123456789"; public static final String XMPP_SERVER_PASSWORD = "admin@123456789";
public static final String SERVER_NAME = "serverName";
public static final String MQTT_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator public static final String MQTT_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator
+ "mqtt.properties"; + "mqtt.properties";
public static final String XMPP_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator public static final String XMPP_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator

@ -38,6 +38,8 @@ import org.wso2.carbon.event.output.adapter.core.MessageType;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration;
import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException; import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException;
import org.json.JSONObject; import org.json.JSONObject;
import org.wso2.carbon.utils.NetworkUtils;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
@ -45,6 +47,7 @@ import javax.sql.DataSource;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.SocketException;
import java.security.PublicKey; import java.security.PublicKey;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.sql.Connection; import java.sql.Connection;

@ -14,6 +14,9 @@ public class VirtualFirealarmEventAdapterSubscription implements InputEventAdapt
if (actualMessage.contains("PUBLISHER")) { if (actualMessage.contains("PUBLISHER")) {
float temperature = Float.parseFloat(actualMessage.split(":")[2]); float temperature = Float.parseFloat(actualMessage.split(":")[2]);
VirtualFireAlarmUtils.publishToDAS(deviceId, temperature); VirtualFireAlarmUtils.publishToDAS(deviceId, temperature);
} else {
float temperature = Float.parseFloat(actualMessage.split(":")[1]);
VirtualFireAlarmUtils.publishToDAS(deviceId, temperature);
} }
} }
} }

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp;
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.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.plugin.impl.util.VirtualFireAlarmUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -37,6 +38,7 @@ public class XmppConfig {
private String virtualFirealarmAdminUsername; private String virtualFirealarmAdminUsername;
private String virtualFirealarmAdminPassword; private String virtualFirealarmAdminPassword;
private String virtualFirealarmAdminJID; private String virtualFirealarmAdminJID;
private String xmppServerName;
private static XmppConfig xmppConfig = new XmppConfig(); private static XmppConfig xmppConfig = new XmppConfig();
private static final Log log = LogFactory.getLog(XmppConfig.class); private static final Log log = LogFactory.getLog(XmppConfig.class);
@ -48,12 +50,13 @@ public class XmppConfig {
Properties properties = new Properties(); Properties properties = new Properties();
properties.load(propertyStream); properties.load(propertyStream);
xmppServerIP = properties.getProperty(VirtualFireAlarmConstants.HOST_KEY); xmppServerIP = properties.getProperty(VirtualFireAlarmConstants.HOST_KEY);
xmppServerName = properties.getProperty(VirtualFireAlarmConstants.SERVER_NAME);
xmppServerPort = Integer.parseInt(properties.getProperty(VirtualFireAlarmConstants.PORT_KEY)); xmppServerPort = Integer.parseInt(properties.getProperty(VirtualFireAlarmConstants.PORT_KEY));
isEnabled = Boolean.parseBoolean(properties.getProperty(VirtualFireAlarmConstants.IS_ENABLED_KEY)); isEnabled = Boolean.parseBoolean(properties.getProperty(VirtualFireAlarmConstants.IS_ENABLED_KEY));
xmppUsername = properties.getProperty(VirtualFireAlarmConstants.ADMIN_USERNAME); xmppUsername = properties.getProperty(VirtualFireAlarmConstants.ADMIN_USERNAME);
xmppPassword = properties.getProperty(VirtualFireAlarmConstants.ADMIN_PASSWORD); xmppPassword = properties.getProperty(VirtualFireAlarmConstants.ADMIN_PASSWORD);
virtualFirealarmAdminUsername = "wso2admin_" + VirtualFireAlarmConstants.DEVICE_TYPE; virtualFirealarmAdminUsername = "wso2admin_" + VirtualFireAlarmConstants.DEVICE_TYPE;
virtualFirealarmAdminJID = virtualFirealarmAdminUsername + "@" + xmppServerIP; virtualFirealarmAdminJID = virtualFirealarmAdminUsername + "@" + xmppServerName;
virtualFirealarmAdminPassword = VirtualFireAlarmConstants.XMPP_SERVER_PASSWORD; virtualFirealarmAdminPassword = VirtualFireAlarmConstants.XMPP_SERVER_PASSWORD;
} catch (IOException e) { } catch (IOException e) {
log.error(e); log.error(e);
@ -97,4 +100,7 @@ public class XmppConfig {
return virtualFirealarmAdminJID; return virtualFirealarmAdminJID;
} }
public String getXmppServerName() {
return xmppServerName;
}
} }

@ -18,8 +18,6 @@
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp; package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jivesoftware.smack.AccountManager; import org.jivesoftware.smack.AccountManager;
import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
@ -36,7 +34,8 @@ public class XmppServerClient {
if (xmppAccount != null) { if (xmppAccount != null) {
try { try {
ConnectionConfiguration config = new ConnectionConfiguration(XmppConfig.getInstance().getXmppServerIP(), ConnectionConfiguration config = new ConnectionConfiguration(XmppConfig.getInstance().getXmppServerIP(),
XmppConfig.getInstance().getXmppServerPort()); XmppConfig.getInstance().getXmppServerPort(),
"Accounts");
XMPPConnection xmppConnection = new XMPPConnection(config); XMPPConnection xmppConnection = new XMPPConnection(config);
xmppConnection.connect(); xmppConnection.connect();
xmppConnection.login(XmppConfig.getInstance().getXmppUsername(), XmppConfig.getInstance().getXmppPassword()); xmppConnection.login(XmppConfig.getInstance().getXmppUsername(), XmppConfig.getInstance().getXmppPassword());

@ -32,10 +32,10 @@ public class XmppUtil {
XmppServerClient xmppServerClient = new XmppServerClient(); XmppServerClient xmppServerClient = new XmppServerClient();
try { try {
XmppAccount xmppAccount = new XmppAccount(); XmppAccount xmppAccount = new XmppAccount();
xmppAccount.setAccountName(XmppConfig.getInstance().getVirtualFirealarmAdminJID()); xmppAccount.setAccountName(XmppConfig.getInstance().getVirtualFirealarmAdminUsername());
xmppAccount.setUsername(XmppConfig.getInstance().getVirtualFirealarmAdminUsername()); xmppAccount.setUsername(XmppConfig.getInstance().getVirtualFirealarmAdminUsername());
xmppAccount.setPassword(XmppConfig.getInstance().getVirtualFirealarmAdminPassword()); xmppAccount.setPassword(XmppConfig.getInstance().getVirtualFirealarmAdminPassword());
xmppAccount.setEmail(""); xmppAccount.setEmail(XmppConfig.getInstance().getVirtualFirealarmAdminJID());
xmppServerClient.createAccount(xmppAccount); xmppServerClient.createAccount(xmppAccount);
} catch (VirtualFirealarmDeviceMgtPluginException e) { } catch (VirtualFirealarmDeviceMgtPluginException e) {
String errorMsg = "An error was encountered whilst trying to create Server XMPP account for device-type - " String errorMsg = "An error was encountered whilst trying to create Server XMPP account for device-type - "

@ -21,8 +21,7 @@ function onRequest(context) {
var deviceType = context.uriParams.deviceType; var deviceType = context.uriParams.deviceType;
var deviceId = request.getParameter("id"); var deviceId = request.getParameter("id");
var autoCompleteParams = [ var autoCompleteParams = [
{"name" : "deviceId", "value" : deviceId}, {"name" : "deviceId", "value" : deviceId}
{"name" : "protocol", "value" : "MQTT"}
]; ];
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {

@ -2,4 +2,5 @@ enabled=false
host=localhost host=localhost
port=5222 port=5222
admin.username=admin admin.username=admin
admin.password=admin admin.password=admin
serverName=localhost

@ -31,5 +31,5 @@ auth-method=token
auth-token=${DEVICE_TOKEN} auth-token=${DEVICE_TOKEN}
refresh-token=${DEVICE_REFRESH_TOKEN} refresh-token=${DEVICE_REFRESH_TOKEN}
push-interval=15 push-interval=15
xmpp-server-name=${SERVER_NAME}

@ -31,5 +31,5 @@ auth-method=token
auth-token=${DEVICE_TOKEN} auth-token=${DEVICE_TOKEN}
refresh-token=${DEVICE_REFRESH_TOKEN} refresh-token=${DEVICE_REFRESH_TOKEN}
push-interval=15 push-interval=15
xmpp-server-name=${SERVER_NAME}

Loading…
Cancel
Save