From d59352bf7024dd82db6592a32f4c19618e93efe8 Mon Sep 17 00:00:00 2001 From: ue85540 Date: Thu, 1 Jun 2023 15:23:26 +0200 Subject: [PATCH] STTRS-1135 spring 3.0 support --- pom.xml | 20 ++-- ...ropertySourceEnvironmentPostProcessor.java | 14 +-- ...ReplyTopicWithWildcardsPropertySource.java | 5 +- .../RequestReplyAutoConfiguration.java | 100 +++++++++--------- .../service/RequestReplyService.java | 6 +- .../service/RequestReplyServiceImpl.java | 6 +- .../requestreply/AbstractRequestReplyIT.java | 1 + 7 files changed, 69 insertions(+), 83 deletions(-) diff --git a/pom.xml b/pom.xml index 6978c25..56e9f95 100644 --- a/pom.xml +++ b/pom.xml @@ -4,13 +4,13 @@ org.springframework.boot spring-boot-starter-parent - 2.7.11 + 3.1.0 ch.sbb.tms.platform spring-boot-starter-request-reply - 3.5.0-SNAPSHOT + 5.0.0-SNAPSHOT spring-boot-starter-request-reply Spring Boot Starter project to provide request and reply functionality to Spring Cloud Stream projects @@ -18,8 +18,8 @@ 17 - 2.5.0 - 2021.0.6 + 3.0.0 + 2022.0.3 1.2 ${project.groupId}:${project.artifactId} @@ -27,7 +27,7 @@ ${env.GIT_BRANCH} ${java.version} - 0.8.9 + 0.8.10 @@ -148,16 +148,8 @@ org.springframework.cloud - spring-cloud-stream - test-jar + spring-cloud-stream-test-binder test - test-binder - - - org.springframework.cloud - spring-cloud-function-context - - io.projectreactor diff --git a/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/env/ReplyTopicWithWildcardPropertySourceEnvironmentPostProcessor.java b/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/env/ReplyTopicWithWildcardPropertySourceEnvironmentPostProcessor.java index 371158e..6a3be60 100644 --- a/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/env/ReplyTopicWithWildcardPropertySourceEnvironmentPostProcessor.java +++ b/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/env/ReplyTopicWithWildcardPropertySourceEnvironmentPostProcessor.java @@ -1,6 +1,8 @@ package ch.sbb.tms.platform.springbootstarter.requestreply.env; import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.boot.SpringApplication; import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.core.Ordered; @@ -13,16 +15,6 @@ public class ReplyTopicWithWildcardPropertySourceEnvironmentPostProcessor implem */ public static final int ORDER = Ordered.HIGHEST_PRECEDENCE + 1; - private final Log logger; - - /** - * Create a new {@link ReplyTopicWithWildcardPropertySourceEnvironmentPostProcessor} instance. - * - * @param logger the logger to use - */ - public ReplyTopicWithWildcardPropertySourceEnvironmentPostProcessor(Log logger) { - this.logger = logger; - } @Override public int getOrder() { @@ -31,7 +23,7 @@ public int getOrder() { @Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { - ReplyTopicWithWildcardsPropertySource.addToEnvironment(environment, this.logger); + ReplyTopicWithWildcardsPropertySource.addToEnvironment(environment); } } diff --git a/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/env/ReplyTopicWithWildcardsPropertySource.java b/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/env/ReplyTopicWithWildcardsPropertySource.java index 5ad1e9e..c4b03f8 100644 --- a/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/env/ReplyTopicWithWildcardsPropertySource.java +++ b/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/env/ReplyTopicWithWildcardsPropertySource.java @@ -5,6 +5,7 @@ import java.util.regex.Pattern; import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MutablePropertySources; @@ -12,6 +13,8 @@ import org.springframework.core.env.StandardEnvironment; public class ReplyTopicWithWildcardsPropertySource extends PropertySource { + + private static final Log logger = LogFactory.getLog(ReplyTopicWithWildcardsPropertySource.class); public static final String PROPERTY_SOURCE_NAME = "replyTopicWithWildcards"; public static final int ACTION_INDEX = 1; public static final int BINDING_NAME_INDEX = 1; @@ -27,7 +30,7 @@ public ReplyTopicWithWildcardsPropertySource(String name, ConfigurableEnvironmen this.uuid = UUID.randomUUID().toString(); } - static void addToEnvironment(ConfigurableEnvironment environment, Log logger) { + static void addToEnvironment(ConfigurableEnvironment environment) { MutablePropertySources sources = environment.getPropertySources(); PropertySource existing = sources.get(PROPERTY_SOURCE_NAME); if (existing != null) { diff --git a/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyAutoConfiguration.java b/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyAutoConfiguration.java index a193d14..1c79e65 100644 --- a/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyAutoConfiguration.java +++ b/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyAutoConfiguration.java @@ -19,7 +19,6 @@ import org.springframework.boot.context.properties.bind.BindResult; import org.springframework.boot.context.properties.bind.Binder; import org.springframework.cloud.function.context.FunctionRegistration; -import org.springframework.cloud.function.context.FunctionType; import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration; import org.springframework.cloud.stream.config.BinderFactoryAutoConfiguration; import org.springframework.cloud.stream.function.FunctionConfiguration; @@ -38,67 +37,66 @@ @ConditionalOnClass({MessageChannel.class}) @ComponentScan("ch.sbb.tms.platform.springbootstarter.requestreply.service") @AutoConfigureAfter({ - ContextFunctionCatalogAutoConfiguration.class, - PropertySourcesPlaceholderConfigurer.class, - BinderFactoryAutoConfiguration.class + ContextFunctionCatalogAutoConfiguration.class, + PropertySourcesPlaceholderConfigurer.class, + BinderFactoryAutoConfiguration.class }) @AutoConfigureBefore({ - FunctionConfiguration.class + FunctionConfiguration.class }) @Order() @EnableConfigurationProperties(RequestReplyProperties.class) public class RequestReplyAutoConfiguration implements ApplicationContextInitializer { - private static final int SOLACE_CONFIGURERS_PRIORITY = 200; + private static final int SOLACE_CONFIGURERS_PRIORITY = 200; - private static final Logger LOG = LoggerFactory.getLogger(RequestReplyAutoConfiguration.class); + private static final Logger LOG = LoggerFactory.getLogger(RequestReplyAutoConfiguration.class); - @Bean - @Order(SOLACE_CONFIGURERS_PRIORITY) - @ConditionalOnMissingBean - @ConditionalOnClass(name = { - "com.solace.spring.cloud.stream.binder.messaging.SolaceHeaders", - "com.solacesystems.jcsmp.Destination" - }) - public SolaceHeaderParser solaceHeaderParser() { - return new SolaceHeaderParser(); - } + @Bean + @Order(SOLACE_CONFIGURERS_PRIORITY) + @ConditionalOnMissingBean + @ConditionalOnClass(name = { + "com.solace.spring.cloud.stream.binder.messaging.SolaceHeaders", + "com.solacesystems.jcsmp.Destination" + }) + public SolaceHeaderParser solaceHeaderParser() { + return new SolaceHeaderParser(); + } - @Bean - @ConditionalOnMissingBean - public RequestReplyServiceImpl requestReplyService() { - return new RequestReplyServiceImpl(); - } + @Bean + @ConditionalOnMissingBean + public RequestReplyServiceImpl requestReplyService() { + return new RequestReplyServiceImpl(); + } - @Override - public void initialize(final GenericApplicationContext context) { - final BindResult bindResult = Binder.get(context.getEnvironment()) - .bind("spring.cloud.stream.requestreply", - RequestReplyProperties.class); + @Override + public void initialize(final GenericApplicationContext context) { + final BindResult bindResult = Binder.get(context.getEnvironment()) + .bind("spring.cloud.stream.requestreply", + RequestReplyProperties.class); - if (!bindResult.isBound()) { - return; - } + if (!bindResult.isBound()) { + return; + } - final RequestReplyProperties requestReplyProperties = bindResult.get(); + final RequestReplyProperties requestReplyProperties = bindResult.get(); - for (final String bindingName : requestReplyProperties.getBindingMappingNames()) { - context.registerBean( - bindingName, - FunctionRegistration.class, - () -> new FunctionRegistration>>( - ((RequestReplyServiceImpl) context.getBean("requestReplyServiceImpl"))::onReplyReceived - ) - .type(new FunctionType( - ResolvableType.forClassWithGenerics( - Consumer.class, - ResolvableType.forClassWithGenerics( - Message.class, - Object.class - ) - ).getType() - )) - ); - LOG.info("Register binding: " + bindingName + " for receiving replies"); - } - } + for (final String bindingName : requestReplyProperties.getBindingMappingNames()) { + context.registerBean( + bindingName, + FunctionRegistration.class, + () -> new FunctionRegistration>>( + ((RequestReplyServiceImpl) context.getBean("requestReplyServiceImpl"))::onReplyReceived + ) + .type(ResolvableType.forClassWithGenerics( + Consumer.class, + ResolvableType.forClassWithGenerics( + Message.class, + Object.class + ) + ).getType() + ) + ); + LOG.info("Register binding: " + bindingName + " for receiving replies"); + } + } } \ No newline at end of file diff --git a/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyService.java b/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyService.java index 6ac6afe..7a93da0 100644 --- a/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyService.java +++ b/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyService.java @@ -4,9 +4,9 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeoutException; -import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import ch.sbb.tms.platform.springbootstarter.requestreply.service.header.parser.errormessage.RemoteErrorException; import reactor.core.publisher.Flux; diff --git a/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyServiceImpl.java b/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyServiceImpl.java index cb69a49..c016403 100644 --- a/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyServiceImpl.java +++ b/src/main/java/ch/sbb/tms/platform/springbootstarter/requestreply/service/RequestReplyServiceImpl.java @@ -17,9 +17,9 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; -import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import ch.sbb.tms.platform.springbootstarter.requestreply.config.RequestReplyProperties; import ch.sbb.tms.platform.springbootstarter.requestreply.exception.RequestReplyException; diff --git a/src/test/java/ch/sbb/tms/platform/springbootstarter/requestreply/AbstractRequestReplyIT.java b/src/test/java/ch/sbb/tms/platform/springbootstarter/requestreply/AbstractRequestReplyIT.java index cc36883..ca83766 100644 --- a/src/test/java/ch/sbb/tms/platform/springbootstarter/requestreply/AbstractRequestReplyIT.java +++ b/src/test/java/ch/sbb/tms/platform/springbootstarter/requestreply/AbstractRequestReplyIT.java @@ -26,6 +26,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.junit4.SpringRunner; import static ch.sbb.tms.platform.springbootstarter.requestreply.AbstractRequestReplyIT.PROFILE_LOCAL_APP; import static ch.sbb.tms.platform.springbootstarter.requestreply.AbstractRequestReplyIT.PROFILE_TEST;