Repository: stratos Updated Branches: refs/heads/master 6afd22ab6 -> e5b18001a
Stratos GUI does not direct to login page if server restart [STRATOS-1416] Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/e5b18001 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/e5b18001 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/e5b18001 Branch: refs/heads/master Commit: e5b18001a2db16e89171dfd789a444afa56ba00c Parents: 6afd22a Author: Dakshika Jayathilaka <[email protected]> Authored: Tue May 19 14:45:43 2015 +0530 Committer: Dakshika Jayathilaka <[email protected]> Committed: Tue May 19 14:47:22 2015 +0530 ---------------------------------------------------------------------- .../console/controllers/rest/rest_calls.jag | 179 ++++++++++--------- 1 file changed, 95 insertions(+), 84 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/e5b18001/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag b/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag index 2307038..26b3a22 100644 --- a/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag +++ b/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag @@ -328,52 +328,57 @@ RESTCalls = new function(){ this.sendReceive = function(httpMethod,urlPostFix,data){ var config = require('/config/console.js').config(); var backendServerURL = config.backendServerConfiguration.url; - // getting the access token from the session. - var endpoint = backendServerURL + urlPostFix; - var headers = this.getRequestHeaders(false); //NEED TO FIX THIS - var response; - switch (httpMethod){ - case "GET": - response = get(endpoint,{},headers); - break; - case "POST": - response = post(endpoint,stringify(data),headers); - break; - case "PUT": - response = put(endpoint,stringify(data),headers); - break; - case "DELETE": - response = del(endpoint,stringify(data),headers); - break; - default : - log.error("Error in the programme flow."); - } - if (response.xhr.status >= 200 && response.xhr.status < 300) { //if success - if(response.data != null && response.data != undefined) { - session.put("get-status", { "message": parse(response.data).message , "status": "success" }); - } - } else if (response.xhr.status >= 300 && response.xhr.status < 400) { //if redirects - if(response.data != null && response.data != undefined) { - session.put("get-status", { "message": parse(response.data).message , "status": "warning" } ); - } - } else if (response.xhr.status >= 400 && response.xhr.status < 500) { //if client error - if(response.data != null && response.data != undefined) { - session.put("get-status",{ "message": parse(response.data).message, "status": "error" } ); + //handle url null issue + if(backendServerURL.indexOf('null') >= 0 ){ + return request.getContextPath()+'/login/'; + }else { + // getting the access token from the session. + var endpoint = backendServerURL + urlPostFix; + var headers = this.getRequestHeaders(false); //NEED TO FIX THIS + var responseREST; + switch (httpMethod) { + case "GET": + responseREST = get(endpoint, {}, headers); + break; + case "POST": + responseREST = post(endpoint, stringify(data), headers); + break; + case "PUT": + responseREST = put(endpoint, stringify(data), headers); + break; + case "DELETE": + responseREST = del(endpoint, stringify(data), headers); + break; + default : + log.error("Error in the programme flow."); } - } else if (response.xhr.status >= 500 && response.xhr.status < 600) { //if server error - if(response.data != null && response.data != undefined) { - session.put("get-status", { "message": parse(response.data).message, "status": "error" } ); + if (responseREST.xhr.status >= 200 && responseREST.xhr.status < 300) { //if success + if (responseREST.data != null && responseREST.data != undefined) { + session.put("get-status", { "message": parse(responseREST.data).message, "status": "success" }); + } + } else if (responseREST.xhr.status >= 300 && responseREST.xhr.status < 400) { //if redirects + if (responseREST.data != null && responseREST.data != undefined) { + session.put("get-status", { "message": parse(responseREST.data).message, "status": "warning" }); + } + } else if (responseREST.xhr.status >= 400 && responseREST.xhr.status < 500) { //if client error + if (responseREST.data != null && responseREST.data != undefined) { + session.put("get-status", { "message": parse(responseREST.data).message, "status": "error" }); + } + } else if (responseREST.xhr.status >= 500 && responseREST.xhr.status < 600) { //if server error + if (responseREST.data != null && responseREST.data != undefined) { + session.put("get-status", { "message": parse(responseREST.data).message, "status": "error" }); + } + } else { + session.put("get-status", "Unknown response!"); } - } else { - session.put("get-status", "Unknown response!"); - } - log.debug("sent is: " + stringify(response)); + log.debug("sent is: " + stringify(responseREST)); - if (response.data != null && response.data != undefined) { - return parse(response.data); - } else { - return response.data; + if (responseREST.data != null && responseREST.data != undefined) { + return parse(responseREST.data); + } else { + return responseREST.data; + } } }; @@ -381,51 +386,57 @@ RESTCalls = new function(){ this.send = function(httpMethod,urlPostFix,data){ var config = require('/config/console.js').config(); var backendServerURL = config.backendServerConfiguration.url; - // getting the access token from the session. - var endpoint = backendServerURL + urlPostFix; - var headers = this.getRequestHeaders(false); //NEED TO FIX THIS - var response; - switch (httpMethod){ - case "GET": - response = get(endpoint,{},headers); - break; - case "POST": - response = post(endpoint,data,headers); - break; - case "PUT": - response = put(endpoint,data,headers); - break; - case "DELETE": - response = del(endpoint,data,headers); - break; - default : - log.error("Error in the programme flow."); - } - if (response.xhr.status >= 200 && response.xhr.status < 300) { //if success - if(response.data != null && response.data != undefined) { - session.put("deploy-status", { "message": parse(response.data).message , "status": "success" }); - } - } else if (response.xhr.status >= 300 && response.xhr.status < 400) { //if redirects - if(response.data != null && response.data != undefined) { - session.put("deploy-status",{ "message": parse(response.data).message, "status": "warning" } ); + //handle url null issue + if(backendServerURL.indexOf('null') >= 0){ + return request.getContextPath()+'/login/'; + }else { + // getting the access token from the session. + var endpoint = backendServerURL + urlPostFix; + var headers = this.getRequestHeaders(false); //NEED TO FIX THIS + var responseREST; + switch (httpMethod) { + case "GET": + responseREST = get(endpoint, {}, headers); + break; + case "POST": + responseREST = post(endpoint, data, headers); + break; + case "PUT": + responseREST = put(endpoint, data, headers); + break; + case "DELETE": + responseREST = del(endpoint, data, headers); + break; + default : + log.error("Error in the programme flow."); } - } else if (response.xhr.status >= 400 && response.xhr.status < 500) { //if client error - if(response.data != null && response.data != undefined) { - session.put("deploy-status", { "message": parse(response.data).message, "status": "error"}); + if (responseREST.xhr.status >= 200 && responseREST.xhr.status < 300) { //if success + if (responseREST.data != null && responseREST.data != undefined) { + session.put("deploy-status", { "message": parse(responseREST.data).message, "status": "success" }); + } + } else if (responseREST.xhr.status >= 300 && responseREST.xhr.status < 400) { //if redirects + if (responseREST.data != null && responseREST.data != undefined) { + session.put("deploy-status", { "message": parse(responseREST.data).message, "status": "warning" }); + } + } else if (responseREST.xhr.status >= 400 && responseREST.xhr.status < 500) { //if client error + if (responseREST.data != null && responseREST.data != undefined) { + session.put("deploy-status", { "message": parse(responseREST.data).message, "status": "error"}); + } + } else if (responseREST.xhr.status >= 500 && responseREST.xhr.status < 600) { //if server error + if (responseREST.data != null && responseREST.data != undefined) { + session.put("deploy-status", { "message": parse(responseREST.data).message, "status": "error"}); + } + } else { + session.put("deploy-status", "Unknown response!"); } - } else if (response.xhr.status >= 500 && response.xhr.status < 600) { //if server error - if(response.data != null && response.data != undefined) { - session.put("deploy-status", { "message": parse(response.data).message, "status": "error"}); + + if (responseREST.data != null && responseREST.data != undefined) { + return parse(responseREST.data); + } else { + return responseREST.data; } - } else { - session.put("deploy-status", "Unknown response!"); } - if (response.data != null && response.data != undefined) { - return parse(response.data); - } else { - return response.data; - } }; @@ -439,8 +450,8 @@ RESTCalls = new function(){ "Authorization": "Basic "+basicAuthToken, "Content-Type": "application/json" }; - var response = get(endpoint,{},headers,"json"); - return response; + var responseREST = get(endpoint,{},headers,"json"); + return responseREST; }; this.getAccessTokenFromSession = function(){
