From cef865f53ac18fa54ce901735b641eb07163b7b9 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Mon, 26 Sep 2016 17:13:43 +0530 Subject: [PATCH] Parsing deviceType configs with %https.ip% and %http.ip% --- .../jaggeryapps/devicemgt/app/modules/utility.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js index 3af4f59e6a..3b96ff0056 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js @@ -24,6 +24,7 @@ utility = function () { var log = new Log("/app/modules/utility.js"); var JavaClass = Packages.java.lang.Class; var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext; + var server = require("carbon")["server"]; var getOsgiService = function (className) { return PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(JavaClass.forName(className)); @@ -38,8 +39,8 @@ utility = function () { PrivilegedCarbonContext.startTenantFlow(); context = PrivilegedCarbonContext.getThreadLocalCarbonContext(); context.setTenantDomain(carbon.server.tenantDomain({ - tenantId: userInfo.tenantId - })); + tenantId: userInfo.tenantId + })); context.setTenantId(userInfo.tenantId); context.setUsername(userInfo.username || null); }; @@ -62,7 +63,7 @@ utility = function () { publicMethods.getDeviceTypeConfig = function (deviceType) { var unitName = publicMethods.getTenantedDeviceUnitName(deviceType, "type-view"); - + if (deviceType in deviceTypeConfigMap) { return deviceTypeConfigMap[deviceType]; } @@ -71,7 +72,10 @@ utility = function () { if (deviceTypeConfigFile.isExists()) { try { deviceTypeConfigFile.open("r"); - deviceTypeConfig = parse(deviceTypeConfigFile.readAll()); + var config = deviceTypeConfigFile.readAll(); + config = config.replace("%https.ip%", server.address("https")); + config = config.replace("%http.ip%", server.address("http")); + deviceTypeConfig = parse(config); } catch (err) { log.error("Error while reading device config file for `" + deviceType + "`: " + err); } finally {