不再需要 @Async
This commit is contained in:
@@ -18,7 +18,6 @@ import java.net.InetAddress;
|
|||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class GeoIPUtil {
|
public class GeoIPUtil {
|
||||||
@@ -34,8 +33,7 @@ public class GeoIPUtil {
|
|||||||
throw new RuntimeException("IP 地址库初始化失败", e);
|
throw new RuntimeException("IP 地址库初始化失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
|
||||||
public static IpInfo getIpInfoThroughProxy(ProxySetting proxySetting) {
|
public static IpInfo getIpInfoThroughProxy(ProxySetting proxySetting) {
|
||||||
if (proxySetting == null) {
|
if (proxySetting == null) {
|
||||||
throw new RuntimeException("代理为空");
|
throw new RuntimeException("代理为空");
|
||||||
@@ -66,7 +64,7 @@ public class GeoIPUtil {
|
|||||||
String responseBody = response.body().string();
|
String responseBody = response.body().string();
|
||||||
log.debug("Response ipv4 from proxy: {}", responseBody.trim());
|
log.debug("Response ipv4 from proxy: {}", responseBody.trim());
|
||||||
ipInfo.setIp(responseBody);
|
ipInfo.setIp(responseBody);
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
log.warn("Proxy ipv4 error: {}", e.getMessage());
|
log.warn("Proxy ipv4 error: {}", e.getMessage());
|
||||||
return IpInfo.EMPTY;
|
return IpInfo.EMPTY;
|
||||||
}
|
}
|
||||||
@@ -81,7 +79,7 @@ public class GeoIPUtil {
|
|||||||
String responseBody = response.body().string();
|
String responseBody = response.body().string();
|
||||||
log.debug("Response ipv6 from proxy: {}", responseBody.trim());
|
log.debug("Response ipv6 from proxy: {}", responseBody.trim());
|
||||||
ipInfo.setIpv6(responseBody);
|
ipInfo.setIpv6(responseBody);
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
log.warn("Proxy ipv6 error {}", e.getMessage());
|
log.warn("Proxy ipv6 error {}", e.getMessage());
|
||||||
}
|
}
|
||||||
return queryIpInfoGeoLite(ipInfo);
|
return queryIpInfoGeoLite(ipInfo);
|
||||||
@@ -104,7 +102,7 @@ public class GeoIPUtil {
|
|||||||
|
|
||||||
if (response.getSubdivisions() != null && !response.getSubdivisions().isEmpty()) {
|
if (response.getSubdivisions() != null && !response.getSubdivisions().isEmpty()) {
|
||||||
// 省
|
// 省
|
||||||
Subdivision subdivision = response.getSubdivisions().get(0);
|
Subdivision subdivision = response.getSubdivisions().getFirst();
|
||||||
if (subdivision != null) {
|
if (subdivision != null) {
|
||||||
String subdivisionStr = subdivision.getNames().get(LOCALE);
|
String subdivisionStr = subdivision.getNames().get(LOCALE);
|
||||||
ipInfo.setSubdivision(subdivisionStr);
|
ipInfo.setSubdivision(subdivisionStr);
|
||||||
@@ -125,4 +123,4 @@ public class GeoIPUtil {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.format("GeoLite2-City %s\r\n", queryIpInfoGeoLite(new IpInfo().setIp("46.3.98.216")));
|
System.out.format("GeoLite2-City %s\r\n", queryIpInfoGeoLite(new IpInfo().setIp("46.3.98.216")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user