upstream changes

NuwanSameera 9 years ago
commit 74f8dd9f0c

@ -51,7 +51,7 @@ public class ApisAppClient {
private String loginEndpoint; private String loginEndpoint;
private String subscriptionListEndpoint; private String subscriptionListEndpoint;
private static Log log = LogFactory.getLog(ApisAppClient.class); private static Log log = LogFactory.getLog(ApisAppClient.class);
private boolean isEnabled; private boolean isApiManagerEnabled;
public static ApisAppClient getInstance(){ public static ApisAppClient getInstance(){
@ -66,7 +66,7 @@ public class ApisAppClient {
DeviceManagementConfigurationManager.getInstance().getDeviceCloudMgtConfig().getApiManager(); DeviceManagementConfigurationManager.getInstance().getDeviceCloudMgtConfig().getApiManager();
String serverUrl=apiManagerConfig.getServerURL(); String serverUrl=apiManagerConfig.getServerURL();
String serverPort=apiManagerConfig.getServerPort(); String serverPort=apiManagerConfig.getServerPort();
isEnabled = apiManagerConfig.isEnabled(); isApiManagerEnabled = apiManagerConfig.isEnabled();
String loginURL = serverUrl+":"+serverPort+apiManagerConfig.getLoginURL(); String loginURL = serverUrl+":"+serverPort+apiManagerConfig.getLoginURL();
loginEndpoint= loginURL+"?action=login&username="+apiManagerConfig.getUsername() loginEndpoint= loginURL+"?action=login&username="+apiManagerConfig.getUsername()
@ -77,25 +77,36 @@ public class ApisAppClient {
} }
public String getBase64EncodedConsumerKeyAndSecret(String deviceType) { public String getBase64EncodedConsumerKeyAndSecret(String deviceType) {
if(!isEnabled) return null; if (!isApiManagerEnabled) return null;
String consumerKeyAndSecret = deviceTypeToApiAppMap.get(deviceType); String consumerKeyAndSecret = deviceTypeToApiAppMap.get(deviceType);
if(consumerKeyAndSecret == null){ if (consumerKeyAndSecret == null) {
ArrayList<IotDeviceTypeConfig> iotDeviceTypeConfigs = new ArrayList<>(); ArrayList<IotDeviceTypeConfig> iotDeviceTypeConfigs = new ArrayList<>();
IotDeviceTypeConfig DeviceTypeConfig = IotDeviceTypeConfigurationManager.getInstance().getIotDeviceTypeConfigMap().get(deviceType); IotDeviceTypeConfigurationManager deviceTypeConfigurationManager =
if(DeviceTypeConfig != null) { IotDeviceTypeConfigurationManager.getInstance();
iotDeviceTypeConfigs.add(DeviceTypeConfig); IotDeviceTypeConfig deviceTypeConfig = null;
setBase64EncodedConsumerKeyAndSecret(iotDeviceTypeConfigs); if (deviceTypeConfigurationManager != null) {
consumerKeyAndSecret = deviceTypeToApiAppMap.get(deviceType); deviceTypeConfig = deviceTypeConfigurationManager.getIotDeviceTypeConfigMap().get(
if(consumerKeyAndSecret==null){ deviceType);
log.warn("There is no API application for the device type " + deviceType); }
} if (deviceTypeConfig != null) {
iotDeviceTypeConfigs.add(deviceTypeConfig);
} else {
deviceTypeConfig = new IotDeviceTypeConfig();
deviceTypeConfig.setType(deviceType);
deviceTypeConfig.setApiApplicationName(deviceType);
iotDeviceTypeConfigs.add(deviceTypeConfig);
}
setBase64EncodedConsumerKeyAndSecret(iotDeviceTypeConfigs);
consumerKeyAndSecret = deviceTypeToApiAppMap.get(deviceType);
if (consumerKeyAndSecret == null) {
log.warn("There is no API application for the device type " + deviceType);
} }
} }
return consumerKeyAndSecret; return consumerKeyAndSecret;
} }
public void setBase64EncodedConsumerKeyAndSecret(List<IotDeviceTypeConfig> iotDeviceTypeConfigList) { public void setBase64EncodedConsumerKeyAndSecret(List<IotDeviceTypeConfig> iotDeviceTypeConfigList) {
if(!isEnabled) return; if(!isApiManagerEnabled) return;
URL loginURL = null; URL loginURL = null;
try { try {
@ -132,8 +143,6 @@ public class ApisAppClient {
getMethod.setHeader("cookie", cookie); getMethod.setHeader("cookie", cookie);
httpResponse = httpClient.execute(getMethod); httpResponse = httpClient.execute(getMethod);
response = IoTUtil.getResponseString(httpResponse); response = IoTUtil.getResponseString(httpResponse);
if(log.isDebugEnabled()) { if(log.isDebugEnabled()) {
log.debug(response); log.debug(response);
} }

@ -137,7 +137,7 @@ public abstract class MQTTTransportHandler
options.setCleanSession(true); options.setCleanSession(true);
//TODO:: Use constant strings //TODO:: Use constant strings
options.setWill(clientWillTopic, "Connection-Lost".getBytes(StandardCharsets.UTF_8), 2, options.setWill(clientWillTopic, "Connection-Lost".getBytes(StandardCharsets.UTF_8), 2,
true); true);
client.setCallback(this); client.setCallback(this);
} }
@ -247,7 +247,7 @@ public abstract class MQTTTransportHandler
client.publish(topic, payLoad.getBytes(StandardCharsets.UTF_8), qos, retained); client.publish(topic, payLoad.getBytes(StandardCharsets.UTF_8), qos, retained);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Message: " + payLoad + " to MQTT topic [" + topic + log.debug("Message: " + payLoad + " to MQTT topic [" + topic +
"] published successfully"); "] published successfully");
} }
} catch (MqttException ex) { } catch (MqttException ex) {
String errorMsg = String errorMsg =
@ -266,7 +266,7 @@ public abstract class MQTTTransportHandler
client.publish(topic, message); client.publish(topic, message);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Message: " + message.toString() + " to MQTT topic [" + topic + log.debug("Message: " + message.toString() + " to MQTT topic [" + topic +
"] published successfully"); "] published successfully");
} }
} catch (MqttException ex) { } catch (MqttException ex) {
//TODO:: Compulsory log of errors and remove formatted error //TODO:: Compulsory log of errors and remove formatted error
@ -290,7 +290,7 @@ public abstract class MQTTTransportHandler
public void connectionLost(Throwable throwable) { public void connectionLost(Throwable throwable) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.warn("Lost Connection for client: " + this.clientId + " to " + this.mqttBrokerEndPoint + "." + log.warn("Lost Connection for client: " + this.clientId + " to " + this.mqttBrokerEndPoint + "." +
"\nThis was due to - " + throwable.getMessage()); "\nThis was due to - " + throwable.getMessage());
} }
Thread reconnectThread = new Thread() { Thread reconnectThread = new Thread() {
@ -322,7 +322,7 @@ public abstract class MQTTTransportHandler
processIncomingMessage(mqttMessage, topic); processIncomingMessage(mqttMessage, topic);
} catch (TransportHandlerException e) { } catch (TransportHandlerException e) {
log.error("An error occurred when trying to process received MQTT message [" + mqttMessage + "] " + log.error("An error occurred when trying to process received MQTT message [" + mqttMessage + "] " +
"for topic [" + topic + "].", e); "for topic [" + topic + "].", e);
} }
} }
}; };
@ -348,10 +348,10 @@ public abstract class MQTTTransportHandler
if (iMqttDeliveryToken.getMessage() != null) { if (iMqttDeliveryToken.getMessage() != null) {
String message = iMqttDeliveryToken.getMessage().toString(); String message = iMqttDeliveryToken.getMessage().toString();
log.debug("Message to client [" + client + "] under topic (" + topic + log.debug("Message to client [" + client + "] under topic (" + topic +
") was delivered successfully with the delivery message: '" + message + "'"); ") was delivered successfully with the delivery message: '" + message + "'");
} else { } else {
log.debug("Message to client [" + client + "] under topic (" + topic + log.debug("Message to client [" + client + "] under topic (" + topic +
") was delivered successfully."); ") was delivered successfully.");
} }
} }
} else { } else {
@ -371,5 +371,4 @@ public abstract class MQTTTransportHandler
client.disconnect(); client.disconnect();
} }
} }
} }

