diff options
author | Steve Marion <steve.marion@sonarsource.com> | 2024-12-16 11:48:52 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-12-31 20:03:06 +0000 |
commit | 7d6e9e42e42a982bcb6648a2ef161293642b9415 (patch) | |
tree | b762a668c979d3b62ee859c3ad2ae2a785be539a /server/sonar-webserver-webapi-v2 | |
parent | 928e495ba84502a6b95a1bd64ae725f94de89bb6 (diff) | |
download | sonarqube-7d6e9e42e42a982bcb6648a2ef161293642b9415.tar.gz sonarqube-7d6e9e42e42a982bcb6648a2ef161293642b9415.zip |
SONAR-24053 Replace expression language usage by simple message interpolation for validation error messages.
Remove dependency on org.glassfish.expressly:expressly.
Diffstat (limited to 'server/sonar-webserver-webapi-v2')
3 files changed, 17 insertions, 5 deletions
diff --git a/server/sonar-webserver-webapi-v2/build.gradle b/server/sonar-webserver-webapi-v2/build.gradle index 7e75b599c05..fb7b4af92e1 100644 --- a/server/sonar-webserver-webapi-v2/build.gradle +++ b/server/sonar-webserver-webapi-v2/build.gradle @@ -9,8 +9,6 @@ dependencies { api 'org.springdoc:springdoc-openapi-starter-webmvc-api' api 'org.springframework:spring-webmvc' api 'org.hibernate.validator:hibernate-validator' - api 'jakarta.el:jakarta.el-api' - api 'org.glassfish.expressly:expressly' api project(':server:sonar-db-dao') api project(':server:sonar-webserver-common') diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/config/CommonWebConfig.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/config/CommonWebConfig.java index 273d665e93f..84891c8f97d 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/config/CommonWebConfig.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/config/CommonWebConfig.java @@ -21,6 +21,9 @@ package org.sonar.server.v2.config; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; +import jakarta.validation.Validation; +import jakarta.validation.ValidatorFactory; +import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator; import org.sonar.server.v2.common.RestResponseEntityExceptionHandler; import org.springdoc.core.properties.SpringDocConfigProperties; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; @@ -29,7 +32,6 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.http.MediaType; -import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -49,8 +51,11 @@ public class CommonWebConfig implements WebMvcConfigurer { } @Bean - public LocalValidatorFactoryBean validator() { - return new LocalValidatorFactoryBean(); + public ValidatorFactory validator() { + return Validation.byDefaultProvider() + .configure() + .messageInterpolator(new ParameterMessageInterpolator()) + .buildValidatorFactory(); } @Bean diff --git a/server/sonar-webserver-webapi-v2/src/testFixtures/java/org/sonar/server/v2/api/ControllerTester.java b/server/sonar-webserver-webapi-v2/src/testFixtures/java/org/sonar/server/v2/api/ControllerTester.java index 8a63eaaedc7..edd3bae6e16 100644 --- a/server/sonar-webserver-webapi-v2/src/testFixtures/java/org/sonar/server/v2/api/ControllerTester.java +++ b/server/sonar-webserver-webapi-v2/src/testFixtures/java/org/sonar/server/v2/api/ControllerTester.java @@ -19,10 +19,14 @@ */ package org.sonar.server.v2.api; +import jakarta.validation.Validation; +import jakarta.validation.ValidatorFactory; import java.util.List; +import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator; import org.sonar.server.v2.common.RestResponseEntityExceptionHandler; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.validation.beanvalidation.SpringValidatorAdapter; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; @@ -32,8 +36,13 @@ public class ControllerTester { } public static MockMvc getMockMvcWithHandlerInterceptors(List<HandlerInterceptor> handlerInterceptors, Object... controllers) { + ValidatorFactory validatorFactory = Validation.byDefaultProvider() + .configure() + .messageInterpolator(new ParameterMessageInterpolator()) + .buildValidatorFactory(); return MockMvcBuilders .standaloneSetup(controllers) + .setValidator(new SpringValidatorAdapter(validatorFactory.getValidator())) .setCustomHandlerMapping(() -> resolveRequestMappingHandlerMapping(handlerInterceptors)) .setControllerAdvice(new RestResponseEntityExceptionHandler()) .setUseTrailingSlashPatternMatch(true) |