Skip to content

Commit

Permalink
Improve Eurostat driver
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Feb 22, 2023
1 parent d807212 commit 9baeeb9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 37 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- ![PROVIDER] Improve Eurostat driver [#416](https://github.com/nbbrd/sdmx-dl/issues/416)

## [3.0.0-beta.10] - 2023-02-13

This is a bugfix release for the deployment of v3.0.0-beta.9.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import internal.sdmxdl.provider.ri.web.RiRestClient;
import internal.sdmxdl.provider.ri.web.Sdmx21RestParsers;
import internal.sdmxdl.provider.ri.web.Sdmx21RestQueries;
import internal.util.http.*;
import internal.util.http.HttpClient;
import internal.util.http.HttpRequest;
import internal.util.http.HttpResponse;
import internal.util.http.HttpResponseException;
import internal.util.http.ext.InterceptingClient;
import lombok.NonNull;
import nbbrd.io.Resource;
Expand All @@ -29,7 +32,6 @@
import nbbrd.io.text.LongProperty;
import nbbrd.io.text.Parser;
import nbbrd.service.ServiceProvider;
import sdmxdl.DataflowRef;
import sdmxdl.format.MessageFooter;
import sdmxdl.format.ObsParser;
import sdmxdl.format.xml.SdmxXmlStreams;
Expand Down Expand Up @@ -57,7 +59,6 @@
import static sdmxdl.LanguagePriorityList.ANY;
import static sdmxdl.ext.spi.Dialect.SDMX21_DIALECT;
import static sdmxdl.provider.SdmxFix.Category.PROTOCOL;
import static sdmxdl.provider.SdmxFix.Category.QUERY;

/**
* @author Philippe Charles
Expand Down Expand Up @@ -105,30 +106,19 @@ private static RestClient newClient(SdmxWebSource s, WebContext c) throws IOExce
c.getLanguages(),
ObsParser::newDefault,
getHttpClient(s, c),
new EurostatRestQueries(),
new Sdmx21RestQueries(false),
new Sdmx21RestParsers(),
false
);
}

private static InterceptingClient getHttpClient(SdmxWebSource s, WebContext c) {
private static HttpClient getHttpClient(SdmxWebSource s, WebContext c) {
int asyncMaxRetries = ASYNC_MAX_RETRIES_PROPERTY.get(s.getProperties());
long asyncSleepTime = ASYNC_SLEEP_TIME_PROPERTY.get(s.getProperties());
return new InterceptingClient(RiHttpUtils.newClient(getContext(s, c)), (client, request, response) -> checkCodesInMessageFooter(client, response, asyncSleepTime, asyncMaxRetries));
}

private static HttpContext getContext(SdmxWebSource s, WebContext c) {
return fixCompression(RiHttpUtils.newContext(s, c));
}

@SdmxFix(id = 1, category = QUERY, cause = "Agency id must be ESTAT instead of 'all'")
private static DataflowRef fixAgencyId(DataflowRef ref) {
return DataflowRef.of("ESTAT", ref.getId(), ref.getVersion());
}

@SdmxFix(id = 2, category = PROTOCOL, cause = "SSL exception if backend is schannel and compression requested")
private static HttpContext fixCompression(HttpContext context) {
return context.toBuilder().clearDecoders().build();
return new InterceptingClient(
RiHttpUtils.newClient(RiHttpUtils.newContext(s, c)),
(client, request, response) -> checkCodesInMessageFooter(client, response, asyncSleepTime, asyncMaxRetries)
);
}

@SdmxFix(id = 3, category = PROTOCOL, cause = "Some response codes are located in the message footer")
Expand Down Expand Up @@ -184,23 +174,6 @@ private static void sleep(long timeInMillis) throws IOException {
}
}

private static final class EurostatRestQueries extends Sdmx21RestQueries {

public EurostatRestQueries() {
super(false);
}

@Override
public URLQueryBuilder getFlowsQuery(URL endpoint) {
return onMeta(endpoint, DEFAULT_DATAFLOW_PATH, fixAgencyId(FLOWS));
}

@Override
public URLQueryBuilder getFlowQuery(URL endpoint, DataflowRef ref) {
return super.getFlowQuery(endpoint, fixAgencyId(ref));
}
}

@lombok.AllArgsConstructor
private static final class AsyncResponse implements HttpResponse {

Expand Down

0 comments on commit 9baeeb9

Please sign in to comment.