You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by pr...@apache.org on 2014/01/02 11:00:21 UTC

git commit: utility function for calling REST backend

Updated Branches:
  refs/heads/master 0225801ac -> ed4f4e4d4


utility function for calling REST backend


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/ed4f4e4d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/ed4f4e4d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/ed4f4e4d

Branch: refs/heads/master
Commit: ed4f4e4d4643f2e421dbfcbc08ad9c67f14b863e
Parents: 0225801
Author: Pradeep Fernando <pr...@gmail.com>
Authored: Thu Jan 2 15:30:01 2014 +0530
Committer: Pradeep Fernando <pr...@gmail.com>
Committed: Thu Jan 2 15:30:01 2014 +0530

----------------------------------------------------------------------
 .../org.apache.stratos.manager.console/app.js   |  2 +-
 .../util/utility.jag                            | 44 ++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ed4f4e4d/components/org.apache.stratos.manager.console/app.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager.console/app.js b/components/org.apache.stratos.manager.console/app.js
index 22fedcb..0883bb8 100644
--- a/components/org.apache.stratos.manager.console/app.js
+++ b/components/org.apache.stratos.manager.console/app.js
@@ -1,7 +1,7 @@
 var caramel = require('caramel');
 
 caramel.configs({
-    context: '/stratos',
+    context: '/console',
     cache: true,
     negotiation: true,
     themer: function () {

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ed4f4e4d/components/org.apache.stratos.manager.console/util/utility.jag
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager.console/util/utility.jag b/components/org.apache.stratos.manager.console/util/utility.jag
index eadec4b..dcc81da 100644
--- a/components/org.apache.stratos.manager.console/util/utility.jag
+++ b/components/org.apache.stratos.manager.console/util/utility.jag
@@ -74,4 +74,48 @@ function getServerUrl(){
     return serverUrl;
 }
 
+function getAuthenticationHeader(){
+    return {"Authorization": "Basic YWRtaW46YWRtaW4="};
+}
+
+function getBackendServerURL(){
+    var config = require('/config/console.json');
+    return config.backendServerConfiguration.url;
+}
+
+consoleAppUtil = new function(){
+    var log = new Log();
+    this.makeRequest = function(httpMethod,urlPostFix,data){
+        var endpoint = getBackendServerURL() + urlPostFix;
+        var headers = getAuthenticationHeader();
+        var type="json";
+        if(log.isDebugEnabeld()){
+            log.debug("HTTPMethod : " + httpMethod);
+            log.debug("HTTPEndpoint : "+endpoint);
+            log.debug("HTTPHeaders : "+headers);
+        }
+        var response;
+        switch(httpMethod){
+            case "GET":
+               response = get(endpoint,data,headers,type);
+                break;
+            case "POST":
+                response = post(endpoint,data,headers,type);
+                break;
+            case "DELETE":
+                response = del(endpoint,data,headers,type);
+                break;
+            case "PUT":
+                response = put(endpoint,data,headers,type);
+                break;
+            default :
+                response = {"data":"wrong data"}; // TODO: proper error handling.
+        }
+        log.info(response.data);
+        return response;
+    };
+};
+
+
+
 %>
\ No newline at end of file