diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/download/SEBClientLogExport.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/download/SEBClientLogExport.java index df46d6d4..ee36957c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/download/SEBClientLogExport.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/download/SEBClientLogExport.java @@ -55,26 +55,32 @@ public class SEBClientLogExport extends AbstractDownloadServiceHandler { queryParams.add(param, String.valueOf(request.getParameter(param))); } - final InputStream input = this.restService + this.restService .getBuilder(ExportSEBClientLogs.class) + .withResponseExtractor(response -> { + + try { + final InputStream input = response.getBody(); + IOUtils.copyLarge(input, downloadOut); + } catch (final IOException e) { + log.error( + "Unexpected error while streaming incoming config data from web-service to output-stream of download response: ", + e); + } finally { + try { + downloadOut.flush(); + downloadOut.close(); + } catch (final IOException e) { + log.error("Unexpected error while trying to close download output-stream"); + } + } + + return true; + }) .withQueryParams(queryParams) .call() - .getOrThrow(); + .onError(error -> log.error("Download failed: ", error)); - try { - IOUtils.copyLarge(input, downloadOut); - } catch (final IOException e) { - log.error( - "Unexpected error while streaming incoming config data from web-service to output-stream of download response: ", - e); - } finally { - try { - downloadOut.flush(); - downloadOut.close(); - } catch (final IOException e) { - log.error("Unexpected error while trying to close download output-stream"); - } - } } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/AbstractDownloadCall.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/AbstractDownloadCall.java new file mode 100644 index 00000000..3e2afb06 --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/AbstractDownloadCall.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.gui.service.remote.webservice.api; + +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.client.ClientHttpRequest; + +import com.fasterxml.jackson.core.type.TypeReference; + +import ch.ethz.seb.sebserver.gbl.util.Result; + +public class AbstractDownloadCall extends RestCall { + + protected AbstractDownloadCall( + final MediaType contentType, + final String path) { + + super(new RestCall.TypeKey<>(CallType.UNDEFINED, null, new TypeReference() { + }), HttpMethod.GET, contentType, path); + } + + @Override + protected Result exchange(final RestCallBuilder builder) { + + return Result.tryCatch(() -> builder + .getRestTemplate() + .execute( + builder.buildURI(), + this.httpMethod, + (final ClientHttpRequest requestCallback) -> { + }, + builder.getResponseExtractor(), + builder.getURIVariables())); + } + +} diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/AbstractExportCall.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/AbstractExportCall.java index 632529ac..7f20b564 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/AbstractExportCall.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/AbstractExportCall.java @@ -17,6 +17,7 @@ import org.springframework.http.client.ClientHttpRequest; import ch.ethz.seb.sebserver.gbl.util.Result; +@Deprecated(since = "1.2. : This is not streaming correctly. Use AbstractDownloadCall instead") public abstract class AbstractExportCall extends RestCall { protected AbstractExportCall( diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java index 790963fa..89e7ef7f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java @@ -29,6 +29,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.ResourceAccessException; +import org.springframework.web.client.ResponseExtractor; import org.springframework.web.client.RestClientResponseException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -224,6 +225,7 @@ public abstract class RestCall { private final HttpHeaders httpHeaders; private String body = null; private InputStream streamingBody = null; + private ResponseExtractor responseExtractor = null; private final MultiValueMap queryParams; private final Map uriVariables; @@ -253,6 +255,15 @@ public abstract class RestCall { return this.restTemplate; } + public RestCallBuilder withResponseExtractor(final ResponseExtractor responseExtractor) { + this.responseExtractor = responseExtractor; + return this; + } + + public ResponseExtractor getResponseExtractor() { + return this.responseExtractor; + } + public RestCallBuilder withRestTemplate(final RestTemplate restTemplate) { this.restTemplate = restTemplate; return this; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/exam/ExportSEBClientLogs.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/exam/ExportSEBClientLogs.java index 34aa0a68..8e76abba 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/exam/ExportSEBClientLogs.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/exam/ExportSEBClientLogs.java @@ -8,33 +8,21 @@ package ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam; -import java.io.InputStream; - import org.springframework.context.annotation.Lazy; -import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; -import com.fasterxml.jackson.core.type.TypeReference; - import ch.ethz.seb.sebserver.gbl.api.API; -import ch.ethz.seb.sebserver.gbl.api.EntityType; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.AbstractExportCall; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.AbstractDownloadCall; @Lazy @Component @GuiProfile -public class ExportSEBClientLogs extends AbstractExportCall { +public class ExportSEBClientLogs extends AbstractDownloadCall { public ExportSEBClientLogs() { - super(new TypeKey<>( - CallType.UNDEFINED, - EntityType.CLIENT_EVENT, - new TypeReference() { - }), - HttpMethod.GET, - MediaType.APPLICATION_FORM_URLENCODED, + super(MediaType.APPLICATION_FORM_URLENCODED, API.SEB_CLIENT_EVENT_ENDPOINT + API.SEB_CLIENT_EVENT_EXPORT_PATH_SEGMENT); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/SEBClientEventAdminServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/SEBClientEventAdminServiceImpl.java index be4219f0..25ed7f4f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/SEBClientEventAdminServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/SEBClientEventAdminServiceImpl.java @@ -225,7 +225,7 @@ public class SEBClientEventAdminServiceImpl implements SEBClientEventAdminServic private final String sort; private int pageNumber = 1; - private final int pageSize = 1000; + private final int pageSize = 10000; private Collection nextRecords;