diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/apimgt/ApisAppClient.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/apimgt/ApisAppClient.java index b1cc3ddb6a..c25cab600e 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/apimgt/ApisAppClient.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/apimgt/ApisAppClient.java @@ -51,7 +51,7 @@ public class ApisAppClient { private String loginEndpoint; private String subscriptionListEndpoint; private static Log log = LogFactory.getLog(ApisAppClient.class); - private boolean isEnabled; + private boolean isApiManagerEnabled; public static ApisAppClient getInstance(){ @@ -66,7 +66,7 @@ public class ApisAppClient { DeviceManagementConfigurationManager.getInstance().getDeviceCloudMgtConfig().getApiManager(); String serverUrl=apiManagerConfig.getServerURL(); String serverPort=apiManagerConfig.getServerPort(); - isEnabled = apiManagerConfig.isEnabled(); + isApiManagerEnabled = apiManagerConfig.isEnabled(); String loginURL = serverUrl+":"+serverPort+apiManagerConfig.getLoginURL(); loginEndpoint= loginURL+"?action=login&username="+apiManagerConfig.getUsername() @@ -77,25 +77,36 @@ public class ApisAppClient { } public String getBase64EncodedConsumerKeyAndSecret(String deviceType) { - if(!isEnabled) return null; + if (!isApiManagerEnabled) return null; String consumerKeyAndSecret = deviceTypeToApiAppMap.get(deviceType); - if(consumerKeyAndSecret == null){ + if (consumerKeyAndSecret == null) { ArrayList iotDeviceTypeConfigs = new ArrayList<>(); - IotDeviceTypeConfig DeviceTypeConfig = IotDeviceTypeConfigurationManager.getInstance().getIotDeviceTypeConfigMap().get(deviceType); - if(DeviceTypeConfig != null) { - iotDeviceTypeConfigs.add(DeviceTypeConfig); - setBase64EncodedConsumerKeyAndSecret(iotDeviceTypeConfigs); - consumerKeyAndSecret = deviceTypeToApiAppMap.get(deviceType); - if(consumerKeyAndSecret==null){ - log.warn("There is no API application for the device type " + deviceType); - } + IotDeviceTypeConfigurationManager deviceTypeConfigurationManager = + IotDeviceTypeConfigurationManager.getInstance(); + IotDeviceTypeConfig deviceTypeConfig = null; + if (deviceTypeConfigurationManager != null) { + deviceTypeConfig = deviceTypeConfigurationManager.getIotDeviceTypeConfigMap().get( + 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 iotDeviceTypeConfigList) { - if(!isEnabled) return; + if(!isApiManagerEnabled) return; URL loginURL = null; try { @@ -132,8 +143,6 @@ public class ApisAppClient { getMethod.setHeader("cookie", cookie); httpResponse = httpClient.execute(getMethod); response = IoTUtil.getResponseString(httpResponse); - - if(log.isDebugEnabled()) { log.debug(response); } diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/transport/mqtt/MQTTTransportHandler.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/transport/mqtt/MQTTTransportHandler.java index a365d6d15e..10eea3e8d6 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/transport/mqtt/MQTTTransportHandler.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/transport/mqtt/MQTTTransportHandler.java @@ -137,7 +137,7 @@ public abstract class MQTTTransportHandler options.setCleanSession(true); //TODO:: Use constant strings options.setWill(clientWillTopic, "Connection-Lost".getBytes(StandardCharsets.UTF_8), 2, - true); + true); client.setCallback(this); } @@ -247,7 +247,7 @@ public abstract class MQTTTransportHandler client.publish(topic, payLoad.getBytes(StandardCharsets.UTF_8), qos, retained); if (log.isDebugEnabled()) { log.debug("Message: " + payLoad + " to MQTT topic [" + topic + - "] published successfully"); + "] published successfully"); } } catch (MqttException ex) { String errorMsg = @@ -266,7 +266,7 @@ public abstract class MQTTTransportHandler client.publish(topic, message); if (log.isDebugEnabled()) { log.debug("Message: " + message.toString() + " to MQTT topic [" + topic + - "] published successfully"); + "] published successfully"); } } catch (MqttException ex) { //TODO:: Compulsory log of errors and remove formatted error @@ -290,7 +290,7 @@ public abstract class MQTTTransportHandler public void connectionLost(Throwable throwable) { if (log.isDebugEnabled()) { 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() { @@ -322,7 +322,7 @@ public abstract class MQTTTransportHandler processIncomingMessage(mqttMessage, topic); } catch (TransportHandlerException e) { 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) { String message = iMqttDeliveryToken.getMessage().toString(); 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 { log.debug("Message to client [" + client + "] under topic (" + topic + - ") was delivered successfully."); + ") was delivered successfully."); } } } else { @@ -371,5 +371,4 @@ public abstract class MQTTTransportHandler client.disconnect(); } } -} - +} \ No newline at end of file diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/IoTUtil.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/IoTUtil.java index eba1be0d37..38bcc34f73 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/IoTUtil.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/IoTUtil.java @@ -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, * 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, * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * 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.HttpParams; 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.internal.IoTCommonDataHolder; +import org.wso2.carbon.utils.NetworkUtils; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.net.SocketException; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -46,7 +49,8 @@ import java.security.UnrecoverableKeyException; 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 @@ -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; + } + } diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/ZipUtil.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/ZipUtil.java index 92905be56f..b6ab042a0d 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/ZipUtil.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/ZipUtil.java @@ -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, * 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, * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * 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.controlqueue.mqtt.MqttConfig; 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.utils.CarbonUtils; @@ -33,7 +34,6 @@ import java.util.Map; 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 HTTP_PORT_PROPERTY = "httpPort"; @@ -56,9 +56,14 @@ public class ZipUtil { String templateSketchPath = sketchFolder + sep + deviceType; String serverName = DeviceManagementConfigurationManager.getInstance().getDeviceManagementServerInfo().getName(); - String iotServerIP = System.getProperty(LOCAL_BIND_ADDRESS_PROPERTY); // bind.address - String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY); - String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY); + String iotServerIP; + try { + 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 httpServerEP = HTTP_PROTOCOL_APPENDER + iotServerIP + ":" + httpServerPort; @@ -87,8 +92,8 @@ public class ZipUtil { xmppEndpoint = xmppEndpoint + ":" + XmppConfig.getInstance().getSERVER_CONNECTION_PORT(); - Map contextParams = new HashMap(); - contextParams.put("SERVER_NAME", serverName); + Map contextParams = new HashMap<>(); + contextParams.put("SERVER_NAME", serverName); contextParams.put("DEVICE_OWNER", owner); contextParams.put("DEVICE_ID", deviceId); contextParams.put("DEVICE_NAME", deviceName); diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/type-view.hbs b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/type-view.hbs index fee37a2ee0..4a4678c4cb 100644 --- a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/type-view.hbs +++ b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/type-view.hbs @@ -9,8 +9,7 @@
+ target="_blank">[ here ] for latest instructions and troubleshooting.
@@ -165,7 +164,8 @@
  • 03   Fill login form with the credentials. - (Use server URL as [ https://<WSO2_IoT_SERVER_HOST>:<SERVER_PORT> ] and click on + (Use server URL as [ https://<WSO2_IoT_SERVER_HOST>:<HTTPS_SERVER_PORT> ] + and click on Register Device button.)
  • diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs index 11b2451d5c..56164fbb7e 100644 --- a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs +++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs @@ -9,8 +9,7 @@
    + target="_blank">[ here ] for latest instructions and troubleshooting.
    diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs index 99d7db07e0..d6d30c132a 100644 --- a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs +++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs @@ -9,8 +9,7 @@
    + target="_blank">[ here ] for latest instructions and troubleshooting.
    diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/type-view.hbs b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/type-view.hbs index 5fb7c271ef..0748cdb853 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/type-view.hbs +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/type-view.hbs @@ -9,8 +9,7 @@
    + target="_blank">[ here ] for latest instructions and troubleshooting.
    diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs index a285c72f86..1a5fb8eea3 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs @@ -9,8 +9,7 @@
    + target="_blank">[ here ] for latest instructions and troubleshooting.
    diff --git a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/type-view.hbs b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/type-view.hbs index 8b8266d0d8..f20111f212 100644 --- a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/type-view.hbs +++ b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/type-view.hbs @@ -8,8 +8,7 @@
    + target="_blank">[ here ] for latest instructions and troubleshooting.
    diff --git a/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/type-view.hbs b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/type-view.hbs index 0aeb79a807..09c98431b0 100644 --- a/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/type-view.hbs +++ b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/type-view.hbs @@ -8,8 +8,7 @@
    + target="_blank">[ here ] for latest instructions and troubleshooting.
    diff --git a/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/type-view.hbs b/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/type-view.hbs index 700c136ac1..ad002615ca 100644 --- a/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/type-view.hbs +++ b/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/type-view.hbs @@ -8,8 +8,7 @@
    + target="_blank">[ here ] for latest instructions and troubleshooting.