diff --git a/pom.xml b/pom.xml
index 1768ccf9af1..075df7d5eb6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -269,7 +269,6 @@
true
-
${basedir}/src/test/resources
@@ -277,7 +276,6 @@
**/*.*
-
${basedir}/rest-api-spec
rest-api-spec
@@ -287,7 +285,6 @@
-
org.apache.maven.plugins
diff --git a/src/main/java/org/elasticsearch/watcher/actions/index/IndexAction.java b/src/main/java/org/elasticsearch/watcher/actions/index/IndexAction.java
index 8e46cb8bbab..5770c92090f 100644
--- a/src/main/java/org/elasticsearch/watcher/actions/index/IndexAction.java
+++ b/src/main/java/org/elasticsearch/watcher/actions/index/IndexAction.java
@@ -38,8 +38,8 @@ public class IndexAction extends Action {
private final ClientProxy client;
- private final String index;
- private final String type;
+ final String index;
+ final String type;
public IndexAction(ESLogger logger, @Nullable Transform transform, ClientProxy client, String index, String type) {
super(logger, transform);
@@ -235,8 +235,8 @@ public class IndexAction extends Action {
public static class Result extends Action.Result {
- private final Payload response;
- private final String reason;
+ final Payload response;
+ final String reason;
public Result(Payload response, String reason, boolean isCreated) {
super(TYPE, isCreated);
diff --git a/src/main/java/org/elasticsearch/watcher/actions/webhook/WebhookAction.java b/src/main/java/org/elasticsearch/watcher/actions/webhook/WebhookAction.java
index 7d0e32df67c..bfb0a0bde86 100644
--- a/src/main/java/org/elasticsearch/watcher/actions/webhook/WebhookAction.java
+++ b/src/main/java/org/elasticsearch/watcher/actions/webhook/WebhookAction.java
@@ -7,6 +7,7 @@ package org.elasticsearch.watcher.actions.webhook;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
+import org.elasticsearch.common.base.Charsets;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
@@ -23,15 +24,15 @@ import org.elasticsearch.watcher.support.http.HttpClient;
import org.elasticsearch.watcher.support.http.HttpMethod;
import org.elasticsearch.watcher.support.http.HttpResponse;
import org.elasticsearch.watcher.support.template.Template;
-import org.elasticsearch.watcher.support.template.XContentTemplate;
import org.elasticsearch.watcher.transform.Transform;
import org.elasticsearch.watcher.transform.TransformRegistry;
import org.elasticsearch.watcher.watch.Payload;
import org.elasticsearch.watcher.watch.WatchExecutionContext;
import java.io.IOException;
-import java.util.Locale;
-import java.util.Map;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.*;
/**
*/
@@ -41,9 +42,9 @@ public class WebhookAction extends Action {
private final HttpClient httpClient;
- private final HttpMethod method;
- private final Template url;
- private final @Nullable Template body;
+ final HttpMethod method;
+ final Template url;
+ final @Nullable Template body;
public WebhookAction(ESLogger logger, @Nullable Transform transform, HttpClient httpClient, HttpMethod method, Template url, Template body) {
super(logger, transform);
@@ -61,8 +62,14 @@ public class WebhookAction extends Action {
@Override
protected Result execute(WatchExecutionContext ctx, Payload payload) throws IOException {
Map model = Variables.createCtxModel(ctx, payload);
- String urlText = url.render(model);
- String bodyText = body != null ? body.render(model) : XContentTemplate.YAML.render(model);
+ Map urlSafeModel = new HashMap<>(model.size());
+
+ for (Map.Entry entry : model.entrySet()) {
+ urlSafeModel.put(entry.getKey(), makeURLSafe(entry.getValue()));
+ }
+
+ String urlText = url.render(urlSafeModel);
+ String bodyText = body != null ? body.render(model) : ""; //If body is null send an empty body
try {
try (HttpResponse response = httpClient.execute(method, urlText, bodyText)) {
int status = response.status();
@@ -158,7 +165,7 @@ public class WebhookAction extends Action {
@Override
protected XContentBuilder xContentBody(XContentBuilder builder, Params params) throws IOException {
- return builder.field("success", success())
+ return builder.field(SUCCESS_FIELD.getPreferredName(), success())
.field(WebhookAction.Parser.HTTP_STATUS_FIELD.getPreferredName(), httpStatus)
.field(WebhookAction.Parser.URL_FIELD.getPreferredName(), url)
.field(WebhookAction.Parser.BODY_FIELD.getPreferredName(), body);
@@ -174,6 +181,10 @@ public class WebhookAction extends Action {
this.reason = reason;
}
+ public String reason() {
+ return reason;
+ }
+
@Override
protected XContentBuilder xContentBody(XContentBuilder builder, Params params) throws IOException {
return builder.field(WebhookAction.Parser.REASON_FIELD.getPreferredName(), reason);
@@ -299,7 +310,8 @@ public class WebhookAction extends Action {
throw new ActionException("could not parse webhook result. expected boolean field [success]");
}
- Result result = success ? new Result.Executed(httpStatus, url, body) : new Result.Failure(reason);
+
+ Result result = (reason == null) ? new Result.Executed(httpStatus, url, body) : new Result.Failure(reason);
if (transformResult != null) {
result.transformResult(transformResult);
}
@@ -307,6 +319,28 @@ public class WebhookAction extends Action {
}
}
+ private Object makeURLSafe(Object toSafe) throws UnsupportedEncodingException {
+ if (toSafe instanceof List) {
+ List