Skip to content

Commit 98e6a63

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

8 files changed

Lines changed: 29 additions & 67 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-
private static final Logger LOG = Logger.getLogger(ECBAbstractRateProvider.class.getName());
60+
protected 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/ECBHistoric90RateProvider.java

Lines changed: 12 additions & 3 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
@@ -23,6 +23,8 @@
2323
import javax.money.convert.ProviderContextBuilder;
2424
import javax.money.convert.RateType;
2525
import java.net.URI;
26+
import java.net.URISyntaxException;
27+
import java.net.URL;
2628
import java.util.HashMap;
2729
import java.util.Map;
2830

@@ -70,12 +72,19 @@ public String getDataId() {
7072
protected LoadDataInformation getDefaultLoadData() {
7173
final Map<String, String> props = new HashMap<>();
7274
props.put("period", "03:00");
73-
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+
}
7483
return new LoadDataInformationBuilder()
7584
.withResourceId(getDataId())
7685
.withUpdatePolicy(LoaderService.UpdatePolicy.SCHEDULED)
7786
.withProperties(props)
78-
.withBackupResource(URI.create(ECB_HIST90_FALLBACK_PATH))
87+
.withBackupResource(backupResource)
7988
.withResourceLocations(URI.create(ECB_HIST90_URL))
8089
.withStartRemote(true)
8190
.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
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Werner Keil and others by the @author tag.
2+
* Copyright (c) 2023-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

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
public final class Defaults {
44
private Defaults() {}
55

6-
//public static final String DIGIT_FRACTION = "ecb.digit.fraction"
7-
86
public static final String HOST = "https://www.imf.org/external/np/fin/data/rms_mth.aspx?SelectDate=%s&reportType=%s&tsvflag=Y";
97

108
public static final String CVSDR = "CVSDR";

moneta-core/src/main/java/org/javamoney/moneta/spi/loader/LoadDataInformation.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.javamoney.moneta.spi.loader;
1717

18-
import java.io.InputStream;
1918
import java.net.URI;
2019
import java.util.Arrays;
2120
import java.util.Map;
@@ -41,24 +40,17 @@ public class LoadDataInformation {
4140

4241
private final URI backupResource;
4342

44-
public InputStream getFallbackStream() {
45-
return fallbackStream;
46-
}
47-
48-
private final InputStream fallbackStream;
49-
5043
private final URI[] resourceLocations;
5144

5245
private final boolean startRemote;
5346

5447
LoadDataInformation(String resourceId, UpdatePolicy updatePolicy,
5548
Map<String, String> properties, LoaderService.Listener listener,
56-
InputStream fallbackStream, URI backupResource, URI[] resourceLocations, boolean startRemote) {
49+
URI backupResource, URI[] resourceLocations, boolean startRemote) {
5750
this.resourceId = resourceId;
5851
this.updatePolicy = updatePolicy;
5952
this.properties = properties;
6053
this.listener = listener;
61-
this.fallbackStream = fallbackStream;
6254
this.backupResource = backupResource;
6355
this.resourceLocations = resourceLocations;
6456
this.startRemote = startRemote;

moneta-core/src/main/java/org/javamoney/moneta/spi/loader/LoadDataInformationBuilder.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.javamoney.moneta.spi.loader;
1717

18-
import java.io.InputStream;
1918
import java.net.URI;
2019
import java.util.Map;
2120
import java.util.Objects;
@@ -37,17 +36,11 @@ public class LoadDataInformationBuilder {
3736
private UpdatePolicy updatePolicy;
3837

3938
private Map<String, String> properties;
40-
4139
/** An (optional) Listener to be registered. */
4240
private Listener listener;
43-
44-
/**
45-
* The fallback input stream in the classpath.
46-
*/
47-
private InputStream fallbackStream;
48-
4941
/**
50-
* The backup resource location in the local filesystem.
42+
* The backup resource location in the classpath, not
43+
* {@code null}.
5144
*/
5245
private URI backupResource;
5346

@@ -76,11 +69,6 @@ public LoadDataInformationBuilder withLoaderListener(Listener listener) {
7669
return this;
7770
}
7871

79-
public LoadDataInformationBuilder withFallbackStream(InputStream stream) {
80-
this.fallbackStream = stream;
81-
return this;
82-
}
83-
8472
public LoadDataInformationBuilder withBackupResource(URI backupResource) {
8573
this.backupResource = backupResource;
8674
return this;
@@ -110,7 +98,8 @@ else if (Objects.isNull(resourceLocations)) {
11098
throw new IllegalStateException("The properties should be informed");
11199
}
112100
return new LoadDataInformation(resourceId, updatePolicy, properties,
113-
listener, fallbackStream, backupResource, resourceLocations, startRemote);
101+
listener, backupResource, resourceLocations, startRemote);
114102
}
115103

104+
116105
}

moneta-core/src/main/java/org/javamoney/moneta/spi/loader/okhttp/HttpLoadDataService.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,10 @@ public boolean execute(String resourceId,
5050
}
5151
try {
5252
if (load.loadFallback()) {
53-
if (load.getFallbackStream() != null) {
54-
LOG.log(Level.FINE, "Read fallback data from stream");
55-
listener.trigger(resourceId, load);
56-
LOG.log(Level.FINE, "Loaded fallback data from input stream");
57-
return true;
58-
} else if (load.getFallbackResource() != null) {
59-
LOG.log(Level.FINE, "Read fallback data from: " + load.getFallbackResource());
60-
listener.trigger(resourceId, load);
61-
LOG.log(Level.FINE, "Loaded fallback data from: " + load.getFallbackResource());
62-
return true;
63-
}
53+
LOG.log(Level.WARNING, "Read fallback data from: " + load.getFallbackResource());
54+
listener.trigger(resourceId, load);
55+
LOG.log(Level.WARNING, "Loaded fallback data from: " + load.getFallbackResource());
56+
return true;
6457
}
6558
} catch (Exception e) {
6659
LOG.log(Level.SEVERE, "Failed to read/load fallback resource: " + resourceId,

moneta-core/src/main/java/org/javamoney/moneta/spi/loader/okhttp/LoadableHttpResource.java

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,9 @@ class LoadableHttpResource implements DataStreamFactory {
5959
*/
6060
private final List<URI> remoteResources = new ArrayList<>();
6161
/**
62-
* The fallback location (local).
62+
* The fallback location (classpath).
6363
*/
6464
private final URI fallbackLocation;
65-
66-
/**
67-
* The fallback stream (classpath).
68-
*/
69-
private final InputStream fallbackStream;
7065
/**
7166
* The cache used.
7267
*/
@@ -115,7 +110,6 @@ class LoadableHttpResource implements DataStreamFactory {
115110
this.updatePolicy = loadDataInformation.getUpdatePolicy();
116111
this.properties = loadDataInformation.getProperties();
117112
this.fallbackLocation = loadDataInformation.getBackupResource();
118-
this.fallbackStream = loadDataInformation.getFallbackStream();
119113
this.remoteResources.addAll(Arrays.asList(loadDataInformation.getResourceLocations()));
120114
}
121115

@@ -177,15 +171,6 @@ public final List<URI> getRemoteResources() {
177171
return Collections.unmodifiableList(remoteResources);
178172
}
179173

180-
/**
181-
* Return the fallback input stream.
182-
*
183-
* @return the fallback stream, or null.
184-
*/
185-
public InputStream getFallbackStream() {
186-
return fallbackStream;
187-
}
188-
189174
/**
190175
* Return the fallback location.
191176
*
@@ -239,7 +224,7 @@ public final long getLastLoaded() {
239224
public boolean loadRemote() {
240225
for (URI itemToLoad : remoteResources) {
241226
try {
242-
return load(itemToLoad, false, null);
227+
return load(itemToLoad, false);
243228
} catch (Exception e) {
244229
LOG.log(Level.WARNING, "Failed to load resource: " + itemToLoad, e);
245230
}
@@ -260,7 +245,7 @@ public boolean loadFallback() {
260245
", loadFallback not supported.");
261246
return false;
262247
}
263-
load(fallbackLocation, true, fallbackStream);
248+
load(fallbackLocation, true);
264249
clearCache();
265250
return true;
266251
} catch (Exception e) {
@@ -317,22 +302,18 @@ protected void writeCache() throws IOException {
317302
/**
318303
* Tries to load the data from the given location. The location hereby can be a remote location or a local
319304
* location. Also it can be an URL pointing to a current dataset, or an url directing to fallback resources,
320-
* e.g. within the current file system.
305+
* e.g. within the current classpath.
321306
*
322307
* @param itemToLoad the target {@link URI}
323308
* @param fallbackLoad true, for a fallback URL.
324309
*/
325-
private boolean load(URI itemToLoad, boolean fallbackLoad, InputStream fallbackStream) {
310+
protected boolean load(URI itemToLoad, boolean fallbackLoad) {
326311
InputStream is = null;
327312
ByteArrayOutputStream stream = new ByteArrayOutputStream();
328313

329314
try {
330315
if (fallbackLoad) {
331-
if (fallbackStream != null) {
332-
is = new BufferedInputStream(fallbackStream);
333-
} else {
334-
is = new BufferedInputStream(itemToLoad.toURL().openStream());
335-
}
316+
is = new BufferedInputStream(itemToLoad.toURL().openStream());
336317
} else {
337318
OkHttpClient.Builder builder = new OkHttpClient.Builder();
338319

0 commit comments

Comments
 (0)