Skip to content

Commit

Permalink
STTRS-1135 spring 3.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenRover committed Jun 1, 2023
1 parent 6f94140 commit d59352b
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 83 deletions.
20 changes: 6 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.11</version>
<version>3.1.0</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<groupId>ch.sbb.tms.platform</groupId>
<artifactId>spring-boot-starter-request-reply</artifactId>
<version>3.5.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
<name>spring-boot-starter-request-reply</name>
<description>Spring Boot Starter project to provide request and reply functionality to Spring Cloud Stream
projects
</description>

<properties>
<java.version>17</java.version>
<solace-spring-cloud.version>2.5.0</solace-spring-cloud.version>
<spring-cloud.version>2021.0.6</spring-cloud.version>
<solace-spring-cloud.version>3.0.0</solace-spring-cloud.version>
<spring-cloud.version>2022.0.3</spring-cloud.version>
<commons-logging.version>1.2</commons-logging.version>

<sonar.projectKey>${project.groupId}:${project.artifactId}</sonar.projectKey>
<sonar.projectName>${project.groupId}:${project.artifactId}</sonar.projectName>
<!--suppress UnresolvedMavenProperty -->
<sonar.branch.name>${env.GIT_BRANCH}</sonar.branch.name>
<sonar.java.source>${java.version}</sonar.java.source>
<jacoco-maven-plugin.version>0.8.9</jacoco-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.10</jacoco-maven-plugin.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -148,16 +148,8 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
<type>test-jar</type>
<artifactId>spring-cloud-stream-test-binder</artifactId>
<scope>test</scope>
<classifier>test-binder</classifier>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-context</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {
Expand All @@ -31,7 +23,7 @@ public int getOrder() {

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
ReplyTopicWithWildcardsPropertySource.addToEnvironment(environment, this.logger);
ReplyTopicWithWildcardsPropertySource.addToEnvironment(environment);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
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;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment;

public class ReplyTopicWithWildcardsPropertySource extends PropertySource<ReplyTopicWithWildcards> {

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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<GenericApplicationContext> {
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<RequestReplyProperties> bindResult = Binder.get(context.getEnvironment())
.bind("spring.cloud.stream.requestreply",
RequestReplyProperties.class);
@Override
public void initialize(final GenericApplicationContext context) {
final BindResult<RequestReplyProperties> 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<Consumer<Message<?>>>(
((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<Consumer<Message<?>>>(
((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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d59352b

Please sign in to comment.