Commit 619e4fd3 by 袁津

[chg]优化日志打印:只有天气、aqi接口调用异常时,才打印日志

1 parent ad71b23a
...@@ -38,6 +38,8 @@ public class JsonService { ...@@ -38,6 +38,8 @@ public class JsonService {
// 调用weather接口 // 调用weather接口
Callable<Boolean> weatherCallable = () -> { Callable<Boolean> weatherCallable = () -> {
String json = "";
try {
String host = jsonclass.getHost1(); String host = jsonclass.getHost1();
String path = jsonclass.getPath1(); String path = jsonclass.getPath1();
String method = "POST"; String method = "POST";
...@@ -49,9 +51,8 @@ public class JsonService { ...@@ -49,9 +51,8 @@ public class JsonService {
Map<String, String> bodys = new HashMap<>(); Map<String, String> bodys = new HashMap<>();
bodys.put("cityId", String.valueOf(cityId)); bodys.put("cityId", String.valueOf(cityId));
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys); HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
String json = EntityUtils.toString(response.getEntity()); json = EntityUtils.toString(response.getEntity());
System.out.println(sdf.format(new Date()) + "调用weather接口返回json:" + json);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd")); mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
...@@ -60,6 +61,11 @@ public class JsonService { ...@@ -60,6 +61,11 @@ public class JsonService {
dataMap.put("WEATHER", weatherMessage); dataMap.put("WEATHER", weatherMessage);
return true; return true;
} }
} catch (Exception e) {
// 接口调用发生异常时,打印接口返回信息
System.out.println("调用weather接口发生异常,接口返回数据:" + json);
throw e;
}
return false; return false;
}; };
Retryer<Boolean> weatherRetryer = RetryerBuilder.<Boolean>newBuilder() Retryer<Boolean> weatherRetryer = RetryerBuilder.<Boolean>newBuilder()
...@@ -89,6 +95,8 @@ public class JsonService { ...@@ -89,6 +95,8 @@ public class JsonService {
// 调用aqi接口 // 调用aqi接口
Callable<Boolean> aqiCallable = () -> { Callable<Boolean> aqiCallable = () -> {
String json = "";
try {
String host = jsonclass.getHost2(); String host = jsonclass.getHost2();
String path = jsonclass.getPath2(); String path = jsonclass.getPath2();
String method = "POST"; String method = "POST";
...@@ -100,7 +108,7 @@ public class JsonService { ...@@ -100,7 +108,7 @@ public class JsonService {
Map<String, String> bodys = new HashMap<>(); Map<String, String> bodys = new HashMap<>();
bodys.put("cityId", String.valueOf(cityId)); bodys.put("cityId", String.valueOf(cityId));
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys); HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
String json = EntityUtils.toString(response.getEntity()); json = EntityUtils.toString(response.getEntity());
System.out.println(sdf.format(new Date()) + "调用AQI接口返回json:" + json); System.out.println(sdf.format(new Date()) + "调用AQI接口返回json:" + json);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
...@@ -111,6 +119,11 @@ public class JsonService { ...@@ -111,6 +119,11 @@ public class JsonService {
dataMap.put("AQI", aqiMessage); dataMap.put("AQI", aqiMessage);
return true; return true;
} }
} catch (Exception e) {
// 接口调用发生异常时,打印接口返回信息
System.out.println("调用AQI接口发生异常,接口返回数据:" + json);
throw e;
}
return false; return false;
}; };
Retryer<Boolean> aqiRetryer = RetryerBuilder.<Boolean>newBuilder() Retryer<Boolean> aqiRetryer = RetryerBuilder.<Boolean>newBuilder()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!