From def31a46690e8555b396f27e458813b8d9057bc0 Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 15 Nov 2021 14:17:04 +0100 Subject: [PATCH] added better error notification for timeouts, and work with longer request timout limits --- .../seb/sebserver/ClientHttpRequestFactoryService.java | 2 +- .../seb/sebserver/gui/service/page/PageContext.java | 4 ++++ .../gui/service/remote/webservice/api/RestCall.java | 10 ++++++++++ src/main/resources/config/application-gui.properties | 5 +++++ src/main/resources/messages.properties | 1 + 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/ClientHttpRequestFactoryService.java b/src/main/java/ch/ethz/seb/sebserver/ClientHttpRequestFactoryService.java index 567b1152..06b16245 100644 --- a/src/main/java/ch/ethz/seb/sebserver/ClientHttpRequestFactoryService.java +++ b/src/main/java/ch/ethz/seb/sebserver/ClientHttpRequestFactoryService.java @@ -76,7 +76,7 @@ public class ClientHttpRequestFactoryService { final ClientCredentialService clientCredentialService, @Value("${sebserver.http.client.connect-timeout:15000}") final int connectTimeout, @Value("${sebserver.http.client.connection-request-timeout:20000}") final int connectionRequestTimeout, - @Value("${sebserver.http.client.read-timeout:10000}") final int readTimeout) { + @Value("${sebserver.http.client.read-timeout:60000}") final int readTimeout) { this.environment = environment; this.clientCredentialService = clientCredentialService; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageContext.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageContext.java index 406a61c6..1c9a24a2 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageContext.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageContext.java @@ -281,6 +281,10 @@ public interface PageContext { * * @param error the original error */ default void notifyUnexpectedError(final Exception error) { + if (error instanceof PageMessageException) { + publishInfo(((PageMessageException) error).getMessageKey()); + return; + } notifyError(UNEXPECTED_ERROR_KEY, error); } 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 3fc41d7e..790963fa 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 @@ -28,6 +28,7 @@ import org.springframework.http.MediaType; 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.RestClientResponseException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -46,11 +47,15 @@ import ch.ethz.seb.sebserver.gbl.model.Page; import ch.ethz.seb.sebserver.gbl.model.PageSortOrder; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.gbl.util.Utils; +import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; +import ch.ethz.seb.sebserver.gui.service.page.PageMessageException; public abstract class RestCall { private static final Logger log = LoggerFactory.getLogger(RestCall.class); + public static final LocTextKey REQUEST_TIMEOUT_MESSAGE = new LocTextKey("sebserver.overall.message.requesttimeout"); + public enum CallType { UNDEFINED, GET_SINGLE, @@ -161,6 +166,11 @@ public abstract class RestCall { } return Result.ofError(restCallError); + } catch (final ResourceAccessException rae) { + if (rae.getMessage().contains("Read timed out")) { + return Result.ofError(new PageMessageException(REQUEST_TIMEOUT_MESSAGE)); + } + return Result.ofError(rae); } catch (final Exception e) { final RestCallError restCallError = new RestCallError("Unexpected error while rest call", e); restCallError.errors.add(APIMessage.ErrorMessage.UNEXPECTED.of( diff --git a/src/main/resources/config/application-gui.properties b/src/main/resources/config/application-gui.properties index 6b20a69e..2fe17115 100644 --- a/src/main/resources/config/application-gui.properties +++ b/src/main/resources/config/application-gui.properties @@ -23,6 +23,11 @@ sebserver.gui.http.webservice.port=8080 sebserver.gui.http.webservice.contextPath=${server.servlet.context-path} sebserver.gui.entrypoint=/gui + +sebserver.http.client.connect-timeout=60000 +sebserver.http.client.connection-request-timeout=100000 +sebserver.http.client.read-timeout=200000 + sebserver.gui.webservice.apipath=${sebserver.webservice.api.admin.endpoint} # defines the polling interval that is used to poll the webservice for client connection data on a monitored exam page sebserver.gui.webservice.poll-interval=2000 diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 9a11c799..c0af9223 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -9,6 +9,7 @@ sebserver.overall.help=Documentation sebserver.overall.help.link=https://seb-server.readthedocs.io/en/latest/index.html sebserver.overall.message.leave.without.save=You have unsaved changes!
Are you sure you want to leave the page? The changes will be lost. +sebserver.overall.message.requesttimeout=There was a request timeout. If this is a search please try to narrow down your search by using the filter above and try again. sebserver.overall.upload=Please select a file sebserver.overall.upload.unsupported.file=This file type is not supported. Supported files are: {0} sebserver.overall.action.modify.cancel=Cancel