|
|
@@ -8,17 +8,20 @@
|
|
|
|
|
|
package org.elasticsearch.http;
|
|
|
|
|
|
-import com.fasterxml.jackson.databind.JsonNode;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-
|
|
|
import org.elasticsearch.client.Request;
|
|
|
import org.elasticsearch.client.Response;
|
|
|
import org.elasticsearch.client.ResponseException;
|
|
|
+import org.elasticsearch.test.XContentTestUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
+import static org.hamcrest.Matchers.not;
|
|
|
+import static org.hamcrest.Matchers.nullValue;
|
|
|
import static org.hamcrest.Matchers.startsWith;
|
|
|
+import static org.hamcrest.collection.IsMapContaining.hasKey;
|
|
|
|
|
|
/**
|
|
|
* Tests that by default the error_trace parameter can be used to show stacktraces
|
|
|
@@ -26,7 +29,6 @@ import static org.hamcrest.Matchers.startsWith;
|
|
|
public class DetailedErrorsEnabledIT extends HttpSmokeTestCase {
|
|
|
|
|
|
public void testThatErrorTraceCanBeEnabled() throws IOException {
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
try {
|
|
|
Request request = new Request("DELETE", "/");
|
|
|
@@ -37,18 +39,20 @@ public class DetailedErrorsEnabledIT extends HttpSmokeTestCase {
|
|
|
Response response = e.getResponse();
|
|
|
assertThat(response.getHeader("Content-Type"), containsString("application/json"));
|
|
|
|
|
|
- JsonNode jsonNode = mapper.readTree(response.getEntity().getContent());
|
|
|
+ var jsonNode = XContentTestUtils.createJsonMapView(response.getEntity().getContent());
|
|
|
|
|
|
assertThat(
|
|
|
- jsonNode.get("error").get("stack_trace").asText(),
|
|
|
+ jsonNode.get("error.stack_trace"),
|
|
|
startsWith("org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: index / indices is missing")
|
|
|
);
|
|
|
|
|
|
// An ActionRequestValidationException isn't an ElasticsearchException, so when the code tries
|
|
|
// to work out the root cause, all it actually achieves is wrapping the actual exception in
|
|
|
// an ElasticsearchException. At least this proves that the root cause logic is executing.
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ Map<String, Object> cause = (Map<String, Object>) jsonNode.<List<Object>>get("error.root_cause").get(0);
|
|
|
assertThat(
|
|
|
- jsonNode.get("error").get("root_cause").get(0).get("stack_trace").asText(),
|
|
|
+ cause.get("stack_trace").toString(),
|
|
|
startsWith("org.elasticsearch.ElasticsearchException$1: Validation Failed: 1: index / indices is missing")
|
|
|
);
|
|
|
}
|
|
|
@@ -63,14 +67,12 @@ public class DetailedErrorsEnabledIT extends HttpSmokeTestCase {
|
|
|
Response response = e.getResponse();
|
|
|
assertThat(response.getHeader("Content-Type"), containsString("application/json"));
|
|
|
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- JsonNode jsonNode = mapper.readTree(response.getEntity().getContent());
|
|
|
+ var jsonNode = XContentTestUtils.createJsonMapView(response.getEntity().getContent());
|
|
|
|
|
|
- assertFalse("Unexpected .stack_trace in JSON response", jsonNode.get("error").has("stack_trace"));
|
|
|
- assertFalse(
|
|
|
- "Unexpected .error.root_cause[0].stack_trace in JSON response",
|
|
|
- jsonNode.get("error").get("root_cause").get(0).has("stack_trace")
|
|
|
- );
|
|
|
+ assertThat("Unexpected .stack_trace in JSON response", jsonNode.get("error.stack_track"), nullValue());
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ Map<String, Object> cause = (Map<String, Object>) jsonNode.<List<Object>>get("error.root_cause").get(0);
|
|
|
+ assertThat("Unexpected .error.root_cause[0].stack_trace in JSON response", cause, not(hasKey("stack_trace")));
|
|
|
}
|
|
|
}
|
|
|
}
|