From 809992fb9f3b20ef88b3464a9a8b7c85cdd4d765 Mon Sep 17 00:00:00 2001 From: GPrathap Date: Mon, 2 Jan 2017 15:33:01 +0530 Subject: [PATCH 1/2] remove hardcoded oauth2 token --- .../geo-dashboard/js/websocket.js | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/js/websocket.js b/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/js/websocket.js index 30fcb20d4..7c27e57f0 100644 --- a/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/js/websocket.js +++ b/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/js/websocket.js @@ -690,25 +690,26 @@ function intializeWebsocketUrls() { deviceId = state.device.id; deviceType = state.device.type; if (deviceId && deviceType) { - //TODO need to get the token wso2.gadgets.identity.getUsername(function (username) { - $.getJSON("/portal/store/carbon.super/fs/gadget/geo-dashboard/controllers/get_server_info.jag?username=" + username, function (data) { - webSocketURL = 'wss://' + data.ip + ':' + data.httpsPort + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance - .CEP_WEB_SOCKET_OUTPUT_ADAPTOR_WEBAPP_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions - .constance.TENANT_INDEX + ApplicationOptions.constance.PATH_SEPARATOR + data.user.domain + - ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance - .CEP_WEB_SOCKET_OUTPUT_ADAPTOR_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance.VERSION - + "?deviceId=" + deviceId + "&deviceType=" + deviceType; - alertWebSocketURL = 'wss://' + data.ip + ':' + data.httpsPort + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance - .CEP_WEB_SOCKET_OUTPUT_ADAPTOR_WEBAPP_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions - .constance.TENANT_INDEX + ApplicationOptions.constance.PATH_SEPARATOR + data.user.domain + - ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance - .CEP_ON_ALERT_WEB_SOCKET_OUTPUT_ADAPTOR_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance.VERSION - + "?deviceId=" + deviceId + "&deviceType=" + deviceType; - document.cookie = "websocket-token=619e6170-10e8-31f0-904b-b7770d53e545; path=/"; - $("#proximity_alert").hide(); - initializeWebSocket(); - initializeOnAlertWebSocket(); + wso2.gadgets.identity.getAccessToken(function (accessToken) { + $.getJSON("/portal/store/carbon.super/fs/gadget/geo-dashboard/controllers/get_server_info.jag?username=" + username, function (data) { + webSocketURL = 'wss://' + data.ip + ':' + data.httpsPort + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance + .CEP_WEB_SOCKET_OUTPUT_ADAPTOR_WEBAPP_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions + .constance.TENANT_INDEX + ApplicationOptions.constance.PATH_SEPARATOR + data.user.domain + + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance + .CEP_WEB_SOCKET_OUTPUT_ADAPTOR_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance.VERSION + + "?deviceId=" + deviceId + "&deviceType=" + deviceType; + alertWebSocketURL = 'wss://' + data.ip + ':' + data.httpsPort + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance + .CEP_WEB_SOCKET_OUTPUT_ADAPTOR_WEBAPP_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions + .constance.TENANT_INDEX + ApplicationOptions.constance.PATH_SEPARATOR + data.user.domain + + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance + .CEP_ON_ALERT_WEB_SOCKET_OUTPUT_ADAPTOR_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance.VERSION + + "?deviceId=" + deviceId + "&deviceType=" + deviceType; + document.cookie = "websocket-token="+accessToken+"; path=/"; + $("#proximity_alert").hide(); + initializeWebSocket(); + initializeOnAlertWebSocket(); + }); }); }); } else { From 29cff5ae8ad10de8a126b1f53708fb9e1c7c7c48 Mon Sep 17 00:00:00 2001 From: sinthuja Date: Tue, 3 Jan 2017 13:31:30 +0530 Subject: [PATCH 2/2] fixing the ip resolving issue. --- .../geo-dashboard/js/websocket.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/js/websocket.js b/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/js/websocket.js index 7c27e57f0..ced06d049 100644 --- a/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/js/websocket.js +++ b/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/js/websocket.js @@ -689,23 +689,25 @@ function intializeWebsocketUrls() { wso2.gadgets.state.getGlobalState(function (state) { deviceId = state.device.id; deviceType = state.device.type; + var hostname = window.parent.location.hostname; + var port = window.parent.location.port; if (deviceId && deviceType) { wso2.gadgets.identity.getUsername(function (username) { wso2.gadgets.identity.getAccessToken(function (accessToken) { $.getJSON("/portal/store/carbon.super/fs/gadget/geo-dashboard/controllers/get_server_info.jag?username=" + username, function (data) { - webSocketURL = 'wss://' + data.ip + ':' + data.httpsPort + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance + webSocketURL = 'wss://' + hostname + ':' + port + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance .CEP_WEB_SOCKET_OUTPUT_ADAPTOR_WEBAPP_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions .constance.TENANT_INDEX + ApplicationOptions.constance.PATH_SEPARATOR + data.user.domain + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance .CEP_WEB_SOCKET_OUTPUT_ADAPTOR_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance.VERSION + "?deviceId=" + deviceId + "&deviceType=" + deviceType; - alertWebSocketURL = 'wss://' + data.ip + ':' + data.httpsPort + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance + alertWebSocketURL = 'wss://' + hostname + ':' + port + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance .CEP_WEB_SOCKET_OUTPUT_ADAPTOR_WEBAPP_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions .constance.TENANT_INDEX + ApplicationOptions.constance.PATH_SEPARATOR + data.user.domain + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance .CEP_ON_ALERT_WEB_SOCKET_OUTPUT_ADAPTOR_NAME + ApplicationOptions.constance.PATH_SEPARATOR + ApplicationOptions.constance.VERSION + "?deviceId=" + deviceId + "&deviceType=" + deviceType; - document.cookie = "websocket-token="+accessToken+"; path=/"; + document.cookie = "websocket-token=" + accessToken + "; path=/"; $("#proximity_alert").hide(); initializeWebSocket(); initializeOnAlertWebSocket();