Merge pull request #155 from ayyoob/apir

skipped reading from configuration file for api client
Dilan U. Ariyaratne 9 years ago
commit 2228836b32

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

Loading…
Cancel
Save