Skip to content

Commit 5ba1c4e

Browse files
committed
Failed to load resource input for ECBCurrentRateProvider from org/javamoney/moneta/convert/ecb/defaults/eurofxref-daily.xml #431
1 parent 98e6a63 commit 5ba1c4e

6 files changed

Lines changed: 30 additions & 17 deletions

File tree

moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/ECBAbstractRateProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
abstract class ECBAbstractRateProvider extends AbstractRateProvider implements
5858
LoaderService.Listener {
5959

60-
protected static final Logger LOG = Logger.getLogger(ECBAbstractRateProvider.class.getName());
60+
private static final Logger LOG = Logger.getLogger(ECBAbstractRateProvider.class.getName());
6161

6262
private static final String BASE_CURRENCY_CODE = "EUR";
6363

moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/ECBCurrentRateProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected LoadDataInformation getDefaultLoadData() {
7171
.withResourceId(getDataId())
7272
.withUpdatePolicy(LoaderService.UpdatePolicy.SCHEDULED)
7373
.withProperties(props)
74-
.withBackupResource(URI.create(ECB_CURRENT_FALLBACK_PATH))
74+
.withBackupResource(getResourceFromPath(ECB_CURRENT_FALLBACK_PATH))
7575
.withResourceLocations(URI.create(ECB_CURRENT_URL))
7676
.withStartRemote(true)
7777
.build();

moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/ECBHistoric90RateProvider.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,12 @@ public String getDataId() {
7272
protected LoadDataInformation getDefaultLoadData() {
7373
final Map<String, String> props = new HashMap<>();
7474
props.put("period", "03:00");
75-
final URL backupUrl = getClass().getResource(ECB_HIST90_FALLBACK_PATH);
76-
// TODO factor fallBackResource into ECBAbstractRateProvider
77-
URI backupResource = null;
78-
try {
79-
backupResource = backupUrl.toURI();
80-
} catch (URISyntaxException e) {
81-
LOG.warning(e.getMessage());
82-
}
75+
8376
return new LoadDataInformationBuilder()
8477
.withResourceId(getDataId())
8578
.withUpdatePolicy(LoaderService.UpdatePolicy.SCHEDULED)
8679
.withProperties(props)
87-
.withBackupResource(backupResource)
80+
.withBackupResource(getResourceFromPath(ECB_HIST90_FALLBACK_PATH))
8881
.withResourceLocations(URI.create(ECB_HIST90_URL))
8982
.withStartRemote(true)
9083
.build();

moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/ECBHistoricRateProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Werner Keil and others by the @author tag.
2+
* Copyright (c) 2012, 2025, Werner Keil and others by the @author tag.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
@@ -27,6 +27,7 @@
2727
import java.util.HashMap;
2828
import java.util.Map;
2929

30+
import static org.javamoney.moneta.convert.ecb.defaults.Defaults.ECB_HIST_FALLBACK_PATH;
3031
import static org.javamoney.moneta.convert.ecb.defaults.Defaults.ECB_HIST_URL;
3132

3233
/**
@@ -81,7 +82,7 @@ protected LoadDataInformation getDefaultLoadData() {
8182
.withResourceId(getDataId())
8283
.withUpdatePolicy(LoaderService.UpdatePolicy.SCHEDULED)
8384
.withProperties(props)
84-
.withBackupResource(URI.create("org/javamoney/moneta/convert/ecb/defaults/eurofxref-hist.xml"))
85+
.withBackupResource(getResourceFromPath(ECB_HIST_FALLBACK_PATH))
8586
.withResourceLocations(URI.create(ECB_HIST_URL))
8687
.withStartRemote(false)
8788
.build();

moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/defaults/Defaults.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ private Defaults() {}
2323
public static final String ECB_CURRENT_FALLBACK_PATH = "org/javamoney/moneta/convert/ecb/defaults/eurofxref-daily.xml";
2424

2525
public static final String ECB_HIST90_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml";
26-
2726
public static final String ECB_HIST90_FALLBACK_PATH = "org/javamoney/moneta/convert/ecb/defaults/eurofxref-hist-90d.xml";
2827

2928
public static final String ECB_HIST_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml";
29+
public static final String ECB_HIST_FALLBACK_PATH = "org/javamoney/moneta/convert/ecb/defaults/eurofxref-hist.xml";
3030
}

moneta-core/src/main/java/org/javamoney/moneta/spi/AbstractRateProvider.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
2+
* Copyright (c) 2012, 2025, Werner Keil and others by the @author tag.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
@@ -19,6 +19,9 @@
1919

2020
import java.math.BigDecimal;
2121
import java.math.MathContext;
22+
import java.net.URI;
23+
import java.net.URISyntaxException;
24+
import java.net.URL;
2225
import java.time.LocalDate;
2326
import java.time.LocalDateTime;
2427
import java.util.Objects;
@@ -47,8 +50,7 @@ public abstract class AbstractRateProvider implements ExchangeRateProvider {
4750
*/
4851
private final ProviderContext context;
4952

50-
@Deprecated
51-
protected final Logger log = Logger.getLogger(getClass().getName());
53+
protected static final Logger LOG = Logger.getLogger(AbstractRateProvider.class.getName());
5254

5355
/**
5456
* Constructor.
@@ -175,4 +177,21 @@ protected LocalDate[] getQueryDates(ConversionQuery query) {
175177
}
176178
return null;
177179
}
180+
181+
/**
182+
* Return a URI from the given location.
183+
*
184+
* @param path the given location.
185+
* @return the URL resource, or null.
186+
*/
187+
protected URI getResourceFromPath(String path) {
188+
final URL url = getClass().getResource(path);
189+
URI resource = null;
190+
try {
191+
resource = url.toURI();
192+
} catch (URISyntaxException e) {
193+
LOG.warning(e.getMessage());
194+
}
195+
return resource;
196+
}
178197
}

0 commit comments

Comments
 (0)