From d2bda91efce672f7a5d23aad0230f9bcb341ec24 Mon Sep 17 00:00:00 2001 From: gsergiu <4517853+gsergiu@users.noreply.github.com> Date: Wed, 29 May 2024 11:03:37 +0200 Subject: [PATCH 1/2] switched back to lowercase etranslation --- .../service/etranslation/ETranslationTranslationService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/translation-service-etranslation/src/main/java/eu/europeana/api/translation/service/etranslation/ETranslationTranslationService.java b/translation-service-etranslation/src/main/java/eu/europeana/api/translation/service/etranslation/ETranslationTranslationService.java index c006bd10..c013c7c3 100644 --- a/translation-service-etranslation/src/main/java/eu/europeana/api/translation/service/etranslation/ETranslationTranslationService.java +++ b/translation-service-etranslation/src/main/java/eu/europeana/api/translation/service/etranslation/ETranslationTranslationService.java @@ -38,8 +38,8 @@ public class ETranslationTranslationService extends AbstractTranslationService { public static final String markupDelimiter="\ndeenPVsaOg\n";//base64 encoded string (as in generateRedisKey()) with new lines public static final String markupDelimiterWithoutNewline="deenPVsaOg"; public static final String eTranslationErrorCallbackIndicator="eTranslationErrorCallback"; - public static final String eTranslationCallbackRelativeUrl="/eTranslation/callback"; - public static final String eTranslationErrorCallbackRelativeUrl="/eTranslation/error-callback"; + public static final String eTranslationCallbackRelativeUrl="/etranslation/callback"; + public static final String eTranslationErrorCallbackRelativeUrl="/etranslation/error-callback"; private String serviceId; private final String baseUrl; From db537dc46e8cecb540f53478d887aa9b65006e22 Mon Sep 17 00:00:00 2001 From: gsergiu <4517853+gsergiu@users.noreply.github.com> Date: Wed, 29 May 2024 11:32:01 +0200 Subject: [PATCH 2/2] timeout simulation #EA-3859 --- .../web/ETranslationCallbackController.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/translation-web/src/main/java/eu/europeana/api/translation/web/ETranslationCallbackController.java b/translation-web/src/main/java/eu/europeana/api/translation/web/ETranslationCallbackController.java index 963dd7cb..2c662549 100644 --- a/translation-web/src/main/java/eu/europeana/api/translation/web/ETranslationCallbackController.java +++ b/translation-web/src/main/java/eu/europeana/api/translation/web/ETranslationCallbackController.java @@ -4,6 +4,8 @@ import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -32,8 +34,8 @@ public void eTranslationCallbackPost( @RequestParam(value = "target-language", required = false) String targetLanguage, @RequestParam(value = "translated-text", required = true) String translatedTextSnippet, @RequestParam(value = "request-id", required = true) String requestId, - @RequestParam(value = "external-reference", required = true) String externalReference, - @RequestBody(required = false) String body) { + @RequestParam(value = "external-reference", required = true) String externalReference) { + if(LOGGER.isDebugEnabled()) { LOGGER.debug("eTranslation callback has been received with the request-id: {}, and the" + " external-reference: {}", LoggingUtils.sanitizeUserInput(requestId), LoggingUtils.sanitizeUserInput(externalReference)); @@ -45,18 +47,35 @@ public void eTranslationCallbackPost( @Tag(description = "ETranslation callback endpoint", name = "eTranslationCallback") @GetMapping(value = ETranslationTranslationService.eTranslationCallbackRelativeUrl) - public void eTranslationCallbackGet( + public ResponseEntity eTranslationCallbackGet( @RequestParam(value = "target-language", required = false) String targetLanguage, - @RequestParam(value = "translated-text", required = true) String translatedTextSnippet, - @RequestParam(value = "request-id", required = true) String requestId, - @RequestParam(value = "external-reference", required = true) String externalReference) { + @RequestParam(value = "translated-text", required = false) String translatedTextSnippet, + @RequestParam(value = "request-id", required = false) String requestId, + @RequestParam(value = "external-reference", required = false) String externalReference, + @RequestParam(value = "timeout", required = false) int timeout, + @RequestBody(required = false) String body) { + if(timeout > 0) { + try { + //for simulation purposes, wait for $timeout seconds + Thread.sleep(timeout * 1000); + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); + } catch (InterruptedException e) { + //should not happen + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.toString()); + } + } + if(LOGGER.isDebugEnabled()) { LOGGER.debug("eTranslation callback has been received with the request-id: {}, and the" - + " external-reference: {}", LoggingUtils.sanitizeUserInput(requestId), LoggingUtils.sanitizeUserInput(externalReference)); + + " external-reference: {}", LoggingUtils.sanitizeUserInput(""+ requestId), LoggingUtils.sanitizeUserInput(""+externalReference)); } if(externalReference!=null && translatedTextSnippet!=null) { redisTemplate.convertAndSend(externalReference, translatedTextSnippet); } + + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); + + } @Tag(description = "ETranslation error callback endpoint", name = "eTranslationErrorCallback")