From cf1ecdc242cdaa791dacb26c541ac9e833822869 Mon Sep 17 00:00:00 2001 From: Brian Jung Date: Wed, 23 May 2018 17:21:27 +0900 Subject: [PATCH] Support UTF8 encoding. --- .../com/rundeck/plugin/HttpNotificationPlugin.groovy | 11 +++++++++-- src/test/groovy/HttpNotificationPluginSpec.groovy | 10 ++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/groovy/com/rundeck/plugin/HttpNotificationPlugin.groovy b/src/main/groovy/com/rundeck/plugin/HttpNotificationPlugin.groovy index d1cb871..30ad979 100644 --- a/src/main/groovy/com/rundeck/plugin/HttpNotificationPlugin.groovy +++ b/src/main/groovy/com/rundeck/plugin/HttpNotificationPlugin.groovy @@ -14,8 +14,10 @@ import com.google.gson.Gson import com.rundeck.plugin.oauth.OAuthClient import groovyx.net.http.ContentType import groovyx.net.http.HTTPBuilder +import groovyx.net.http.EncoderRegistry import groovyx.net.http.Method import org.apache.log4j.Logger +import java.nio.charset.Charset; /** * Created by rundeck on 12/27/17. @@ -207,7 +209,8 @@ class HttpNotificationPlugin implements NotificationPlugin, Describable { } @Override - boolean postNotification(String trigger, Map executionData, Map config) { + boolean postNotification(String trigger, Map executionData, Map config) + { String remoteUrl = config.containsKey(HTTP_URL) ? config.get(HTTP_URL).toString() : null String method = config.containsKey(HTTP_METHOD) ? config.get(HTTP_METHOD).toString() : null String contentTypeStr = config.containsKey(HTTP_CONTENT_TYPE) ? config.get(HTTP_CONTENT_TYPE).toString() : null @@ -228,6 +231,9 @@ class HttpNotificationPlugin implements NotificationPlugin, Describable { def requestBody = parseBody(bodyStr) def http = new HTTPBuilder() + + http.encoderRegistry = new EncoderRegistry( charset: 'utf-8' ) + if(ignoreSSL){ http.ignoreSSLIssues() } @@ -311,7 +317,8 @@ class HttpNotificationPlugin implements NotificationPlugin, Describable { return result } - Map parseHeaders(String headers){ + Map parseHeaders(String headers) + { Map requestHeaders = new HashMap<>(); //checking json diff --git a/src/test/groovy/HttpNotificationPluginSpec.groovy b/src/test/groovy/HttpNotificationPluginSpec.groovy index 785a7e9..f9ba45b 100644 --- a/src/test/groovy/HttpNotificationPluginSpec.groovy +++ b/src/test/groovy/HttpNotificationPluginSpec.groovy @@ -11,11 +11,13 @@ class HttpNotificationPluginSpec extends Specification{ def notificator = new HttpNotificationPlugin() - String remoteUrl="http://google.com" - String methodStr = "GET" - String contentType ="text/html" + String remoteUrl="https://outlook.office.com/webhook/79d86a26-f956-4e3a-bc3a-9dc11cc6903f@b1fd7989-50d8-455b-9070-a00d818974ec/IncomingWebhook/8cf770284a124a92a52a39c8f7895eb3/1b958be6-edb8-44db-b423-f8fcafb1a1fe" + String methodStr = "POST" + String contentType ="application/json" + String bodyStr1 = "{\"text\":\"1111111111111wrong ν•œκΈ€μ€.\"}"; + String bodyStr = new String(bodyStr1.getBytes("UTF-8"),"UTF-8"); def executionData = [:] - def config = [remoteUrl:remoteUrl,method:methodStr,contentType:contentType] + def config = [remoteUrl:remoteUrl,method:methodStr,contentType:contentType,body:bodyStr] String trigger ="success" when: