Skip to content

Commit b311920

Browse files
authored
feat: Merge pull request #142 from pagopa/release-uat
feat: Release uat
2 parents 48c64da + bd1ca23 commit b311920

File tree

14 files changed

+220
-69
lines changed

14 files changed

+220
-69
lines changed

.grype.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ignore:
22
# false positive match on reactor-netty packages due to a bug on grype: https://github.com/anchore/grype/issues/431
3-
# Actually we are using netty 4.1.100
3+
# Actually we are using netty 4.1.104
44
- vulnerability: CVE-2014-3488 # solved in netty 3.9.2
55
- vulnerability: CVE-2015-2156 # solved in netty 4.1.42
66
- vulnerability: CVE-2019-16869 # solved in netty 4.1.42

Dockerfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Build
33
#
4-
FROM maven:3.9.5-amazoncorretto-17-al2023@sha256:eeaa7ab572d931f7273fc5cf31429923f172091ae388969e11f42ec6dd817d74 AS buildtime
4+
FROM maven:3.9.6-amazoncorretto-17-al2023@sha256:9ace9c9e506877b0e1877a7f709fa9dc7895d5fbdcc93d4170dfb3d25e2839e9 AS buildtime
55

66
WORKDIR /build
77
COPY . .
@@ -11,10 +11,7 @@ RUN mvn clean package -DskipTests
1111
#
1212
# Docker RUNTIME
1313
#
14-
FROM amazoncorretto:17.0.9-alpine3.18@sha256:df48bf2e183230040890460ddb4359a10aa6c7aad24bd88899482c52053c7e17 AS runtime
15-
16-
# security fixes
17-
RUN apk update && apk upgrade --no-cache libcrypto3 libssl3
14+
FROM amazoncorretto:17.0.9-alpine3.18@sha256:ed14b8c2f00dbb7b94446aa01d00583976ff0eda2577f5474035f3b4cf078dfd AS runtime
1815

1916
RUN apk --no-cache add shadow
2017
RUN useradd --uid 10000 runner
@@ -24,7 +21,7 @@ WORKDIR /app
2421

