From 76c20ccd0d72d0d471defdd261708d39ebce96b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Flei=C3=9Fig?= Date: Thu, 9 May 2019 09:11:00 +0200 Subject: [PATCH] Issue #49 using all 2XX response status as valid response --- .../destination/client/DestinationHttpClient.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/notification/src/main/java/com/amazon/opendistroforelasticsearch/alerting/destination/client/DestinationHttpClient.java b/notification/src/main/java/com/amazon/opendistroforelasticsearch/alerting/destination/client/DestinationHttpClient.java index dd6c8141..bd43ea92 100644 --- a/notification/src/main/java/com/amazon/opendistroforelasticsearch/alerting/destination/client/DestinationHttpClient.java +++ b/notification/src/main/java/com/amazon/opendistroforelasticsearch/alerting/destination/client/DestinationHttpClient.java @@ -54,6 +54,15 @@ public class DestinationHttpClient { private static final int TIMEOUT_MILLISECONDS = (int) TimeValue.timeValueSeconds(5).millis(); private static final int SOCKET_TIMEOUT_MILLISECONDS = (int)TimeValue.timeValueSeconds(50).millis(); + /** + * all valid response status + */ + private static final Set VALID_RESPONSE_STATUS = new HashSet<>( + Arrays.asList(RestStatus.OK.getStatus(), RestStatus.CREATED.getStatus(), RestStatus.ACCEPTED.getStatus(), + RestStatus.NON_AUTHORITATIVE_INFORMATION.getStatus(), RestStatus.NO_CONTENT.getStatus(), + RestStatus.RESET_CONTENT.getStatus(), RestStatus.PARTIAL_CONTENT.getStatus(), + RestStatus.MULTI_STATUS.getStatus())); + private static CloseableHttpClient HTTP_CLIENT = createHttpClient(); private static CloseableHttpClient createHttpClient() { @@ -153,7 +162,7 @@ public String getResponseString(CloseableHttpResponse response) throws IOExcepti private void validateResponseStatus(HttpResponse response) throws IOException { int statusCode = response.getStatusLine().getStatusCode(); - if (!(statusCode == RestStatus.OK.getStatus() || statusCode == RestStatus.CREATED.getStatus())) { + if (!(VALID_RESPONSE_STATUS.contains(statusCode))) { throw new IOException("Failed: " + response); } }