diff --git a/src/main/java/quant/rich/emoney/util/GeoIPUtil.java b/src/main/java/quant/rich/emoney/util/GeoIPUtil.java index 76cf0a2..83349ff 100644 --- a/src/main/java/quant/rich/emoney/util/GeoIPUtil.java +++ b/src/main/java/quant/rich/emoney/util/GeoIPUtil.java @@ -18,7 +18,6 @@ import java.net.InetAddress; import java.net.Proxy; import java.util.concurrent.TimeUnit; import org.springframework.core.io.ClassPathResource; -import org.springframework.scheduling.annotation.Async; @Slf4j public class GeoIPUtil { @@ -34,8 +33,7 @@ public class GeoIPUtil { throw new RuntimeException("IP 地址库初始化失败", e); } } - - @Async + public static IpInfo getIpInfoThroughProxy(ProxySetting proxySetting) { if (proxySetting == null) { throw new RuntimeException("代理为空"); @@ -66,7 +64,7 @@ public class GeoIPUtil { String responseBody = response.body().string(); log.debug("Response ipv4 from proxy: {}", responseBody.trim()); ipInfo.setIp(responseBody); - } catch (IOException e) { + } catch (Exception e) { log.warn("Proxy ipv4 error: {}", e.getMessage()); return IpInfo.EMPTY; } @@ -81,7 +79,7 @@ public class GeoIPUtil { String responseBody = response.body().string(); log.debug("Response ipv6 from proxy: {}", responseBody.trim()); ipInfo.setIpv6(responseBody); - } catch (IOException e) { + } catch (Exception e) { log.warn("Proxy ipv6 error {}", e.getMessage()); } return queryIpInfoGeoLite(ipInfo); @@ -104,7 +102,7 @@ public class GeoIPUtil { if (response.getSubdivisions() != null && !response.getSubdivisions().isEmpty()) { // 省 - Subdivision subdivision = response.getSubdivisions().get(0); + Subdivision subdivision = response.getSubdivisions().getFirst(); if (subdivision != null) { String subdivisionStr = subdivision.getNames().get(LOCALE); ipInfo.setSubdivision(subdivisionStr); @@ -125,4 +123,4 @@ public class GeoIPUtil { public static void main(String[] args) { System.out.format("GeoLite2-City %s\r\n", queryIpInfoGeoLite(new IpInfo().setIp("46.3.98.216"))); } -} \ No newline at end of file +}