2522
COPY --from=buildtime /build/target/*.jar /app/app.jar
2623
# The agent is enabled at runtime via JAVA_TOOL_OPTIONS.
27-
ADD https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.4.18/applicationinsights-agent-3.4.18.jar /app/applicationinsights-agent.jar
24+
ADD https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.4.19/applicationinsights-agent-3.4.19.jar /app/applicationinsights-agent.jar
2825

2926
RUN chown -R runner:runner /app
3027

pom.xml

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.1.5</version>
8+
<version>3.1.7</version>
99
</parent>
1010

1111
<groupId>it.gov.pagopa</groupId>
1212
<artifactId>idpay-transactions</artifactId>
1313
<name>idpay-transactions</name>
1414
<description>Transactions Microservice</description>
15-
<version>1.1.4</version>
15+
<version>1.2.0</version>
1616

1717
<properties>
1818
<java.version>17</java.version>
@@ -44,6 +44,11 @@
4444
<groupId>org.springframework.boot</groupId>
4545
<artifactId>spring-boot-starter-aop</artifactId>
4646
</dependency>
47+
<dependency>
48+
<groupId>org.springdoc</groupId>
49+
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
50+
<version>2.3.0</version>
51+
</dependency>
4752

4853
<!--3rd party library-->
4954
<dependency>
@@ -55,17 +60,12 @@
5560
<dependency>
5661
<groupId>org.apache.commons</groupId>
5762
<artifactId>commons-text</artifactId>
58-
<version>1.10.0</version>
59-
</dependency>
60-
<dependency>
61-
<groupId>org.springdoc</groupId>
62-
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
63-
<version>2.2.0</version>
63+
<version>1.11.0</version>
6464
</dependency>
6565
<dependency>
6666
<groupId>org.codehaus.janino</groupId>
6767
<artifactId>janino</artifactId>
68-
<version>3.1.10</version>
68+
<version>3.1.11</version>
6969
</dependency>
7070

7171
<!-- Security fixes -->
@@ -88,22 +88,39 @@
8888
<groupId>org.springframework.boot</groupId>
8989
<artifactId>spring-boot-starter-test</artifactId>
9090
<scope>test</scope>
91+
<exclusions>
92+
<exclusion>
93+
<groupId>junit</groupId>
94+
<artifactId>junit</artifactId>
95+
</exclusion>
96+
</exclusions>
9197
</dependency>
9298
<dependency>
9399
<groupId>org.springframework.kafka</groupId>
94100
<artifactId>spring-kafka-test</artifactId>
95101
<scope>test</scope>
96102
</dependency>
103+
<dependency>
104+
<groupId>org.springframework.cloud</groupId>
105+
<artifactId>spring-cloud-contract-wiremock</artifactId>
106+
<scope>test</scope>
107+
</dependency>
97108
<dependency>
98109
<groupId>com.github.javafaker</groupId>
99110
<artifactId>javafaker</artifactId>
100111
<version>1.0.2</version>
101112
<scope>test</scope>
113+
<exclusions>
114+
<exclusion>
115+
<groupId>org.yaml</groupId>
116+
<artifactId>snakeyaml</artifactId>
117+
</exclusion>
118+
</exclusions>
102119
</dependency>
103120
<dependency>
104121
<groupId>de.flapdoodle.embed</groupId>
105122
<artifactId>de.flapdoodle.embed.mongo.spring30x</artifactId>
106-
<version>4.9.3</version>
123+
<version>4.11.0</version>
107124
<scope>test</scope>
108125
</dependency>
109126
<dependency>
@@ -112,12 +129,6 @@
112129
<version>4.2.0</version>
113130
<scope>test</scope>
114131
</dependency>
115-
<dependency>
116-
<groupId>org.springframework.cloud</groupId>
117-
<artifactId>spring-cloud-contract-wiremock</artifactId>
118-
<version>4.0.4</version>
119-
<scope>test</scope>
120-
</dependency>
121132
</dependencies>
122133

123134
<dependencyManagement>
@@ -133,15 +144,24 @@
133144
<dependency>
134145
<groupId>io.netty</groupId>
135146
<artifactId>netty-bom</artifactId>
136-
<!-- Forced to 4.1.100 due to https://nvd.nist.gov/vuln/detail/CVE-2023-44487 -->
137-
<version>4.1.100.Final</version>
147+
<!-- Forced to >= 4.1.104 due to https://nvd.nist.gov/vuln/detail/CVE-2023-44487 -->
148+
<version>4.1.104.Final</version>
138149
<type>pom</type>
139150
<scope>import</scope>
140151
</dependency>
141152
</dependencies>
142153
</dependencyManagement>
154+
143155
<build>
144156
<plugins>
157+
<plugin>
158+
<groupId>org.apache.maven.plugins</groupId>
159+
<artifactId>maven-surefire-plugin</artifactId>
160+
<version>3.2.3</version>
161+
<configuration>
162+
<argLine>@{argLine} -Duser.timezone=Europe/Rome</argLine>
163+
</configuration>
164+
</plugin>
145165
<plugin>
146166
<groupId>org.springframework.boot</groupId>
147167
<artifactId>spring-boot-maven-plugin</artifactId>
@@ -157,7 +177,7 @@
157177
<plugin>
158178
<groupId>io.github.git-commit-id</groupId>
159179
<artifactId>git-commit-id-maven-plugin</artifactId>
160-
<version>5.0.0</version>
180+
<version>7.0.0</version>
161181
<executions>
162182
<execution>
163183
<id>get-the-git-infos</id>

src/main/java/it/gov/pagopa/common/web/exception/ErrorManager.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,26 @@
55
import org.springframework.http.HttpStatus;
66
import org.springframework.http.MediaType;
77
import org.springframework.http.ResponseEntity;
8+
import org.springframework.lang.Nullable;
89
import org.springframework.web.bind.annotation.ExceptionHandler;
910
import org.springframework.web.bind.annotation.RestControllerAdvice;
1011
import org.springframework.web.server.ServerWebExchange;
1112

13+
import java.util.Optional;
14+
1215

1316
@RestControllerAdvice
1417
@Slf4j
1518
public class ErrorManager {
16-
private static final ErrorDTO defaultErrorDTO;
17-
static {
18-
defaultErrorDTO =new ErrorDTO("Error", "Something gone wrong");
19+
private final ErrorDTO defaultErrorDTO;
20+
21+
public ErrorManager(@Nullable ErrorDTO defaultErrorDTO) {
22+
this.defaultErrorDTO = Optional.ofNullable(defaultErrorDTO)
23+
.orElse(new ErrorDTO("Error", "Something gone wrong"));
1924
}
2025
@ExceptionHandler(RuntimeException.class)
2126
protected ResponseEntity<ErrorDTO> handleException(RuntimeException error, ServerWebExchange exchange) {
22-
if(!(error instanceof ClientException clientException) || clientException.isPrintStackTrace() || clientException.getCause() != null){
23-
log.error("Something went wrong handling request {}", getRequestDetails(exchange), error);
24-
} else {
25-
log.info("A {} occurred handling request {}: HttpStatus {} - {} at {}",
26-
clientException.getClass().getSimpleName(),
27-
getRequestDetails(exchange),
28-
clientException.getHttpStatus(),
29-
clientException.getMessage(),
30-
clientException.getStackTrace().length > 0 ? clientException.getStackTrace()[0] : "UNKNOWN");
31-
}
27+
logClientException(error, exchange);
3228

3329
if(error instanceof ClientExceptionNoBody clientExceptionNoBody){
3430
return ResponseEntity.status(clientExceptionNoBody.getHttpStatus()).build();
@@ -50,6 +46,27 @@ protected ResponseEntity<ErrorDTO> handleException(RuntimeException error, Serve
5046
}
5147
}
5248

49+
public static void logClientException(RuntimeException error, ServerWebExchange exchange) {
50+
String clientExceptionMessage = "";
51+
if(error instanceof ClientException clientException) {
52+
clientExceptionMessage = ": HttpStatus %s - %s%s".formatted(
53+
clientException.getHttpStatus(),
54+
(clientException instanceof ClientExceptionWithBody clientExceptionWithBody) ? clientExceptionWithBody.getCode() + ": " : "",
55+
clientException.getMessage()
56+
);
57+
}
58+
59+
if(!(error instanceof ClientException clientException) || clientException.isPrintStackTrace() || error.getCause() != null){
60+
log.error("Something went wrong handling request {}{}", getRequestDetails(exchange), clientExceptionMessage, error);
61+
} else {
62+
log.info("A {} occurred handling request {}{} at {}",
63+
error.getClass().getSimpleName() ,
64+
getRequestDetails(exchange),
65+
clientExceptionMessage,
66+
error.getStackTrace().length > 0 ? error.getStackTrace()[0] : "UNKNOWN");
67+
}
68+
}
69+
5370
public static String getRequestDetails(ServerWebExchange exchange) {
5471
return "%s %s (%s)".formatted(exchange.getRequest().getMethod(), exchange.getRequest().getURI(), exchange.getRequest().getId());
5572
}

src/main/java/it/gov/pagopa/common/web/exception/MongoExceptionHandler.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,33 @@
1212
import org.springframework.http.MediaType;
1313
import org.springframework.http.ResponseEntity;
1414
import org.springframework.http.ResponseEntity.BodyBuilder;
15+
import org.springframework.lang.Nullable;
1516
import org.springframework.web.bind.annotation.ExceptionHandler;
1617
import org.springframework.web.bind.annotation.RestControllerAdvice;
1718
import org.springframework.web.server.ServerWebExchange;
1819

20+
import java.util.Optional;
21+
1922
@RestControllerAdvice
2023
@Slf4j
2124
@Order(Ordered.HIGHEST_PRECEDENCE)
2225
public class MongoExceptionHandler {
2326

2427
private final ErrorManager errorManager;
2528

26-
public MongoExceptionHandler(ErrorManager errorManager) {
29+
private final ErrorDTO tooManyRequestsErrorDTO;
30+
31+
public MongoExceptionHandler(ErrorManager errorManager, @Nullable ErrorDTO tooManyRequestsErrorDTO) {
2732
this.errorManager = errorManager;
33+
34+
this.tooManyRequestsErrorDTO = Optional.ofNullable(tooManyRequestsErrorDTO)
35+
.orElse(new ErrorDTO("TOO_MANY_REQUESTS", "Too Many Requests"));
2836
}
2937

38+
3039
@ExceptionHandler(DataAccessException.class)
3140
protected ResponseEntity<ErrorDTO> handleDataAccessException(
32-
DataAccessException ex, ServerWebExchange request) {
41+
DataAccessException ex, ServerWebExchange request) {
3342

3443
if (MongoRequestRateTooLargeRetryer.isRequestRateTooLargeException(ex)) {
3544
Long retryAfterMs = MongoRequestRateTooLargeRetryer.getRetryAfterMs(ex);
@@ -66,7 +75,7 @@ private ResponseEntity<ErrorDTO> getErrorDTOResponseEntity(Exception ex,
6675
}
6776

6877
return bodyBuilder
69-
.body(new ErrorDTO("TOO_MANY_REQUESTS", "TOO_MANY_REQUESTS"));
78+
.body(tooManyRequestsErrorDTO);
7079
}
7180

72-
}
81+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package it.gov.pagopa.idpay.transactions.config;
2+
3+
import it.gov.pagopa.common.web.dto.ErrorDTO;
4+
import it.gov.pagopa.idpay.transactions.utils.ExceptionConstants;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
@Configuration
9+
public class TransactionErrorManagerConfig {
10+
11+
@Bean
12+
ErrorDTO defaultErrorDTO() {
13+
return new ErrorDTO(
14+
ExceptionConstants.ExceptionCode.GENERIC_ERROR,
15+
ExceptionConstants.ExceptionMessage.GENERIC_ERROR
16+
);
17+
}
18+
19+
@Bean
20+
ErrorDTO tooManyRequestsErrorDTO() {
21+
return new ErrorDTO(ExceptionConstants.ExceptionCode.TOO_MANY_REQUESTS, ExceptionConstants.ExceptionMessage.TOO_MANY_REQUESTS);
22+
}
23+
}

src/main/java/it/gov/pagopa/idpay/transactions/controller/TransactionsControllerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import it.gov.pagopa.common.web.exception.ClientExceptionWithBody;
44
import it.gov.pagopa.idpay.transactions.model.RewardTransaction;
55
import it.gov.pagopa.idpay.transactions.service.RewardTransactionService;
6+
import it.gov.pagopa.idpay.transactions.utils.ExceptionConstants;
67
import lombok.extern.slf4j.Slf4j;
78
import org.springframework.data.domain.Pageable;
89
import org.springframework.http.HttpStatus;
@@ -28,7 +29,7 @@ public Flux<RewardTransaction> findAll(String idTrxIssuer, String userId, LocalD
2829
}else if(userId != null && trxDateStart != null && trxDateEnd != null){
2930
return rewardTransactionService.findByRange(userId, trxDateStart, trxDateEnd, amount, pageable);
3031
}else {
31-
throw new ClientExceptionWithBody(HttpStatus.BAD_REQUEST, "Error","Mandatory filters are missing. Insert one of the following options: 1) idTrxIssuer 2) userId, trxDateStart and trxDateEnd");
32+
throw new ClientExceptionWithBody(HttpStatus.BAD_REQUEST, ExceptionConstants.ExceptionCode.TRANSACTIONS_MISSING_MANDATORY_FILTERS,ExceptionConstants.ExceptionMessage.TRANSACTIONS_MISSING_MANDATORY_FILTERS);
3233
}
3334
}
3435
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package it.gov.pagopa.idpay.transactions.utils;
2+
3+
public final class ExceptionConstants {
4+
private ExceptionConstants(){}
5+
6+
public static final class ExceptionCode {
7+
private ExceptionCode(){}
8+
9+
public static final String TOO_MANY_REQUESTS = "TRANSACTIONS_TOO_MANY_REQUESTS";
10+
public static final String GENERIC_ERROR = "TRANSACTIONS_GENERIC_ERROR";
11+
public static final String TRANSACTIONS_MISSING_MANDATORY_FILTERS = "TRANSACTIONS_MISSING_MANDATORY_FILTERS";
12+
}
13+
14+
public static final class ExceptionMessage {
15+
private ExceptionMessage(){}
16+
17+
public static final String TOO_MANY_REQUESTS = "Too Many Requests";
18+
public static final String GENERIC_ERROR = "Something gone wrong";
19+
public static final String TRANSACTIONS_MISSING_MANDATORY_FILTERS = "Mandatory filters are missing. Insert one of the following options: 1) idTrxIssuer 2) userId, trxDateStart and trxDateEnd";
20+
}
21+
}

src/test/java/it/gov/pagopa/common/kafka/KafkaTestUtilitiesService.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ public class KafkaTestUtilitiesService {
6565
private String applicationName;
6666
@Value("${spring.kafka.bootstrap-servers}")
6767
private String bootstrapServers;
68-
@Value("${spring.cloud.stream.kafka.binder.zkNodes}")
69-
private String zkNodes;
7068

7169
@Autowired
7270
private ObjectMapper objectMapper;
@@ -111,7 +109,7 @@ void clearTopics() {
111109

112110
/** It will return usefull URLs related to embedded kafka */
113111
public String getKafkaUrls() {
114-
return "bootstrapServers: %s, zkNodes: %s".formatted(bootstrapServers, zkNodes);
112+
return "bootstrapServers: %s".formatted(bootstrapServers);
115113
}
116114

117115
//region consume messages
@@ -320,7 +318,7 @@ public void assertCommitOrder(String flowName, int totalSendMessages) {
320318
}
321319
//endregion
322320

323-
//region error topic
321+
//region error topic
324322
public void checkErrorsPublished(String topicErrors, Pattern errorUseCaseIdPatternMatch, int expectedErrorMessagesNumber, long maxWaitingMs, List<Pair<Supplier<String>, java.util.function.Consumer<ConsumerRecord<String, String>>>> errorUseCases) {
325323
final List<ConsumerRecord<String, String>> errors = consumeMessages(topicErrors, expectedErrorMessagesNumber, maxWaitingMs);
326324
for (final ConsumerRecord<String, String> record : errors) {

0 commit comments

Comments
 (0)