diff --git a/src/main/java/org/elasticsearch/watcher/support/http/HttpClient.java b/src/main/java/org/elasticsearch/watcher/support/http/HttpClient.java index bbf1252ed10..c9a1c4b3da8 100644 --- a/src/main/java/org/elasticsearch/watcher/support/http/HttpClient.java +++ b/src/main/java/org/elasticsearch/watcher/support/http/HttpClient.java @@ -61,7 +61,7 @@ public class HttpClient extends AbstractComponent { public HttpResponse execute(HttpRequest request) throws IOException { String queryString = null; - if (request.params() != null) { + if (request.params() != null && !request.params().isEmpty()) { StringBuilder builder = new StringBuilder(); for (Map.Entry entry : request.params().entrySet()) { if (builder.length() != 0) { diff --git a/src/test/java/org/elasticsearch/watcher/support/http/HttpClientTest.java b/src/test/java/org/elasticsearch/watcher/support/http/HttpClientTest.java index 0e0093155e5..74ea88fbffc 100644 --- a/src/test/java/org/elasticsearch/watcher/support/http/HttpClientTest.java +++ b/src/test/java/org/elasticsearch/watcher/support/http/HttpClientTest.java @@ -28,6 +28,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; /** */ @@ -98,6 +99,22 @@ public class HttpClientTest extends ElasticsearchTestCase { assertThat(recordedRequest.getHeader(headerKey), equalTo(headerValue)); } + @Test + public void testNoQueryString() throws Exception { + webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body")); + HttpRequest.Builder requestBuilder = HttpRequest.builder("localhost", webPort) + .method(HttpMethod.GET) + .path("/test"); + + HttpResponse response = httpClient.execute(requestBuilder.build()); + assertThat(response.status(), equalTo(200)); + assertThat(response.body().toUtf8(), equalTo("body")); + + RecordedRequest recordedRequest = webServer.takeRequest(); + assertThat(recordedRequest.getPath(), equalTo("/test")); + assertThat(recordedRequest.getBody().readUtf8Line(), nullValue()); + } + @Test public void testBasicAuth() throws Exception { webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body")); @@ -110,6 +127,7 @@ public class HttpClientTest extends ElasticsearchTestCase { assertThat(response.status(), equalTo(200)); assertThat(response.body().toUtf8(), equalTo("body")); RecordedRequest recordedRequest = webServer.takeRequest(); + assertThat(recordedRequest.getPath(), equalTo("/test")); assertThat(recordedRequest.getHeader("Authorization"), equalTo("Basic dXNlcjpwYXNz")); } @@ -132,6 +150,7 @@ public class HttpClientTest extends ElasticsearchTestCase { assertThat(response.status(), equalTo(200)); assertThat(response.body().toUtf8(), equalTo("body")); RecordedRequest recordedRequest = webServer.takeRequest(); + assertThat(recordedRequest.getPath(), equalTo("/test")); assertThat(recordedRequest.getBody().readUtf8Line(), equalTo("body")); } diff --git a/src/test/java/org/elasticsearch/watcher/test/integration/WebhookHttpsIntegrationTests.java b/src/test/java/org/elasticsearch/watcher/test/integration/WebhookHttpsIntegrationTests.java index 7320a9c8228..eb0ae6c82b9 100644 --- a/src/test/java/org/elasticsearch/watcher/test/integration/WebhookHttpsIntegrationTests.java +++ b/src/test/java/org/elasticsearch/watcher/test/integration/WebhookHttpsIntegrationTests.java @@ -111,7 +111,7 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest assertWatchWithMinimumPerformedActionsCount("_id", 1, false); RecordedRequest recordedRequest = webServer.takeRequest(); - assertThat(recordedRequest.getPath(), equalTo("/test/_id?")); + assertThat(recordedRequest.getPath(), equalTo("/test/_id")); assertThat(recordedRequest.getBody().readUtf8Line(), equalTo("{key=value}")); SearchResponse response = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") @@ -146,7 +146,7 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest assertWatchWithMinimumPerformedActionsCount("_id", 1, false); RecordedRequest recordedRequest = webServer.takeRequest(); - assertThat(recordedRequest.getPath(), equalTo("/test/_id?")); + assertThat(recordedRequest.getPath(), equalTo("/test/_id")); assertThat(recordedRequest.getBody().readUtf8Line(), equalTo("{key=value}")); assertThat(recordedRequest.getHeader("Authorization"), equalTo("Basic X3VzZXJuYW1lOl9wYXNzd29yZA==")); }