|
9 | 9 | import org.apache.http.NameValuePair; |
10 | 10 | import org.apache.http.client.fluent.Request; |
11 | 11 | import org.apache.http.message.BasicNameValuePair; |
| 12 | +import org.slf4j.Logger; |
| 13 | +import org.slf4j.LoggerFactory; |
12 | 14 |
|
13 | 15 | import java.io.IOException; |
14 | 16 | import java.io.InputStream; |
|
22 | 24 | import java.util.stream.Collectors; |
23 | 25 |
|
24 | 26 | public class DevRant { |
| 27 | + private static final Logger LOGGER = LoggerFactory.getLogger(DevRant.class); |
| 28 | + |
25 | 29 | static final String APP_ID = "3"; |
26 | 30 | static final String PLAT_ID = "3"; |
27 | 31 |
|
@@ -350,7 +354,7 @@ JsonObject get(String url, NameValuePair... params) { |
350 | 354 | finalUrl.append('&').append(param.getName()).append('=').append(URLEncoder.encode(param.getValue(), "UTF-8")); |
351 | 355 | } catch (UnsupportedEncodingException e) { |
352 | 356 | // This never happens. |
353 | | - e.printStackTrace(); |
| 357 | + LOGGER.error("Unsupported encoding while trying to encode parameter value.", e); |
354 | 358 | } |
355 | 359 |
|
356 | 360 | return executeRequest(Request.Get(BASE_URL + finalUrl.toString())); |
@@ -394,15 +398,15 @@ private JsonObject executeRequest(Request request) { |
394 | 398 | try { |
395 | 399 | stream = request.socketTimeout(timeout).connectTimeout(timeout).execute().returnContent().asStream(); |
396 | 400 | } catch (IOException e) { |
397 | | - e.printStackTrace(); |
| 401 | + LOGGER.warn("Exception while processing request:\n" + request.toString() + '\n' + e.getMessage()); |
398 | 402 | return null; |
399 | 403 | } |
400 | 404 |
|
401 | 405 | // Parse the response as json. |
402 | 406 | try (JsonReader reader = new JsonReader(new InputStreamReader(stream))) { |
403 | 407 | return new JsonParser().parse(reader).getAsJsonObject(); |
404 | 408 | } catch (IOException e) { |
405 | | - e.printStackTrace(); |
| 409 | + LOGGER.error("Exception while trying to create JsonReader.", e); |
406 | 410 | return null; |
407 | 411 | } |
408 | 412 | } |
|
0 commit comments