diff --git a/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/common/http/HttpClient.java b/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/common/http/HttpClient.java index 597425a2c23..95cef69c9d7 100644 --- a/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/common/http/HttpClient.java +++ b/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/common/http/HttpClient.java @@ -241,8 +241,9 @@ public class HttpClient extends AbstractComponent { try { List qparams = new ArrayList<>(request.params.size()); request.params.forEach((k, v) -> qparams.add(new BasicNameValuePair(k, v))); + String format = URLEncodedUtils.format(qparams, "UTF-8"); URI uri = URIUtils.createURI(request.scheme.scheme(), request.host, request.port, request.path, - URLEncodedUtils.format(qparams, "UTF-8"), null); + Strings.isNullOrEmpty(format) ? null : format, null); return uri; } catch (URISyntaxException e) { diff --git a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java index 2cf657f0557..2a02c5300bd 100644 --- a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java +++ b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java @@ -595,4 +595,15 @@ public class HttpClientTests extends ESTestCase { assertThat(webServer.requests().get(0).getHeader(HttpHeaders.CONTENT_TYPE), is(XContentType.JSON.mediaType())); assertThat(webServer.requests().get(0).getBody(), is(body)); } + + public void testThatUrlDoesNotContainQuestionMarkAtTheEnd() throws Exception { + webServer.enqueue(new MockResponse().setResponseCode(200).setBody("whatever")); + + HttpRequest request = HttpRequest.builder("localhost", webServer.getPort()) + .path("foo") + .build(); + httpClient.execute(request); + assertThat(webServer.requests(), hasSize(1)); + assertThat(webServer.requests().get(0).getUri().getRawPath(), is("/foo")); + } }