add logging to all external api calls

This commit is contained in:
Craig Raw 2022-08-17 10:59:33 +02:00
parent 5aea538f09
commit b3bd42b8f6
8 changed files with 67 additions and 8 deletions

View file

@ -121,6 +121,10 @@ public class PayNymAvatar extends StackPane {
Proxy proxy = AppServices.getProxy();
String url = PayNymService.getHostUrl(proxy != null) + "/" + paymentCodeStr + "/avatar";
if(log.isDebugEnabled()) {
log.debug("Requesting PayNym avatar from " + url);
}
try(InputStream is = (proxy == null ? new URL(url).openStream() : new URL(url).openConnection(proxy).getInputStream())) {
Image image = new Image(is, 150, 150, true, false);
paymentCodeCache.put(cacheId, image);

View file

@ -123,8 +123,8 @@ public class Auth47 {
}
private void send(String json) throws IOException, Auth47Exception {
if(log.isDebugEnabled()) {
log.debug("Sending " + json + " to " + callback);
if(log.isInfoEnabled()) {
log.info("Sending auth47 response " + json + " to " + callback);
}
Proxy proxy = AppServices.getProxy();

View file

@ -146,6 +146,10 @@ public enum BroadcastSource {
try {
URL url = getURL(proxy);
if(log.isInfoEnabled()) {
log.info("Broadcasting transaction to " + url);
}
HttpURLConnection connection = proxy == null ? (HttpURLConnection)url.openConnection() : (HttpURLConnection)url.openConnection(proxy);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "text/plain");

View file

@ -52,6 +52,10 @@ public enum ExchangeSource {
String url = "https://api.coinbase.com/v2/exchange-rates?currency=BTC";
Proxy proxy = AppServices.getProxy();
if(log.isInfoEnabled()) {
log.info("Requesting exchange rates from " + url);
}
try(InputStream is = (proxy == null ? new URL(url).openStream() : new URL(url).openConnection(proxy).getInputStream()); Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
Gson gson = new Gson();
return gson.fromJson(reader, CoinbaseRates.class);
@ -87,6 +91,10 @@ public enum ExchangeSource {
String url = "https://api.coingecko.com/api/v3/exchange_rates";
Proxy proxy = AppServices.getProxy();
if(log.isInfoEnabled()) {
log.info("Requesting exchange rates from " + url);
}
try(InputStream is = (proxy == null ? new URL(url).openStream() : new URL(url).openConnection(proxy).getInputStream()); Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
Gson gson = new Gson();
return gson.fromJson(reader, CoinGeckoRates.class);

View file

@ -68,6 +68,10 @@ public enum FeeRatesSource {
private static Map<Integer, Double> getThreeTierFeeRates(Map<Integer, Double> defaultblockTargetFeeRates, String url) {
Proxy proxy = AppServices.getProxy();
if(log.isInfoEnabled()) {
log.info("Requesting fee rates from " + url);
}
Map<Integer, Double> blockTargetFeeRates = new LinkedHashMap<>();
try(InputStream is = (proxy == null ? new URL(url).openStream() : new URL(url).openConnection(proxy).getInputStream()); Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
Gson gson = new Gson();

View file

@ -103,6 +103,10 @@ public class LnurlAuth {
public void sendResponse(Wallet wallet) throws LnurlAuthException, IOException {
URL callback = getReturnURL(wallet);
if(log.isInfoEnabled()) {
log.info("Sending LNURL-auth response to " + callback);
}
Proxy proxy = AppServices.getProxy();
if(proxy == null && callback.getHost().toLowerCase(Locale.ROOT).endsWith(TorService.TOR_ADDRESS_SUFFIX)) {
throw new LnurlAuthException("A Tor proxy must be configured to authenticate this resource.");

View file

@ -47,6 +47,11 @@ public class VersionCheckService extends ScheduledService<VersionUpdatedEvent> {
private VersionCheck getVersionCheck() throws IOException {
URL url = new URL(VERSION_CHECK_URL);
Proxy proxy = AppServices.getProxy();
if(log.isInfoEnabled()) {
log.info("Requesting application version check from " + url);
}
HttpsURLConnection conn = (HttpsURLConnection)(proxy == null ? url.openConnection() : url.openConnection(proxy));
try(InputStreamReader reader = new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)) {

View file

@ -51,8 +51,13 @@ public class PayNymService {
HashMap<String, Object> body = new HashMap<>();
body.put("code", paymentCode.toString());
String url = getHostUrl() + "/api/v1/create";
if(log.isInfoEnabled()) {
log.info("Creating PayNym using " + url);
}
IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST);
return httpClient.postJson(getHostUrl() + "/api/v1/create", Map.class, headers, body)
return httpClient.postJson(url, Map.class, headers, body)
.subscribeOn(Schedulers.io())
.observeOn(JavaFxScheduler.platform())
.map(Optional::get);
@ -69,8 +74,13 @@ public class PayNymService {
HashMap<String, Object> body = new HashMap<>();
body.put("code", paymentCode.toString());
String url = getHostUrl() + "/api/v1/token";
if(log.isInfoEnabled()) {
log.info("Updating PayNym token using " + url);
}
IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST);
return httpClient.postJson(getHostUrl() + "/api/v1/token", Map.class, headers, body)
return httpClient.postJson(url, Map.class, headers, body)
.subscribeOn(Schedulers.io())
.observeOn(JavaFxScheduler.platform())
.map(Optional::get);
@ -114,8 +124,13 @@ public class PayNymService {
HashMap<String, Object> body = new HashMap<>();
body.put("signature", signature);
String url = getHostUrl() + "/api/v1/claim";
if(log.isInfoEnabled()) {
log.info("Claiming PayNym using " + url);
}
IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST);
return httpClient.postJson(getHostUrl() + "/api/v1/claim", Map.class, headers, body)
return httpClient.postJson(url, Map.class, headers, body)
.subscribeOn(Schedulers.io())
.observeOn(JavaFxScheduler.platform())
.map(Optional::get);
@ -139,8 +154,13 @@ public class PayNymService {
body.put("code", strPaymentCode);
body.put("signature", signature);
String url = getHostUrl() + "/api/v1/nym/add";
if(log.isInfoEnabled()) {
log.info("Adding payment code to PayNym using " + url);
}
IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST);
return httpClient.postJson(getHostUrl() + "/api/v1/nym/add", Map.class, headers, body)
return httpClient.postJson(url, Map.class, headers, body)
.subscribeOn(Schedulers.io())
.observeOn(JavaFxScheduler.platform())
.map(Optional::get);
@ -159,8 +179,13 @@ public class PayNymService {
body.put("signature", signature);
body.put("target", paymentCode.toString());
String url = getHostUrl() + "/api/v1/follow";
if(log.isInfoEnabled()) {
log.info("Following payment code using " + url);
}
IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST);
return httpClient.postJson(getHostUrl() + "/api/v1/follow", Map.class, headers, body)
return httpClient.postJson(url, Map.class, headers, body)
.subscribeOn(Schedulers.io())
.observeOn(JavaFxScheduler.platform())
.map(Optional::get);
@ -173,8 +198,13 @@ public class PayNymService {
HashMap<String, Object> body = new HashMap<>();
body.put("nym", nymIdentifier);
String url = getHostUrl() + "/api/v1/nym";
if(log.isInfoEnabled()) {
log.info("Fetching PayNym using " + url);
}
IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST);
return httpClient.postJson(getHostUrl() + "/api/v1/nym", Map.class, headers, body)
return httpClient.postJson(url, Map.class, headers, body)
.subscribeOn(Schedulers.io())
.observeOn(JavaFxScheduler.platform())
.map(Optional::get);