[2.0.0] Bump the lib to Spring 3 (#66)

This commit is contained in:
Baikov Dmitrii 2024-07-09 17:41:18 +03:00 committed by GitHub
parent 7f23818021
commit dc7cdd30a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 46 additions and 36 deletions

View File

@ -7,4 +7,4 @@ on:
jobs: jobs:
build: build:
uses: valitydev/java-workflow/.github/workflows/maven-library-build.yml@v1 uses: valitydev/java-workflow/.github/workflows/maven-library-build.yml@v3

View File

@ -8,7 +8,7 @@ on:
jobs: jobs:
deploy: deploy:
uses: valitydev/java-workflow/.github/workflows/maven-library-deploy.yml@v1 uses: valitydev/java-workflow/.github/workflows/maven-library-deploy.yml@v3
secrets: secrets:
server-username: ${{ secrets.OSSRH_USERNAME }} server-username: ${{ secrets.OSSRH_USERNAME }}
server-password: ${{ secrets.OSSRH_TOKEN }} server-password: ${{ secrets.OSSRH_TOKEN }}

28
pom.xml
View File

@ -7,12 +7,12 @@
<parent> <parent>
<groupId>dev.vality</groupId> <groupId>dev.vality</groupId>
<artifactId>library-parent-pom</artifactId> <artifactId>library-parent-pom</artifactId>
<version>1.0.2</version> <version>2.0.2</version>
<relativePath/> <relativePath/>
</parent> </parent>
<artifactId>adapter-common-lib</artifactId> <artifactId>adapter-common-lib</artifactId>
<version>1.2.13</version> <version>2.0.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>adapter-common-lib</name> <name>adapter-common-lib</name>
@ -44,9 +44,9 @@
<dockerfile.registry>${env.REGISTRY}</dockerfile.registry> <dockerfile.registry>${env.REGISTRY}</dockerfile.registry>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring.version>5.3.20</spring.version> <spring.version>6.1.10</spring.version>
<spring-boot.version>2.7.0</spring-boot.version> <spring-boot.version>3.3.1</spring-boot.version>
<jackson.version>2.13.2</jackson.version> <jackson.version>2.17.1</jackson.version>
<logback.version>1.2.11</logback.version> <logback.version>1.2.11</logback.version>
</properties> </properties>
@ -140,6 +140,16 @@
<version>4.0.0</version> <version>4.0.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.3.1</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.1.0</version>
</dependency>
<!-- Spring --> <!-- Spring -->
<dependency> <dependency>
@ -169,7 +179,7 @@
<dependency> <dependency>
<groupId>org.springframework.vault</groupId> <groupId>org.springframework.vault</groupId>
<artifactId>spring-vault-core</artifactId> <artifactId>spring-vault-core</artifactId>
<version>2.3.2</version> <version>3.1.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@ -209,19 +219,19 @@
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version> <version>5.10.3</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.junit.vintage</groupId> <groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId> <artifactId>junit-vintage-engine</artifactId>
<version>5.8.2</version> <version>5.10.3</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.testcontainers</groupId> <groupId>org.testcontainers</groupId>
<artifactId>vault</artifactId> <artifactId>vault</artifactId>
<version>1.17.5</version> <version>1.19.8</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -49,7 +49,7 @@ public class LoggingInterceptor implements ClientHttpRequestInterceptor {
private void logResponse(int requestNumber, ClientHttpResponse response) throws IOException { private void logResponse(int requestNumber, ClientHttpResponse response) throws IOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
String prefix = requestNumber + " < "; String prefix = requestNumber + " < ";
log.debug("{} Response: {} {} {}", prefix, response.getStatusCode(), response.getStatusCode().name(), log.debug("{} Response: {} {} {}", prefix, response.getStatusCode(), response.getStatusCode().value(),
response.getStatusText()); response.getStatusText());
log.debug("{} Headers: {}", prefix, response.getHeaders()); log.debug("{} Headers: {}", prefix, response.getHeaders());
String body = StreamUtils.copyToString(response.getBody(), StandardCharsets.UTF_8); String body = StreamUtils.copyToString(response.getBody(), StandardCharsets.UTF_8);
@ -74,12 +74,7 @@ public class LoggingInterceptor implements ClientHttpRequestInterceptor {
@Override @Override
public HttpStatus getStatusCode() throws IOException { public HttpStatus getStatusCode() throws IOException {
return response.getStatusCode(); return HttpStatus.resolve(response.getStatusCode().value());
}
@Override
public int getRawStatusCode() throws IOException {
return response.getRawStatusCode();
} }
@Override @Override

View File

@ -4,11 +4,11 @@ import dev.vality.woody.api.flow.WFlow;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.Filter; import jakarta.servlet.Filter;
import javax.servlet.FilterChain; import jakarta.servlet.FilterChain;
import javax.servlet.ServletException; import jakarta.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
public class NetworkFilterComponent { public class NetworkFilterComponent {

View File

@ -2,9 +2,9 @@ package dev.vality.adapter.common.component;
import dev.vality.woody.api.trace.ContextUtils; import dev.vality.woody.api.trace.ContextUtils;
import dev.vality.woody.api.trace.context.TraceContext; import dev.vality.woody.api.trace.context.TraceContext;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.springframework.boot.actuate.metrics.web.client.MetricsRestTemplateCustomizer; import org.springframework.boot.actuate.metrics.web.client.ObservationRestTemplateCustomizer;
import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
@ -15,18 +15,22 @@ import java.util.List;
public class RestTemplateComponent { public class RestTemplateComponent {
public RestTemplate getSimpleRestTemplate(MetricsRestTemplateCustomizer metricsRestTemplateCustomizer, public RestTemplate getSimpleRestTemplate(ObservationRestTemplateCustomizer observationRestTemplateCustomizer,
int networkTimeout) { int networkTimeout) {
HttpComponentsClientHttpRequestFactory requestFactory = getRequestFactory(getSimpleHttpClient()); HttpComponentsClientHttpRequestFactory requestFactory = getRequestFactory(getSimpleHttpClient());
RestTemplateBuilder restTemplateBuilder = getRestTemplateBuilder(requestFactory, metricsRestTemplateCustomizer); RestTemplateBuilder restTemplateBuilder =
getRestTemplateBuilder(requestFactory, observationRestTemplateCustomizer);
return getRestTemplate(restTemplateBuilder, networkTimeout); return getRestTemplate(restTemplateBuilder, networkTimeout);
} }
public RestTemplate getRestTemplateWithConverters(MetricsRestTemplateCustomizer metricsRestTemplateCustomizer, public RestTemplate getRestTemplateWithConverters(
ObservationRestTemplateCustomizer observationRestTemplateCustomizer,
List<HttpMessageConverter<?>> messageConverterList, List<HttpMessageConverter<?>> messageConverterList,
int networkTimeout) { int networkTimeout
) {
HttpComponentsClientHttpRequestFactory requestFactory = getRequestFactory(getSimpleHttpClient()); HttpComponentsClientHttpRequestFactory requestFactory = getRequestFactory(getSimpleHttpClient());
RestTemplateBuilder restTemplateBuilder = getRestTemplateBuilder(requestFactory, metricsRestTemplateCustomizer); RestTemplateBuilder restTemplateBuilder =
getRestTemplateBuilder(requestFactory, observationRestTemplateCustomizer);
RestTemplate restTemplate = getRestTemplate(restTemplateBuilder, networkTimeout); RestTemplate restTemplate = getRestTemplate(restTemplateBuilder, networkTimeout);
restTemplate.setMessageConverters(messageConverterList); restTemplate.setMessageConverters(messageConverterList);
return restTemplate; return restTemplate;
@ -41,11 +45,13 @@ public class RestTemplateComponent {
.build(); .build();
} }
public RestTemplateBuilder getRestTemplateBuilder(HttpComponentsClientHttpRequestFactory requestFactory, public RestTemplateBuilder getRestTemplateBuilder(
MetricsRestTemplateCustomizer metricsRestTemplateCustomizer) { HttpComponentsClientHttpRequestFactory requestFactory,
ObservationRestTemplateCustomizer observationRestTemplateCustomizer
) {
return new RestTemplateBuilder() return new RestTemplateBuilder()
.requestFactory(() -> requestFactory) .requestFactory(() -> requestFactory)
.additionalCustomizers(metricsRestTemplateCustomizer); .additionalCustomizers(observationRestTemplateCustomizer);
} }
public HttpComponentsClientHttpRequestFactory getRequestFactory(CloseableHttpClient httpClient) { public HttpComponentsClientHttpRequestFactory getRequestFactory(CloseableHttpClient httpClient) {
@ -59,5 +65,4 @@ public class RestTemplateComponent {
.disableAutomaticRetries() .disableAutomaticRetries()
.build(); .build();
} }
} }