From 67199866a077a80c1a8a0480e8152537e17afbe2 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 13 Jan 2016 17:30:38 +0530 Subject: [PATCH 1/3] skipped reading from configuration file --- .../device/mgt/iot/apimgt/ApisAppClient.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) 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..0586fbd393 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 @@ -81,14 +81,19 @@ public class ApisAppClient { String consumerKeyAndSecret = deviceTypeToApiAppMap.get(deviceType); 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); - } + IotDeviceTypeConfig deviceTypeConfig = IotDeviceTypeConfigurationManager.getInstance().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; @@ -132,8 +137,6 @@ public class ApisAppClient { getMethod.setHeader("cookie", cookie); httpResponse = httpClient.execute(getMethod); response = IoTUtil.getResponseString(httpResponse); - - if(log.isDebugEnabled()) { log.debug(response); } From c72ebbe367ec6bac09dc4a90350761649df85bb9 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 13 Jan 2016 18:23:05 +0530 Subject: [PATCH 2/3] with changes with formatting --- .../device/mgt/iot/apimgt/ApisAppClient.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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 0586fbd393..83a37fa28a 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 @@ -77,14 +77,20 @@ public class ApisAppClient { } public String getBase64EncodedConsumerKeyAndSecret(String deviceType) { - if(!isEnabled) return null; + if (!isEnabled) 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) { + IotDeviceTypeConfigurationManager deviceTypeConfigurationManager = + IotDeviceTypeConfigurationManager.getInstance(); + IotDeviceTypeConfig deviceTypeConfig = null; + if (deviceTypeConfigurationManager != null) { + deviceTypeConfig = deviceTypeConfigurationManager.getIotDeviceTypeConfigMap().get( + deviceType); + } + if (deviceTypeConfig != null) { iotDeviceTypeConfigs.add(deviceTypeConfig); - }else{ + } else { deviceTypeConfig = new IotDeviceTypeConfig(); deviceTypeConfig.setType(deviceType); deviceTypeConfig.setApiApplicationName(deviceType); @@ -92,11 +98,11 @@ public class ApisAppClient { } setBase64EncodedConsumerKeyAndSecret(iotDeviceTypeConfigs); consumerKeyAndSecret = deviceTypeToApiAppMap.get(deviceType); - if(consumerKeyAndSecret==null){ + if (consumerKeyAndSecret == null) { log.warn("There is no API application for the device type " + deviceType); } } - return consumerKeyAndSecret; + return consumerKeyAndSecret; } public void setBase64EncodedConsumerKeyAndSecret(List iotDeviceTypeConfigList) { From 3a4b3ada46c63c3ddf453975f150fb50be48a699 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 13 Jan 2016 18:33:39 +0530 Subject: [PATCH 3/3] renamed the variable --- .../wso2/carbon/device/mgt/iot/apimgt/ApisAppClient.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 83a37fa28a..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,7 +77,7 @@ public class ApisAppClient { } public String getBase64EncodedConsumerKeyAndSecret(String deviceType) { - if (!isEnabled) return null; + if (!isApiManagerEnabled) return null; String consumerKeyAndSecret = deviceTypeToApiAppMap.get(deviceType); if (consumerKeyAndSecret == null) { ArrayList iotDeviceTypeConfigs = new ArrayList<>(); @@ -106,7 +106,7 @@ public class ApisAppClient { } public void setBase64EncodedConsumerKeyAndSecret(List iotDeviceTypeConfigList) { - if(!isEnabled) return; + if(!isApiManagerEnabled) return; URL loginURL = null; try {