From a984f8e0a76903bda0e210e8eb3fc55452a3b8a4 Mon Sep 17 00:00:00 2001 From: koda Date: Tue, 26 Jun 2018 22:59:11 +0900 Subject: [PATCH] Changed to display WebHook test results --- .../control/admin/WebhookControl.java | 9 ++++ src/main/resources/appresource.properties | 1 + src/main/resources/appresource_ja.properties | 1 + .../WEB-INF/views/admin/webhook/config.jsp | 45 ++++++++++++++++++- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/support/project/knowledge/control/admin/WebhookControl.java b/src/main/java/org/support/project/knowledge/control/admin/WebhookControl.java index f81f431dc..930c7eba7 100644 --- a/src/main/java/org/support/project/knowledge/control/admin/WebhookControl.java +++ b/src/main/java/org/support/project/knowledge/control/admin/WebhookControl.java @@ -21,7 +21,9 @@ import org.support.project.web.dao.ProxyConfigsDao; import org.support.project.web.entity.ProxyConfigsEntity; +import java.io.PrintWriter; import java.io.StringReader; +import java.io.StringWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -112,9 +114,16 @@ public Boundary test() throws Exception { WebhookLogic.get().notify(proxyConfig, webhookConfig, json); addMsgInfo("knowledge.webhook.test.success"); + setAttribute("TEST_JSON", json); } catch (Exception e) { LOG.error("WebHook test was error.", e); addMsgError("knowledge.webhook.test.error"); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + pw.flush(); + String str = sw.toString(); + setAttribute("TEST_ERROR_RESULT", str); } return config(); diff --git a/src/main/resources/appresource.properties b/src/main/resources/appresource.properties index 8a34a9c37..172e79313 100644 --- a/src/main/resources/appresource.properties +++ b/src/main/resources/appresource.properties @@ -695,6 +695,7 @@ knowledge.webhook.delete.error=Failed to delete the webhook settings. knowledge.webhook.delete.success=Deleted the setting of Webhooks. knowledge.webhook.test.error=Failed to test the webhook settings. knowledge.webhook.test.success=Test send of webhook was successful. +knowledge.webhook.test.result=Sended JSON knowledge.webhook.customize=Customize knowledge.webhook.customize.ignore.proxy=Ignore proxy knowledge.webhook.customize.template=Template of send JSON(When saved as empty it returns to the initial template) diff --git a/src/main/resources/appresource_ja.properties b/src/main/resources/appresource_ja.properties index 865227638..af0ec1e91 100644 --- a/src/main/resources/appresource_ja.properties +++ b/src/main/resources/appresource_ja.properties @@ -695,6 +695,7 @@ knowledge.webhook.delete.error=Webhookの設定の削除に失敗しました knowledge.webhook.delete.success=Webhookの設定を削除しました knowledge.webhook.test.error=Webhookのテスト送信に失敗しました knowledge.webhook.test.success=Webhookのテスト送信に成功しました +knowledge.webhook.test.result=テストで送信したJSON knowledge.webhook.customize=Customize knowledge.webhook.customize.ignore.proxy=Proxyを使わない knowledge.webhook.customize.template=送信するJSONのテンプレート(空で保存すると初期値に戻ります) diff --git a/src/main/webapp/WEB-INF/views/admin/webhook/config.jsp b/src/main/webapp/WEB-INF/views/admin/webhook/config.jsp index 019eb5230..2afe85039 100644 --- a/src/main/webapp/WEB-INF/views/admin/webhook/config.jsp +++ b/src/main/webapp/WEB-INF/views/admin/webhook/config.jsp @@ -17,6 +17,9 @@ .pull-right { margin-left: 5px; } +.bootbox-form > .bootbox-input-textarea { + height: 300px; +} @@ -93,6 +96,36 @@ function putConfig() { }); } +<% if (request.getAttribute("TEST_JSON") != null) { %> +var text = $('#TEST_JSON').val(); +try { + text = JSON.stringify(JSON.parse(text), null, ' '); +} catch(e) { +} +bootbox.prompt({ + title: "<%= jspUtil.label("knowledge.webhook.test.result") %>", + inputType: 'textarea', + value: text, + size: 'large', + callback: function (result) { + console.log(result); + } +}); +<% } %> + +<% if (request.getAttribute("TEST_ERROR_RESULT") != null) { %> +var text = $('#TEST_ERROR_RESULT').val(); +bootbox.prompt({ + title: "<%= jspUtil.label("knowledge.webhook.test.error") %>", + inputType: 'textarea', + value: text, + size: 'large', + callback: function (result) { + console.log(result); + } +}); +<% } %> + @@ -208,7 +241,17 @@ function putConfig() { - +
+<% if (request.getAttribute("TEST_JSON") != null) { %> + +<% } %> +<% if (request.getAttribute("TEST_ERROR_RESULT") != null) { %> + +<% } %>