From 4f04175225a878032bcc42fd002c737a0ceb1fe6 Mon Sep 17 00:00:00 2001 From: kramer Date: Wed, 8 Jul 2015 20:41:52 +0200 Subject: [PATCH] added http response code to JestResult - #208 & #220 --- .../main/java/io/searchbox/action/AbstractAction.java | 1 + .../src/main/java/io/searchbox/client/JestResult.java | 10 ++++++++++ jest-common/src/main/java/io/searchbox/core/Bulk.java | 1 + .../java/io/searchbox/action/AbstractActionTest.java | 1 + 4 files changed, 13 insertions(+) diff --git a/jest-common/src/main/java/io/searchbox/action/AbstractAction.java b/jest-common/src/main/java/io/searchbox/action/AbstractAction.java index 1e88167af..759b74a73 100644 --- a/jest-common/src/main/java/io/searchbox/action/AbstractAction.java +++ b/jest-common/src/main/java/io/searchbox/action/AbstractAction.java @@ -65,6 +65,7 @@ public AbstractAction(Builder builder) { protected T createNewElasticSearchResult(T result, String responseBody, int statusCode, String reasonPhrase, Gson gson) { JsonObject jsonMap = parseResponseBody(responseBody); + result.setResponseCode(statusCode); result.setJsonString(responseBody); result.setJsonObject(jsonMap); result.setPathToResult(getPathToResult()); diff --git a/jest-common/src/main/java/io/searchbox/client/JestResult.java b/jest-common/src/main/java/io/searchbox/client/JestResult.java index cf6fac095..38feb1dd4 100644 --- a/jest-common/src/main/java/io/searchbox/client/JestResult.java +++ b/jest-common/src/main/java/io/searchbox/client/JestResult.java @@ -26,6 +26,7 @@ public class JestResult { protected JsonObject jsonObject; protected String jsonString; protected String pathToResult; + protected int responseCode; protected boolean isSucceeded; protected String errorMessage; protected Gson gson; @@ -37,6 +38,7 @@ public JestResult(JestResult source) { this.jsonObject = source.jsonObject; this.jsonString = source.jsonString; this.pathToResult = source.pathToResult; + this.responseCode = source.responseCode; this.isSucceeded = source.isSucceeded; this.errorMessage = source.errorMessage; this.gson = source.gson; @@ -78,6 +80,14 @@ public String getErrorMessage() { return errorMessage; } + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + /** * manually set an error message, eg. for the cases where non-200 response code is received */ diff --git a/jest-common/src/main/java/io/searchbox/core/Bulk.java b/jest-common/src/main/java/io/searchbox/core/Bulk.java index 12238d1e0..96f5d4bbc 100644 --- a/jest-common/src/main/java/io/searchbox/core/Bulk.java +++ b/jest-common/src/main/java/io/searchbox/core/Bulk.java @@ -130,6 +130,7 @@ public BulkResult createNewElasticSearchResult(String responseBody, int statusCo @Override protected BulkResult createNewElasticSearchResult(BulkResult result, String responseBody, int statusCode, String reasonPhrase, Gson gson) { JsonObject jsonMap = parseResponseBody(responseBody); + result.setResponseCode(statusCode); result.setJsonString(responseBody); result.setJsonObject(jsonMap); result.setPathToResult(getPathToResult()); diff --git a/jest-common/src/test/java/io/searchbox/action/AbstractActionTest.java b/jest-common/src/test/java/io/searchbox/action/AbstractActionTest.java index de4f49029..cfb00a5cd 100644 --- a/jest-common/src/test/java/io/searchbox/action/AbstractActionTest.java +++ b/jest-common/src/test/java/io/searchbox/action/AbstractActionTest.java @@ -197,6 +197,7 @@ public void getSuccessIndexResult() { Index index = new Index.Builder("{\"abc\":\"dce\"}").index("test").build(); JestResult result = index.createNewElasticSearchResult(jsonString, 200, null, new Gson()); assertTrue(result.getErrorMessage(), result.isSucceeded()); + assertEquals(200, result.getResponseCode()); } @Test