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); }