Permalink
Show file tree
Hide file tree
7 changes: 7 additions & 0 deletions
7
dpppt-backend-sdk/dpppt-backend-sdk-ws/src/main/docker/application.yml
3 changes: 3 additions & 0 deletions
3
...pppt-backend-sdk-ws/src/main/java/org/dpppt/backend/sdk/ws/controller/GaenController.java
7 changes: 7 additions & 0 deletions
7
dpppt-backend-sdk/dpppt-backend-sdk-ws/src/main/resources/application.yaml
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[MAPR] Setted responses retention time on fake requests
- Loading branch information
Showing
7 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...dk-ws/src/main/java/org/dpppt/backend/sdk/ws/radarcovid/annotation/ResponseRetention.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Copyright (c) 2020 Gobierno de España | ||
| * | ||
| * 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/. | ||
| * | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
| package org.dpppt.backend.sdk.ws.radarcovid.annotation; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Documented | ||
| @Retention(value=RetentionPolicy.RUNTIME) | ||
| @Target(value={ElementType.CONSTRUCTOR, ElementType.METHOD}) | ||
| public @interface ResponseRetention { | ||
|
|
||
| /** | ||
| * Environment property with response retention time, in milliseconds | ||
| */ | ||
| String time(); | ||
| } |
89 changes: 89 additions & 0 deletions
89
...java/org/dpppt/backend/sdk/ws/radarcovid/config/ResponseRetentionAspectConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Copyright (c) 2020 Gobierno de España | ||
| * | ||
| * 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/. | ||
| * | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
| package org.dpppt.backend.sdk.ws.radarcovid.config; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| import org.apache.commons.lang3.math.NumberUtils; | ||
| import org.aspectj.lang.ProceedingJoinPoint; | ||
| import org.aspectj.lang.annotation.Around; | ||
| import org.aspectj.lang.annotation.Aspect; | ||
| import org.aspectj.lang.annotation.Pointcut; | ||
| import org.dpppt.backend.sdk.ws.radarcovid.annotation.ResponseRetention; | ||
| import org.dpppt.backend.sdk.ws.radarcovid.exception.RadarCovidServerException; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.core.env.Environment; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * Aspect in charge of controlling the minimum response time of a service. | ||
| */ | ||
| @Configuration | ||
| @ConditionalOnProperty(name = "application.response.retention.enabled", havingValue = "true", matchIfMissing = true) | ||
| public class ResponseRetentionAspectConfiguration { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger("org.dpppt.backend.sdk.ws.radarcovid.annotation.ResponseRetention"); | ||
|
|
||
| @Autowired | ||
| private Environment environment; | ||
|
|
||
| @Aspect | ||
| @Component | ||
| public class ControllerTimeResponseControlAspect { | ||
|
|
||
| @Pointcut("@annotation(responseRetention)") | ||
| public void annotationPointCutDefinition(ResponseRetention responseRetention){ | ||
| } | ||
|
|
||
| @Around("execution(@org.dpppt.backend.sdk.ws.radarcovid.annotation.ResponseRetention * *..controller..*(..)) && annotationPointCutDefinition(responseRetention)") | ||
| public Object logAround(ProceedingJoinPoint joinPoint, ResponseRetention responseRetention) throws Throwable { | ||
|
|
||
| log.debug("************************* INIT TIME RESPONSE CONTROL *********************************"); | ||
| long start = System.currentTimeMillis(); | ||
| try { | ||
| String className = joinPoint.getSignature().getDeclaringTypeName(); | ||
| String methodName = joinPoint.getSignature().getName(); | ||
| Object result = joinPoint.proceed(); | ||
| long elapsedTime = System.currentTimeMillis() - start; | ||
| long responseRetentionTimeMillis = getTimeMillis(responseRetention.time()); | ||
| log.debug("Controller : Controller {}.{} () execution time : {} ms", className, methodName, elapsedTime); | ||
| if (elapsedTime < responseRetentionTimeMillis) { | ||
| Thread.sleep(responseRetentionTimeMillis - elapsedTime); | ||
| } | ||
| elapsedTime = System.currentTimeMillis() - start; | ||
| log.debug("Controller : Controller {}.{} () NEW execution time : {} ms", className, methodName, elapsedTime); | ||
| log.debug("************************* END TIME RESPONSE CONTROL **********************************"); | ||
| return result; | ||
|
|
||
| } catch (IllegalArgumentException e) { | ||
| log.error("Controller : Illegal argument {} in {} ()", Arrays.toString(joinPoint.getArgs()), | ||
| joinPoint.getSignature().getName()); | ||
| log.debug("************************* END TIME RESPONSE CONTROL **********************************"); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| private long getTimeMillis(String timeMillisString) { | ||
| String stringValue = environment.getProperty(timeMillisString); | ||
| if (NumberUtils.isCreatable(stringValue)) { | ||
| return Long.parseLong(stringValue); | ||
| } else { | ||
| throw new RadarCovidServerException(HttpStatus.INTERNAL_SERVER_ERROR, | ||
| "Invalid timeMillisString value \"" + timeMillisString + "\" - not found or cannot parse into long"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
34 changes: 34 additions & 0 deletions
34
...rc/main/java/org/dpppt/backend/sdk/ws/radarcovid/exception/RadarCovidServerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright (c) 2020 Gobierno de España | ||
| * | ||
| * 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/. | ||
| * | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
| package org.dpppt.backend.sdk.ws.radarcovid.exception; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
|
|
||
|
|
||
| public class RadarCovidServerException extends RuntimeException { | ||
|
|
||
| private final HttpStatus httpStatus; | ||
|
|
||
| /** | ||
| * The Constructor for the Exception class. | ||
| * | ||
| * @param httpStatus the state of the server | ||
| * @param message the message | ||
| */ | ||
| public RadarCovidServerException(HttpStatus httpStatus, String message) { | ||
| super(message); | ||
| this.httpStatus = httpStatus; | ||
| } | ||
|
|
||
| public HttpStatus getHttpStatus() { | ||
| return httpStatus; | ||
| } | ||
|
|
||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters