Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
using all 2XX response status as valid response
  • Loading branch information
Matthias Fleißig committed May 9, 2019
1 parent a238e2e commit 76c20cc
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> 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() {
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 76c20cc

Please sign in to comment.