|
@@ -18,6 +18,8 @@
|
|
|
package org.apache.hadoop.util;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.databind.ObjectReader;
|
|
|
+import com.fasterxml.jackson.databind.ObjectWriter;
|
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
|
|
|
@@ -54,6 +56,11 @@ public class HttpExceptionUtils {
|
|
|
|
|
|
private static final String ENTER = System.getProperty("line.separator");
|
|
|
|
|
|
+ private static final ObjectReader READER =
|
|
|
+ new ObjectMapper().readerFor(Map.class);
|
|
|
+ private static final ObjectWriter WRITER =
|
|
|
+ new ObjectMapper().writerWithDefaultPrettyPrinter();
|
|
|
+
|
|
|
/**
|
|
|
* Creates a HTTP servlet response serializing the exception in it as JSON.
|
|
|
*
|
|
@@ -74,9 +81,8 @@ public class HttpExceptionUtils {
|
|
|
json.put(ERROR_CLASSNAME_JSON, ex.getClass().getName());
|
|
|
Map<String, Object> jsonResponse = new LinkedHashMap<String, Object>();
|
|
|
jsonResponse.put(ERROR_JSON, json);
|
|
|
- ObjectMapper jsonMapper = new ObjectMapper();
|
|
|
Writer writer = response.getWriter();
|
|
|
- jsonMapper.writerWithDefaultPrettyPrinter().writeValue(writer, jsonResponse);
|
|
|
+ WRITER.writeValue(writer, jsonResponse);
|
|
|
writer.flush();
|
|
|
}
|
|
|
|
|
@@ -144,8 +150,7 @@ public class HttpExceptionUtils {
|
|
|
InputStream es = null;
|
|
|
try {
|
|
|
es = conn.getErrorStream();
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- Map json = mapper.readValue(es, Map.class);
|
|
|
+ Map json = READER.readValue(es);
|
|
|
json = (Map) json.get(ERROR_JSON);
|
|
|
String exClass = (String) json.get(ERROR_CLASSNAME_JSON);
|
|
|
String exMsg = (String) json.get(ERROR_MESSAGE_JSON);
|