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 5078ca63..81e442f4 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,7 +38,6 @@ public class ETranslationTranslationService extends AbstractTranslationService { private String serviceId; private final String baseUrl; private final String domain; - //this is the base url of the translation api (without the request handler (or the controller) endpoint) private final String callbackUrl; private final String callbackErrorUrl; private final String credentialUsername; @@ -49,24 +48,26 @@ 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 ETranslationTranslationService(String baseUrl, String domain, String callbackUrl, String callbackErrorUrl, int maxWaitMillisec, + public ETranslationTranslationService(String baseUrl, String domain, String translationApiBaseUrl, int maxWaitMillisec, String username, String password, RedisMessageListenerContainer redisMessageListenerContainer) throws TranslationException { if(!baseUrlTests.equals(baseUrl)) { - validateETranslConfigParams(baseUrl, domain, callbackUrl, callbackErrorUrl, maxWaitMillisec, username, password); + validateETranslConfigParams(baseUrl, domain, translationApiBaseUrl, maxWaitMillisec, username, password); } this.baseUrl = baseUrl; this.domain = domain; - this.callbackUrl=callbackUrl; - this.callbackErrorUrl=callbackErrorUrl; + this.callbackUrl=translationApiBaseUrl + eTranslationCallbackRelativeUrl; + this.callbackErrorUrl=translationApiBaseUrl + eTranslationErrorCallbackRelativeUrl; this.maxWaitMillisec=maxWaitMillisec; this.credentialUsername=username; this.credentialPwd=password; this.redisMessageListenerContainer=redisMessageListenerContainer; } - private void validateETranslConfigParams(String baseUrl, String domain, String callbackUrl, - String callbackErrorUrl, int maxWaitMillisec, String username, String password) throws TranslationException { + private void validateETranslConfigParams(String baseUrl, String domain, String translationApiBaseUrl, + int maxWaitMillisec, String username, String password) throws TranslationException { List missingParams= new ArrayList<>(6); if(StringUtils.isBlank(baseUrl)) { missingParams.add("baseUrl"); @@ -74,11 +75,8 @@ private void validateETranslConfigParams(String baseUrl, String domain, String c if(StringUtils.isBlank(domain)) { missingParams.add("domain"); } - if(StringUtils.isBlank(callbackUrl)) { - missingParams.add("callbackUrl"); - } - if(StringUtils.isBlank(callbackErrorUrl)) { - missingParams.add("callbackErrorUrl"); + if(StringUtils.isBlank(translationApiBaseUrl)) { + missingParams.add("translationApiBaseUrl"); } if(maxWaitMillisec<=0) { missingParams.add("maxWaitMillisec (must be >0)"); @@ -166,13 +164,16 @@ private void createRedisMessageListenerAndWaitForResults(List tr if(LOGGER.isDebugEnabled()) { LOGGER.debug("Received message from redis message listener is: {}", response); } - if(response.contains(ETranslationTranslationService.eTranslationErrorCallbackIndicator)) { - //eTtransl error callback received - throw new TranslationException(response); - } - else if(response!=null) { - //extractTranslationsFromETranslationHtmlResponse(translationObjs, redisMessageListenerAdapter, response); - extractTranslationsFromETranslationResponse(translationObjs, redisMessageListenerAdapter, response); + + if(response!=null) { + if(response.contains(ETranslationTranslationService.eTranslationErrorCallbackIndicator)) { + //eTtransl error callback received + throw new TranslationException(response); + } + else { + //extractTranslationsFromETranslationHtmlResponse(translationObjs, redisMessageListenerAdapter, response); + extractTranslationsFromETranslationResponse(translationObjs, redisMessageListenerAdapter, response); + } } /* unsubscibe this listener which automatically deletes the created pub/sub channel, * which also gets deleted if the app is stopped or anyhow broken. @@ -320,6 +321,9 @@ private long createHttpRequest(String content) throws TranslationException, IOEx long requestNumber; try{ requestNumber = Long.parseLong(respBody); + if(LOGGER.isDebugEnabled()) { + LOGGER.debug("eTranslation request sent with the request-id: {} .", requestNumber); + } if(requestNumber < 0) { throw wrapETranslationErrorResponse(respBody); } diff --git a/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/TranslationRestIT.java b/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/TranslationRestIT.java index c76d6db8..3397b13e 100644 --- a/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/TranslationRestIT.java +++ b/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/TranslationRestIT.java @@ -172,7 +172,7 @@ void translationETranslation() throws Exception { mockMvc .perform( - post("/etranslation/callback").characterEncoding(StandardCharsets.UTF_8) + post(ETranslationTranslationService.eTranslationCallbackRelativeUrl).characterEncoding(StandardCharsets.UTF_8) .param("external-reference", eTranslRef) .param("translated-text", translatedText.toString())) .andExpect(status().isOk()); diff --git a/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationApiAutoconfig.java b/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationApiAutoconfig.java index 68413283..aee88295 100644 --- a/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationApiAutoconfig.java +++ b/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationApiAutoconfig.java @@ -223,8 +223,7 @@ public ETranslationTranslationService getETranslationService( return new ETranslationTranslationService( translationConfig.getEtranslationBaseUrl(), translationConfig.getEtranslationDomain(), - translationConfig.getEtranslationCallback(), - translationConfig.getEtranslationErrorCallback(), + translationConfig.getTranslationApiBaseUrl(), translationConfig.getEtranslationMaxWaitMillisec(), translationConfig.getEtranslationUsername(), translationConfig.getEtranslationPassword(), diff --git a/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationConfig.java b/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationConfig.java index f5f6032c..496a0d04 100644 --- a/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationConfig.java +++ b/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationConfig.java @@ -19,6 +19,9 @@ public class TranslationConfig{ public static final String CONFIG_FOLDER = "/opt/app/config"; + @Value("${translation.api.baseUrl:#{null}}") + private String translationApiBaseUrl; + @Value("${europeana.apikey.jwttoken.signaturekey:}") private String apiKeyPublicKey; @@ -63,13 +66,7 @@ public class TranslationConfig{ @Value("${translation.eTranslation.domain:#{null}}") private String etranslationDomain; - - @Value("${translation.eTranslation.callback:#{null}}") - private String etranslationCallback; - - @Value("${translation.eTranslation.error.callback:#{null}}") - private String etranslationErrorCallback; - + @Value("${translation.eTranslation.maxWaitMillisec:30000}") private int etranslationMaxWaitMillisec; @@ -83,6 +80,10 @@ public TranslationConfig() { super(); } + public String getTranslationApiBaseUrl() { + return translationApiBaseUrl; + } + public String getApiKeyPublicKey() { return apiKeyPublicKey; } @@ -173,14 +174,6 @@ public String getEtranslationDomain() { return etranslationDomain; } - public String getEtranslationCallback() { - return etranslationCallback; - } - - public String getEtranslationErrorCallback() { - return etranslationErrorCallback; - } - public int getEtranslationMaxWaitMillisec() { return etranslationMaxWaitMillisec; } 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 d7ff0d07..5c2513b9 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 @@ -26,7 +26,7 @@ public ETranslationCallbackController(RedisTemplate r } @Tag(description = "ETranslation callback endpoint", name = "eTranslationCallback") - @PostMapping(value = "/etranslation/callback") + @PostMapping(value = ETranslationTranslationService.eTranslationCallbackRelativeUrl) public void eTranslationCallback( @RequestParam(value = "target-language", required = false) String targetLanguage, @RequestParam(value = "translated-text", required = false) String translatedTextSnippet, @@ -43,7 +43,7 @@ public void eTranslationCallback( } @Tag(description = "ETranslation error callback endpoint", name = "eTranslationErrorCallback") - @PostMapping(value = "/etranslation/error-callback") + @PostMapping(value = ETranslationTranslationService.eTranslationErrorCallbackRelativeUrl) public void eTranslationErrorCallback( @RequestParam(value = "error-code", required = false) String errorCode, @RequestParam(value = "error-message", required = false) String errorMessage, diff --git a/translation-web/src/main/resources/translation.user.properties.template b/translation-web/src/main/resources/translation.user.properties.template index 3188e421..65d753a1 100644 --- a/translation-web/src/main/resources/translation.user.properties.template +++ b/translation-web/src/main/resources/translation.user.properties.template @@ -47,12 +47,12 @@ truststore.password= translation.runtime=application +translation.api.baseUrl= + translation.eTranslation.baseUrl= translation.eTranslation.username= translation.eTranslation.password= # eTranslation domain could be "SPD" (for neural and speed-optimized statistical engines on the cloud. This is the default.) else "Europeana" translation.eTranslation.domain= -translation.eTranslation.callback= -translation.eTranslation.error.callback= translation.eTranslation.maxWaitMillisec=