Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 696C0200CD3 for ; Fri, 28 Jul 2017 14:07:17 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6800E16C48D; Fri, 28 Jul 2017 12:07:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0BD2916CA10 for ; Fri, 28 Jul 2017 14:07:15 +0200 (CEST) Received: (qmail 33464 invoked by uid 500); 28 Jul 2017 12:07:15 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 33410 invoked by uid 99); 28 Jul 2017 12:07:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Jul 2017 12:07:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F088BF3304; Fri, 28 Jul 2017 12:07:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: yzhdanov@apache.org To: commits@ignite.apache.org Date: Fri, 28 Jul 2017 12:07:30 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [18/50] [abbrv] ignite git commit: IGNITE-5754 Web Console agent: Use POST instead of GET for requests. archived-at: Fri, 28 Jul 2017 12:07:17 -0000 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/ignite-5658 Commit: abc6e46fb9ec1c5ee228c01943c516ba0f602456 Parents: 95f4abc Author: Andrey Novikov Authored: Mon Jul 24 10:54:01 2017 +0700 Committer: Andrey Novikov 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.?} 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 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 params, - String mtd, Map headers, String body) throws IOException { + Map 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 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 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 params, - String mtd, Map headers, String body) { + Map 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); } }