Clean up http request code in MandrillUtils and MaxMindUtils
This commit is contained in:
parent
0a036f5ec5
commit
2ca872706c
@ -27,7 +27,9 @@ public class MandrillUtils {
|
|||||||
response.exceptionHandler((error) -> {
|
response.exceptionHandler((error) -> {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
});
|
});
|
||||||
}).putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()).end(body.encode());
|
})
|
||||||
|
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString())
|
||||||
|
.end(body.encode());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -19,6 +19,8 @@ public class MaxMindUtils {
|
|||||||
private static final HttpClient httpsClient = APIv3.getVertxInstance().createHttpClient(new HttpClientOptions().setSsl(true).setTrustAll(true));
|
private static final HttpClient httpsClient = APIv3.getVertxInstance().createHttpClient(new HttpClientOptions().setSsl(true).setTrustAll(true));
|
||||||
|
|
||||||
public static void getInsights(String ip, SingleResultCallback<MaxMindResult> callback) {
|
public static void getInsights(String ip, SingleResultCallback<MaxMindResult> callback) {
|
||||||
|
String authHeader = "Basic " + Base64.getEncoder().encodeToString((maxMindUserId + ":" + maxMindLicenseKey).getBytes(Charsets.UTF_8));
|
||||||
|
|
||||||
httpsClient.get(443, "geoip.maxmind.com", "/geoip/v2.1/insights/" + ip, (response) -> {
|
httpsClient.get(443, "geoip.maxmind.com", "/geoip/v2.1/insights/" + ip, (response) -> {
|
||||||
response.bodyHandler((body) -> {
|
response.bodyHandler((body) -> {
|
||||||
JsonObject bodyJson = new JsonObject(body.toString());
|
JsonObject bodyJson = new JsonObject(body.toString());
|
||||||
@ -28,7 +30,9 @@ public class MaxMindUtils {
|
|||||||
response.exceptionHandler((error) -> {
|
response.exceptionHandler((error) -> {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
});
|
});
|
||||||
}).putHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString((maxMindUserId + ":" + maxMindLicenseKey).getBytes(Charsets.UTF_8))).end();
|
})
|
||||||
|
.putHeader("Authorization", authHeader)
|
||||||
|
.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getEnglishName(JsonObject source) {
|
public static String getEnglishName(JsonObject source) {
|
||||||
|
Loading…
Reference in New Issue
Block a user