Skip to content

Commit

Permalink
timeout simulation #EA-3859
Browse files Browse the repository at this point in the history
  • Loading branch information
gsergiu committed May 29, 2024
1 parent d2bda91 commit db537dc
Showing 1 changed file with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -45,18 +47,35 @@ public void eTranslationCallbackPost(

@Tag(description = "ETranslation callback endpoint", name = "eTranslationCallback")
@GetMapping(value = ETranslationTranslationService.eTranslationCallbackRelativeUrl)
public void eTranslationCallbackGet(
public ResponseEntity<String> 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")
Expand Down

0 comments on commit db537dc

Please sign in to comment.