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

Loading…
Cancel
Save