@ -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,7 +11,7 @@
* 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.
*/ */
@ -32,12 +32,15 @@ import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.params.BasicHttpParams; import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.device.mgt.iot.exception.IoTException; import org.wso2.carbon.device.mgt.iot.exception.IoTException;
import org.wso2.carbon.device.mgt.iot.internal.IoTCommonDataHolder; import org.wso2.carbon.device.mgt.iot.internal.IoTCommonDataHolder;
import org.wso2.carbon.utils.NetworkUtils;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.SocketException;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -46,7 +49,8 @@ import java.security.UnrecoverableKeyException;
public class IoTUtil { public class IoTUtil {
private static final Log log = LogFactory.getLog(IoTUtil.class); public static final String HOST_NAME = "HostName";
private static final Log log = LogFactory.getLog(IoTUtil.class);
/** /**
* Return a http client instance * Return a http client instance
@ -106,4 +110,18 @@ public class IoTUtil {
} }
} }
public static String getHostName() throws IoTException {
String hostName = ServerConfiguration.getInstance().getFirstProperty(HOST_NAME);
try {
if (hostName == null) {
hostName = NetworkUtils.getLocalHostname();
}
} catch (SocketException e) {
throw new IoTException("Error while trying to read hostname.", e);
}
return hostName;
}
} }

@ -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,7 +11,7 @@
* 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.
*/ */
@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager; import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager;
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.XmppConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
import org.wso2.carbon.device.mgt.iot.exception.IoTException;
import org.wso2.carbon.device.mgt.iot.util.iotdevice.util.IotDeviceManagementUtil; import org.wso2.carbon.device.mgt.iot.util.iotdevice.util.IotDeviceManagementUtil;
import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.CarbonUtils;
@ -33,7 +34,6 @@ import java.util.Map;
public class ZipUtil { public class ZipUtil {
private static final String LOCAL_BIND_ADDRESS_PROPERTY = "carbon.local.ip";
private static final String HTTPS_PORT_PROPERTY = "httpsPort"; private static final String HTTPS_PORT_PROPERTY = "httpsPort";
private static final String HTTP_PORT_PROPERTY = "httpPort"; private static final String HTTP_PORT_PROPERTY = "httpPort";
@ -56,9 +56,14 @@ public class ZipUtil {
String templateSketchPath = sketchFolder + sep + deviceType; String templateSketchPath = sketchFolder + sep + deviceType;
String serverName = DeviceManagementConfigurationManager.getInstance().getDeviceManagementServerInfo().getName(); String serverName = DeviceManagementConfigurationManager.getInstance().getDeviceManagementServerInfo().getName();
String iotServerIP = System.getProperty(LOCAL_BIND_ADDRESS_PROPERTY); // bind.address String iotServerIP;
String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY); try {
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY); iotServerIP = IoTUtil.getHostName();
} catch (IoTException e) {
throw new DeviceManagementException(e.getMessage());
}
String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY);
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort; String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort;
String httpServerEP = HTTP_PROTOCOL_APPENDER + iotServerIP + ":" + httpServerPort; String httpServerEP = HTTP_PROTOCOL_APPENDER + iotServerIP + ":" + httpServerPort;
@ -87,8 +92,8 @@ public class ZipUtil {
xmppEndpoint = xmppEndpoint + ":" + XmppConfig.getInstance().getSERVER_CONNECTION_PORT(); xmppEndpoint = xmppEndpoint + ":" + XmppConfig.getInstance().getSERVER_CONNECTION_PORT();
Map<String, String> contextParams = new HashMap<String, String>(); Map<String, String> contextParams = new HashMap<>();
contextParams.put("SERVER_NAME", serverName); contextParams.put("SERVER_NAME", serverName);
contextParams.put("DEVICE_OWNER", owner); contextParams.put("DEVICE_OWNER", owner);
contextParams.put("DEVICE_ID", deviceId); contextParams.put("DEVICE_ID", deviceId);
contextParams.put("DEVICE_NAME", deviceName); contextParams.put("DEVICE_NAME", deviceName);

@ -9,8 +9,7 @@
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
<h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Android+Sense" <h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Android+Sense"
target="_blank">[ here ]</a> for latest instructions and trouble target="_blank">[ here ]</a> for latest instructions and troubleshooting.</h4>
shooting.</h4>
</div> </div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
@ -165,7 +164,8 @@
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Fill login <li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Fill login
form with the form with the
credentials. credentials.
<i>(Use server URL as [&nbsp;https://&lt;WSO2_IoT_SERVER_HOST&gt;:&lt;SERVER_PORT&gt;&nbsp;] and click on <i>(Use server URL as [&nbsp;https://&lt;WSO2_IoT_SERVER_HOST&gt;:&lt;HTTPS_SERVER_PORT&gt;&nbsp;]
and click on
<strong>Register Device</strong> button.)</i> <strong>Register Device</strong> button.)</i>
</li> </li>
<li> <li>

@ -9,8 +9,7 @@
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
<h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Arduino" <h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Arduino"
target="_blank">[ here ]</a> for latest instructions and trouble target="_blank">[ here ]</a> for latest instructions and troubleshooting.</h4>
shooting.</h4>
</div> </div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">

@ -9,8 +9,7 @@
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
<h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Digital+Display" <h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Digital+Display"
target="_blank">[ here ]</a> for latest instructions and trouble target="_blank">[ here ]</a> for latest instructions and troubleshooting.</h4>
shooting.</h4>
</div> </div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">

@ -9,8 +9,7 @@
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
<h4 class="doc-link">Click <a href="https://docs.wso2.com/pages/viewpage.action?pageId=48289181" <h4 class="doc-link">Click <a href="https://docs.wso2.com/pages/viewpage.action?pageId=48289181"
target="_blank">[ here ]</a> for latest instructions and trouble target="_blank">[ here ]</a> for latest instructions and troubleshooting.</h4>
shooting.</h4>
</div> </div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">

@ -9,8 +9,7 @@
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
<h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Raspberry+Pi" <h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Raspberry+Pi"
target="_blank">[ here ]</a> for latest instructions and trouble target="_blank">[ here ]</a> for latest instructions and troubleshooting.</h4>
shooting.</h4>
</div> </div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">

@ -8,8 +8,7 @@
</div> </div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
<h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Virtual+Firealarm" <h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Virtual+Firealarm"
target="_blank">[ here ]</a> for latest instructions and trouble target="_blank">[ here ]</a> for latest instructions and troubleshooting.</h4>
shooting.</h4>
</div> </div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">

@ -8,8 +8,7 @@
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
<h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Android" <h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Android"
target="_blank">[ here ]</a> for latest instructions and trouble target="_blank">[ here ]</a> for latest instructions and troubleshooting.</h4>
shooting.</h4>
</div> </div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">

@ -8,8 +8,7 @@
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
<h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Windows" <h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Windows"
target="_blank">[ here ]</a> for latest instructions and trouble target="_blank">[ here ]</a> for latest instructions and troubleshooting.</h4>
shooting.</h4>
</div> </div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top"> <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">

Loading…
Cancel
Save