diff --git a/src/main/java/cl/transbank/util/HttpUtilImpl.java b/src/main/java/cl/transbank/util/HttpUtilImpl.java index 53d64c1..3f0b1aa 100644 --- a/src/main/java/cl/transbank/util/HttpUtilImpl.java +++ b/src/main/java/cl/transbank/util/HttpUtilImpl.java @@ -28,6 +28,7 @@ public class HttpUtilImpl implements HttpUtil { private static Logger logger = Logger.getLogger(HttpUtilImpl.class.getName()); private static volatile HttpUtilImpl instance; + private static final String ERROR_MESSAGE = "error_message"; @Setter @Getter(AccessLevel.PRIVATE) @@ -45,7 +46,7 @@ public T request( Class clazz ) throws IOException, WebpayException { final String jsonIn = getJsonUtil().jsonEncode(request); - final String jsonOut = request(url, method, jsonIn, headers, true); + final String jsonOut = request(url, method, jsonIn, headers); return getJsonUtil().jsonDecode(jsonOut, clazz); } @@ -57,7 +58,7 @@ public List requestList( Class clazz ) throws IOException, WebpayException { final String jsonIn = getJsonUtil().jsonEncode(request); - final String jsonOut = request(url, method, jsonIn, headers, true); + final String jsonOut = request(url, method, jsonIn, headers); return getJsonUtil().jsonDecodeToList(jsonOut, clazz); } @@ -105,21 +106,6 @@ public String request( return request(url, method, query, null, headers); } - /** - * Sends a HTTP request and returns the response. - * This method uses the provided URL and request method to send the request. - * It uses default headers, a default response type, and does not send a request body. - */ - public String request( - @NonNull URL url, - RequestMethod method, - String query, - Map headers, - boolean useException - ) throws IOException, WebpayException { - return request(url, method, query, null, headers); - } - /** * Sends a HTTP request and returns the response. * This method uses the provided URL to send the request. @@ -232,7 +218,7 @@ private void handleResponse( final Map errorMap = (Map) getJsonUtil() .jsonDecode(responseBody, HashMap.class); - errorMessage = errorMap.get("error_message"); + errorMessage = errorMap.get(ERROR_MESSAGE); } if (null == errorMessage) errorMessage = @@ -246,10 +232,9 @@ private void handleResponse( if (responseBody != null && !responseBody.trim().startsWith("[")) { final Map tempMap = getJsonUtil().jsonDecode(responseBody, HashMap.class); if ( - tempMap.containsKey("error_message") && - tempMap.get("error_message") != null + tempMap.containsKey(ERROR_MESSAGE) && tempMap.get(ERROR_MESSAGE) != null ) { - throw new WebpayException(tempMap.get("error_message").toString()); + throw new WebpayException(tempMap.get(ERROR_MESSAGE).toString()); } } }