ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [05/11] ignite git commit: IGNITE-5754 Web Console agent: Use POST instead of GET for requests.
Date Tue, 25 Jul 2017 10:17:56 GMT
IGNITE-5754 Web Console agent: Use POST instead of GET for requests.


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

Branch: refs/heads/master
Commit: abc6e46fb9ec1c5ee228c01943c516ba0f602456
Parents: 95f4abc
Author: Andrey Novikov <anovikov@gridgain.com>
Authored: Mon Jul 24 10:54:01 2017 +0700
Committer: Andrey Novikov <anovikov@gridgain.com>
Committed: Mon Jul 24 10:54:01 2017 +0700

----------------------------------------------------------------------
 modules/web-console/backend/app/agentSocket.js  |  4 +-
 .../web-console/backend/app/browsersHandler.js  |  2 +-
 .../console/agent/handlers/RestListener.java    |  7 +--
 .../ignite/console/agent/rest/RestExecutor.java | 49 +++++++-------------
 4 files changed, 22 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/abc6e46f/modules/web-console/backend/app/agentSocket.js
----------------------------------------------------------------------
diff --git a/modules/web-console/backend/app/agentSocket.js b/modules/web-console/backend/app/agentSocket.js
index db1deaa..0853339 100644
--- a/modules/web-console/backend/app/agentSocket.js
+++ b/modules/web-console/backend/app/agentSocket.js
@@ -126,7 +126,7 @@ module.exports.factory = function(_) {
          * Send event to agent.
          *
          * @param {String} event - Event name.
-         * @param {Array.<Object>?} args - Transmitted arguments.
+         * @param {Object?} args - Transmitted arguments.
          * @returns {Promise}
          */
         emitEvent(event, ...args) {
@@ -202,7 +202,7 @@ module.exports.factory = function(_) {
                 params[`p${idx + 1}`] = args[idx];
             });
 
-            return this.emitEvent('node:rest', {uri: 'ignite', demo, params, method: 'GET'})
+            return this.emitEvent('node:rest', {uri: 'ignite', demo, params})
                 .then(this.restResultParse);
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/abc6e46f/modules/web-console/backend/app/browsersHandler.js
----------------------------------------------------------------------
diff --git a/modules/web-console/backend/app/browsersHandler.js b/modules/web-console/backend/app/browsersHandler.js
index c4ea532..4fb5088 100644
--- a/modules/web-console/backend/app/browsersHandler.js
+++ b/modules/web-console/backend/app/browsersHandler.js
@@ -179,7 +179,7 @@ module.exports.factory = (_, socketio, configure, errors, mongo) =>
{
          */
         executeOnNode(agent, demo, params) {
             return agent
-                .then((agentSock) => agentSock.emitEvent('node:rest', {uri: 'ignite',
demo, params, method: 'GET'}))
+                .then((agentSock) => agentSock.emitEvent('node:rest', {uri: 'ignite',
demo, params}))
                 .then((res) => {
                     if (res.status === 0)
                         return JSON.parse(res.data);

http://git-wip-us.apache.org/repos/asf/ignite/blob/abc6e46f/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/RestListener.java
----------------------------------------------------------------------
diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/RestListener.java
b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/RestListener.java
index c70514d..8855060 100644
--- a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/RestListener.java
+++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/RestListener.java
@@ -61,11 +61,6 @@ public class RestListener extends AbstractListener {
 
         boolean demo = (boolean)args.get("demo");
 
-        if (!args.containsKey("method"))
-            throw new IllegalArgumentException("Missing method in arguments: " + args);
-
-        String mtd = args.get("method").toString();
-
         Map<String, Object> headers = null;
 
         if (args.containsKey("headers"))
@@ -76,6 +71,6 @@ public class RestListener extends AbstractListener {
         if (args.containsKey("body"))
             body = args.get("body").toString();
 
-        return restExecutor.execute(demo, path, params, mtd, headers, body);
+        return restExecutor.execute(demo, path, params, headers, body);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/abc6e46f/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/rest/RestExecutor.java
----------------------------------------------------------------------
diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/rest/RestExecutor.java
b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/rest/RestExecutor.java
index 3936374..03eca4e 100644
--- a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/rest/RestExecutor.java
+++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/rest/RestExecutor.java
@@ -90,7 +90,7 @@ public class RestExecutor {
 
     /** */
     private RestResult sendRequest(boolean demo, String path, Map<String, Object> params,
-        String mtd, Map<String, Object> headers, String body) throws IOException {
+        Map<String, Object> headers, String body) throws IOException {
         if (demo && AgentClusterDemo.getDemoUrl() == null) {
             try {
                 AgentClusterDemo.tryStart().await();
@@ -120,36 +120,24 @@ public class RestExecutor {
                     reqBuilder.addHeader(entry.getKey(), entry.getValue().toString());
         }
 
-        if ("GET".equalsIgnoreCase(mtd)) {
+        if (body != null) {
+            MediaType contentType = MediaType.parse("text/plain");
+
+            reqBuilder.post(RequestBody.create(contentType, body));
+        }
+        else {
+            FormBody.Builder formBody = new FormBody.Builder();
+
             if (params != null) {
                 for (Map.Entry<String, Object> entry : params.entrySet()) {
                     if (entry.getValue() != null)
-                        urlBuilder.addQueryParameter(entry.getKey(), entry.getValue().toString());
+                        formBody.add(entry.getKey(), entry.getValue().toString());
                 }
             }
-        }
-        else if ("POST".equalsIgnoreCase(mtd)) {
-            if (body != null) {
-                MediaType contentType = MediaType.parse("text/plain");
-
-                reqBuilder.post(RequestBody.create(contentType, body));
-            }
-            else {
-                FormBody.Builder formBody = new FormBody.Builder();
-
-                if (params != null) {
-                    for (Map.Entry<String, Object> entry : params.entrySet()) {
-                        if (entry.getValue() != null)
-                            formBody.add(entry.getKey(), entry.getValue().toString());
-                    }
-                }
 
-                reqBuilder.post(formBody.build());
-            }
+            reqBuilder.post(formBody.build());
         }
-        else
-            throw new IllegalArgumentException("Unknown HTTP-method: " + mtd);
-
+        
         reqBuilder.url(urlBuilder.build());
 
         try (Response resp = httpClient.newCall(reqBuilder.build()).execute()) {
@@ -180,7 +168,7 @@ public class RestExecutor {
                 "Please ensure that nodes have [ignite-rest-http] module in classpath " +
                 "(was copied from libs/optional to libs folder).");
 
-            throw new ConnectException("Failed connect to node and execute REST command [url="
+ urlBuilder + "]");
+            throw new ConnectException("Failed connect to node and execute REST command [url="
+ urlBuilder + ", parameters=" + params + "]");
         }
     }
 
@@ -188,21 +176,20 @@ public class RestExecutor {
      * @param demo Is demo node request.
      * @param path Path segment.
      * @param params Params.
-     * @param mtd Method.
      * @param headers Headers.
      * @param body Body.
      */
     public RestResult execute(boolean demo, String path, Map<String, Object> params,
-        String mtd, Map<String, Object> headers, String body) {
+        Map<String, Object> headers, String body) {
         if (log.isDebugEnabled())
-            log.debug("Start execute REST command [method=" + mtd + ", uri=/" + (path ==
null ? "" : path) +
+            log.debug("Start execute REST command [uri=/" + (path == null ? "" : path) +
                 ", parameters=" + params + "]");
 
         try {
-            return sendRequest(demo, path, params, mtd, headers, body);
+            return sendRequest(demo, path, params, headers, body);
         }
         catch (Exception e) {
-            U.error(log, "Failed to execute REST command [method=" + mtd + ", uri=/" + (path
== null ? "" : path) +
+            U.error(log, "Failed to execute REST command [uri=/" + (path == null ? "" : path)
+
                 ", parameters=" + params + "]", e);
 
             return RestResult.fail(404, e.getMessage());
@@ -219,6 +206,6 @@ public class RestExecutor {
         params.put("attr", true);
         params.put("mtr", full);
 
-        return sendRequest(demo, "ignite", params, "GET", null, null);
+        return sendRequest(demo, "ignite", params, null, null);
     }
 }


Mime
View raw message