diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 2c3521197d..a4b76b9530 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 68e8816d71..8e876e1c55 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab -distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +distributionSha256Sum=1541fa36599e12857140465f3c91a97409b4512501c26f9631fb113e392c5bd1 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java index 64d0441343..4a708885ee 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java @@ -114,6 +114,7 @@ public class AmqpInboundGateway extends MessagingGatewaySupport { private AmqpInboundGateway(MessageListenerContainer listenerContainer, AmqpTemplate amqpTemplate, boolean amqpTemplateExplicitlySet) { + Assert.notNull(listenerContainer, "listenerContainer must not be null"); Assert.notNull(amqpTemplate, "'amqpTemplate' must not be null"); Assert.isNull(listenerContainer.getMessageListener(), @@ -194,7 +195,7 @@ public class AmqpInboundGateway extends MessagingGatewaySupport { * @since 4.3.10 * @see #setRetryTemplate(RetryTemplate) */ - public void setRecoveryCallback(RecoveryCallback recoveryCallback) { + public void setRecoveryCallback(RecoveryCallback recoveryCallback) { this.recoveryCallback = recoveryCallback; } @@ -341,6 +342,9 @@ public class AmqpInboundGateway extends MessagingGatewaySupport { protected class Listener implements ChannelAwareMessageListener { + protected Listener() { + } + @SuppressWarnings("unchecked") @Override public void onMessage(final Message message, final Channel channel) { diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/ManualAckListenerExecutionFailedException.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/ManualAckListenerExecutionFailedException.java index bd1b387cae..61246fc05e 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/ManualAckListenerExecutionFailedException.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/ManualAckListenerExecutionFailedException.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 the original author or authors. + * Copyright 2019-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ public class ManualAckListenerExecutionFailedException extends ListenerExecution @Serial private static final long serialVersionUID = 1L; - private final Channel channel; + private final transient Channel channel; private final long deliveryTag; diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/NackedAmqpMessageException.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/NackedAmqpMessageException.java index 301b63d80d..2532003f04 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/NackedAmqpMessageException.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/NackedAmqpMessageException.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019 the original author or authors. + * Copyright 2017-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,8 @@ import org.springframework.messaging.MessagingException; * publisher confirm. * * @author Gary Russell + * @author Artem Bilan + * * @since 4.3.12 * */ @@ -32,10 +34,11 @@ public class NackedAmqpMessageException extends MessagingException { private static final long serialVersionUID = 1L; - private final Object correlationData; - private final String nackReason; + @SuppressWarnings("serial") + private final Object correlationData; + public NackedAmqpMessageException(Message message, @Nullable Object correlationData, String nackReason) { super(message); this.correlationData = correlationData; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupExpiredEvent.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupExpiredEvent.java index 42e7b51e52..3f45f864fd 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupExpiredEvent.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupExpiredEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ public class MessageGroupExpiredEvent extends IntegrationEvent { private static final long serialVersionUID = -7126221042599333919L; + @SuppressWarnings("serial") private final Object groupId; private final int messageCount; @@ -44,6 +45,7 @@ public class MessageGroupExpiredEvent extends IntegrationEvent { public MessageGroupExpiredEvent(Object source, Object groupId, int messageCount, Date lastModified, Date expired, boolean discarded) { + super(source); this.groupId = groupId; this.messageCount = messageCount; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java index 251d9af4be..d953e09691 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java @@ -45,7 +45,7 @@ public class EventDrivenConsumer extends AbstractEndpoint implements Integration Assert.notNull(handler, "handler must not be null"); this.inputChannel = inputChannel; this.handler = handler; - this.setPhase(Integer.MIN_VALUE); + setPhase(Integer.MIN_VALUE); } @Override @@ -55,11 +55,11 @@ public class EventDrivenConsumer extends AbstractEndpoint implements Integration @Override public MessageChannel getOutputChannel() { - if (this.handler instanceof MessageProducer) { - return ((MessageProducer) this.handler).getOutputChannel(); + if (this.handler instanceof MessageProducer messageProducer) { + return messageProducer.getOutputChannel(); } - else if (this.handler instanceof MessageRouter) { - return ((MessageRouter) this.handler).getDefaultOutputChannel(); + else if (this.handler instanceof MessageRouter messageRouter) { + return messageRouter.getDefaultOutputChannel(); } else { return null; @@ -75,8 +75,8 @@ public class EventDrivenConsumer extends AbstractEndpoint implements Integration protected void doStart() { this.logComponentSubscriptionEvent(true); this.inputChannel.subscribe(this.handler); - if (this.handler instanceof Lifecycle) { - ((Lifecycle) this.handler).start(); + if (this.handler instanceof Lifecycle lifecycle) { + lifecycle.start(); } } @@ -84,15 +84,16 @@ public class EventDrivenConsumer extends AbstractEndpoint implements Integration protected void doStop() { this.logComponentSubscriptionEvent(false); this.inputChannel.unsubscribe(this.handler); - if (this.handler instanceof Lifecycle) { - ((Lifecycle) this.handler).stop(); + if (this.handler instanceof Lifecycle lifecycle) { + lifecycle.stop(); } } private void logComponentSubscriptionEvent(boolean add) { - if (this.handler instanceof NamedComponent && this.inputChannel instanceof NamedComponent) { - String channelName = ((NamedComponent) this.inputChannel).getComponentName(); - String componentType = ((NamedComponent) this.handler).getComponentType(); + if (this.handler instanceof NamedComponent namedHandler + && this.inputChannel instanceof NamedComponent namedChannel) { + + String componentType = namedHandler.getComponentType(); componentType = StringUtils.hasText(componentType) ? componentType : ""; String componentName = getComponentName(); componentName = @@ -102,7 +103,7 @@ public class EventDrivenConsumer extends AbstractEndpoint implements Integration .append(componentType) .append(componentName) .append("} as a subscriber to the '") - .append(channelName) + .append(namedChannel.getComponentName()) .append("' channel"); if (add) { buffer.insert(0, "Adding "); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java index b2022b552f..ffed5aafc8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java @@ -81,7 +81,7 @@ public abstract class MessageProducerSupport extends AbstractEndpoint private volatile Subscription subscription; protected MessageProducerSupport() { - this.setPhase(Integer.MAX_VALUE / 2); + setPhase(Integer.MAX_VALUE / 2); } @Override @@ -222,7 +222,6 @@ public abstract class MessageProducerSupport extends AbstractEndpoint if (beanFactory != null) { this.messagingTemplate.setBeanFactory(beanFactory); } - } /** @@ -278,8 +277,8 @@ public abstract class MessageProducerSupport extends AbstractEndpoint .doOnCancel(this::stop) .doOnSubscribe((subs) -> this.subscription = subs); - if (channelForSubscription instanceof ReactiveStreamsSubscribableChannel) { - ((ReactiveStreamsSubscribableChannel) channelForSubscription).subscribeTo(messageFlux); + if (channelForSubscription instanceof ReactiveStreamsSubscribableChannel reactiveStreamsSubscribableChannel) { + reactiveStreamsSubscribableChannel.subscribeTo(messageFlux); } else { messageFlux diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java index 42725cf30d..59e7bc9389 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java @@ -686,6 +686,7 @@ public class DelayHandler extends AbstractReplyProducingMessageHandler implement private final long requestDate; + @SuppressWarnings("serial") private final Message original; DelayedMessageWrapper(Message original, long requestDate) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/CacheRequestHandlerAdvice.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/CacheRequestHandlerAdvice.java index 8bb6632468..efcf6313ee 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/CacheRequestHandlerAdvice.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/CacheRequestHandlerAdvice.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; +import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.cache.CacheManager; import org.springframework.cache.interceptor.CacheAspectSupport; @@ -49,7 +50,7 @@ import org.springframework.util.ReflectionUtils; * The {@link AbstractRequestHandlerAdvice} implementation for caching * {@code AbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message)} results. * Supports all the cache operations - cacheable, put, evict. - * By default only cacheable is applied for the provided {@code cacheNames}. + * By default, only cacheable is applied for the provided {@code cacheNames}. * The default cache {@code key} is {@code payload} of the request message. * * @author Artem Bilan @@ -103,9 +104,6 @@ public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice */ public CacheRequestHandlerAdvice(String... cacheNamesArg) { this.cacheNames = cacheNamesArg != null ? Arrays.copyOf(cacheNamesArg, cacheNamesArg.length) : null; - CacheableOperation.Builder builder = new CacheableOperation.Builder(); - builder.setName(toString()); - this.cacheOperations.add(builder.build()); } /** @@ -192,6 +190,11 @@ public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice @Override protected void onInit() { + if (this.cacheOperations.isEmpty()) { + CacheableOperation.Builder builder = new CacheableOperation.Builder(); + builder.setName(toString()); + this.cacheOperations.add(builder.build()); + } List cacheOperationsToUse; if (!ObjectUtils.isEmpty(this.cacheNames)) { cacheOperationsToUse = @@ -232,14 +235,15 @@ public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice builder.setKeyGenerator(operation.getKeyGenerator()); return builder.build(); }) - .collect(Collectors.toList()); + .toList(); } else { cacheOperationsToUse = this.cacheOperations; } - this.delegate.setBeanFactory(getBeanFactory()); - EvaluationContext evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); + BeanFactory beanFactory = getBeanFactory(); + this.delegate.setBeanFactory(beanFactory); + EvaluationContext evaluationContext = ExpressionUtils.createStandardEvaluationContext(beanFactory); this.delegate.setKeyGenerator((target, method, params) -> this.keyExpression.getValue(evaluationContext, params[0])); // NOSONAR this.delegate.setCacheOperationSources((method, targetClass) -> cacheOperationsToUse); @@ -260,7 +264,6 @@ public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice else { return result; } - }; return this.delegate.invoke(operationInvoker, target, message); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdvice.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdvice.java index e5582a2c16..2f1f0b3a57 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdvice.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdvice.java @@ -309,7 +309,7 @@ public class ExpressionEvaluatingRequestHandlerAdvice extends AbstractRequestHan private static final long serialVersionUID = 1L; - private final Object evaluationResult; + private final transient Object evaluationResult; public MessageHandlingExpressionEvaluatingAdviceException(Message message, String description, Throwable cause, Object evaluationResult) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java index 0814e3af67..b32a81c2e3 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java @@ -73,6 +73,7 @@ public final class MessageHistory implements List, Serializable, Clo private static final MessageBuilderFactory MESSAGE_BUILDER_FACTORY = new DefaultMessageBuilderFactory(); + @SuppressWarnings("serial") private final List components; @Nullable diff --git a/spring-integration-core/src/main/java/org/springframework/integration/message/AdviceMessage.java b/spring-integration-core/src/main/java/org/springframework/integration/message/AdviceMessage.java index a6a742cb15..2f76b55814 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/message/AdviceMessage.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/message/AdviceMessage.java @@ -41,6 +41,7 @@ public class AdviceMessage extends GenericMessage { private static final long serialVersionUID = 1L; + @SuppressWarnings("serial") private final Message inputMessage; public AdviceMessage(T payload, Message inputMessage) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java index c3bc15f860..8dc193fb37 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java @@ -67,7 +67,7 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess * Set the applySequence flag to the specified value. Defaults to true. * @param applySequence true to apply sequence information. */ - public void setApplySequence(boolean applySequence) { + public final void setApplySequence(boolean applySequence) { this.applySequence = applySequence; } @@ -143,8 +143,7 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess private Flux prepareFluxResult(Message message, Object result) { int sequenceSize = 1; Flux flux = Flux.just(result); - if (result instanceof Iterable) { - Iterable iterable = (Iterable) result; + if (result instanceof Iterable iterable) { sequenceSize = obtainSizeIfPossible(iterable); flux = Flux.fromIterable(iterable); } @@ -153,18 +152,15 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess sequenceSize = items.length; flux = Flux.fromArray(items); } - else if (result instanceof Iterator) { - Iterator iter = (Iterator) result; - sequenceSize = obtainSizeIfPossible(iter); - flux = Flux.fromIterable(() -> iter); + else if (result instanceof Iterator iterator) { + sequenceSize = obtainSizeIfPossible(iterator); + flux = Flux.fromIterable(() -> iterator); } - else if (result instanceof Stream) { - Stream stream = ((Stream) result); + else if (result instanceof Stream stream) { sequenceSize = 0; flux = Flux.fromStream(stream); } - else if (result instanceof Publisher) { - Publisher publisher = (Publisher) result; + else if (result instanceof Publisher publisher) { sequenceSize = 0; flux = Flux.from(publisher); } @@ -188,8 +184,7 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess int sequenceSize = 1; Iterator iterator = Collections.singleton(result).iterator(); - if (result instanceof Iterable) { - Iterable iterable = (Iterable) result; + if (result instanceof Iterable iterable) { sequenceSize = obtainSizeIfPossible(iterable); iterator = iterable.iterator(); } @@ -198,19 +193,17 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess sequenceSize = items.length; iterator = Arrays.asList(items).iterator(); } - else if (result instanceof Iterator) { - Iterator iter = (Iterator) result; + else if (result instanceof Iterator iter) { sequenceSize = obtainSizeIfPossible(iter); iterator = iter; } - else if (result instanceof Stream) { - Stream stream = ((Stream) result); + else if (result instanceof Stream stream) { sequenceSize = 0; iterator = stream.iterator(); } - else if (result instanceof Publisher) { + else if (result instanceof Publisher publisher) { sequenceSize = 0; - iterator = Flux.from((Publisher) result).toIterable().iterator(); + iterator = Flux.from(publisher).toIterable().iterator(); } if (!iterator.hasNext()) { @@ -251,8 +244,8 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess * @since 5.0 */ protected int obtainSizeIfPossible(Iterable iterable) { - if (iterable instanceof Collection) { - return ((Collection) iterable).size(); + if (iterable instanceof Collection collection) { + return collection.size(); } else if (JacksonPresent.isJackson2Present() && JacksonNodeHelper.isNode(iterable)) { return JacksonNodeHelper.nodeSize(iterable); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java index b3f07e944f..6fcda7d1d9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java @@ -41,6 +41,7 @@ public class MessageGroupMetadata implements Serializable { private static final long serialVersionUID = 1L; + @SuppressWarnings("serial") private final List messageIds = new LinkedList<>(); private long timestamp; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageHolder.java b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageHolder.java index 088e99fb10..0c5770e4be 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageHolder.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ public class MessageHolder implements Serializable { private static final long serialVersionUID = 1L; + @SuppressWarnings("serial") private Message message; private MessageMetadata messageMetadata; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessage.java b/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessage.java index c54ad22a97..b53ad2ec99 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessage.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 the original author or authors. + * Copyright 2014-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,6 +56,7 @@ public class MutableMessage implements Message, Serializable { private static final long serialVersionUID = -636635024258737500L; + @SuppressWarnings("serial") private final T payload; private final MutableMessageHeaders headers; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/PartialSuccessException.java b/spring-integration-core/src/main/java/org/springframework/integration/support/PartialSuccessException.java index a7649420ea..7e939ed6fb 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/PartialSuccessException.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/PartialSuccessException.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2021 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,8 @@ import org.springframework.util.Assert; * performing multiple updates from a single message, e.g. an FTP 'mput' operation. * * @author Gary Russell + * @author Artem Bilan + * * @since 4.2 * */ @@ -34,9 +36,9 @@ public class PartialSuccessException extends MessagingException { private static final long serialVersionUID = 8810900575763284993L; - private final Collection partialResults; + private final transient Collection partialResults; - private final Collection derivedInput; + private final transient Collection derivedInput; /** * diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/MaxValueReleaseStrategy.java b/spring-integration-core/src/test/java/org/springframework/integration/config/MaxValueReleaseStrategy.java index c2d5f82725..e718fe93fe 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/MaxValueReleaseStrategy.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/MaxValueReleaseStrategy.java @@ -19,28 +19,33 @@ package org.springframework.integration.config; import java.util.Collection; import java.util.List; +/** + * @author Marius Bogoevici + * @author Dave Syer + * @author Artem Bilan + */ public class MaxValueReleaseStrategy { - private long maxValue; + private final long maxValue; public MaxValueReleaseStrategy(long maxValue) { this.maxValue = maxValue; } public boolean checkCompletenessAsList(List numbers) { - int sum = 0; + long sum = 0; for (long number : numbers) { sum += number; } - return sum >= maxValue; + return sum >= this.maxValue; } public boolean checkCompletenessAsCollection(Collection numbers) { - int sum = 0; + long sum = 0; for (long number : numbers) { sum += number; } - return sum >= maxValue; + return sum >= this.maxValue; } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ChainElementsFailureTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ChainElementsFailureTests.java index 474ee88754..403e3dd1fd 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ChainElementsFailureTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ChainElementsFailureTests.java @@ -20,21 +20,21 @@ import java.io.ByteArrayInputStream; import java.util.Locale; import java.util.Properties; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.InputStreamResource; +import org.springframework.core.io.support.PropertiesLoaderUtils; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Oleg Zhurakousky @@ -46,240 +46,73 @@ public class ChainElementsFailureTests { private Locale localeBeforeTest; - @Before + @BeforeEach public void setUp() { localeBeforeTest = Locale.getDefault(); - Locale.setDefault(new Locale("en", "US")); + Locale.setDefault(Locale.forLanguageTag("en-US")); } - @After + @AfterEach public void tearDown() { Locale.setDefault(localeBeforeTest); } - @Test - public void chainServiceActivator() throws Exception { - - try { - this.bootStrap("service-activator"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " + - "not" + - " allowed to appear in element 'int:service-activator'."); - } - + @ParameterizedTest + @ValueSource(strings = { + "service-activator", + "aggregator", + "chain", + "delayer", + "filter", + "gateway", + "header-enricher", + "header-filter", + "header-filter", + "header-value-router", + "transformer", + "router", + "splitter", + "resequencer", + }) + void inputChannelNotAllowed(String element) { + assertThatExceptionOfType(XmlBeanDefinitionStoreException.class) + .isThrownBy(() -> bootStrap(element)) + .withStackTraceContaining( + "cvc-complex-type.3.2.2: Attribute 'input-channel' is not" + + " allowed to appear in element 'int:" + element + "'."); } @Test - public void chainAggregator() throws Exception { - - try { - this.bootStrap("aggregator"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " + - "not" + - " allowed to appear in element 'int:aggregator'."); - } - - } - - @Test - public void chainChain() throws Exception { - - try { - this.bootStrap("chain"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " + - "not" + - " allowed to appear in element 'int:chain'."); - } - } - - @Test - public void chainDelayer() throws Exception { - - try { - this.bootStrap("delayer"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " + - "not" + - " allowed to appear in element 'int:delayer'."); - } - } - - @Test - public void chainFilter() throws Exception { - - try { - this.bootStrap("filter"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " + - "not" + - " allowed to appear in element 'int:filter'."); - } - } - - @Test - public void chainGateway() throws Exception { - - try { - this.bootStrap("gateway"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " + - "not" + - " allowed to appear in element 'int:gateway'."); - } - } - - @Test - public void chainHeaderEnricher() throws Exception { - - try { - this.bootStrap("header-enricher"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" + - " allowed to appear in element 'int:header-enricher'."); - } - } - - @Test - public void chainHeaderFilter() throws Exception { - - try { - this.bootStrap("header-filter"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" + - " allowed to appear in element 'int:header-filter'."); - } - } - - @Test - public void chainHeaderValueRouter() throws Exception { - - try { - this.bootStrap("header-value-router"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " + - "not" + - " allowed to appear in element 'int:header-value-router'."); - } - } - - @Test - public void chainTransformer() throws Exception { - - try { - this.bootStrap("transformer"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" + - " allowed to appear in element 'int:transformer'."); - } - } - - @Test - public void chainRouter() throws Exception { - - try { - this.bootStrap("router"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" + - " allowed to appear in element 'int:router'."); - } - } - - @Test - public void chainSplitter() throws Exception { - - try { - this.bootStrap("splitter"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" + - " allowed to appear in element 'int:splitter'."); - } - } - - @Test - public void chainResequencer() throws Exception { - - try { - this.bootStrap("resequencer"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (XmlBeanDefinitionStoreException e) { - assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" + - " allowed to appear in element 'int:resequencer'."); - } - } - - @Test - public void chainResequencerPoller() throws Exception { - - try { - this.bootStrap("resequencer-poller"); - fail("Expected a XmlBeanDefinitionStoreException to be thrown."); - } - catch (BeanDefinitionParsingException e) { - final String expectedMessage = "Configuration problem: " + - "'int:resequencer' must not define a 'poller' sub-element " + - "when used within a chain."; - final String actualMessage = e.getMessage(); - assertThat(actualMessage.startsWith(expectedMessage)) - .as("Error message did not start with '" + expectedMessage + - "' but instead returned: '" + actualMessage + "'").isTrue(); - } + public void chainResequencerPoller() { + assertThatExceptionOfType(BeanDefinitionParsingException.class) + .isThrownBy(() -> bootStrap("resequencer-poller")) + .withMessageStartingWith("Configuration problem: " + + "'int:resequencer' must not define a 'poller' sub-element " + + "when used within a chain."); } @Test public void testInt2755DetectDuplicateHandlerId() throws Exception { - - try { - this.bootStrap("duplicate-handler-id"); - fail("Expected a BeanDefinitionParsingException to be thrown."); - } - catch (BeanDefinitionParsingException e) { - assertThat(e.getMessage().contains("A bean definition is already registered for " + - "beanName: 'foo$child.bar.handler' within the current .")).isTrue(); - } + assertThatExceptionOfType(BeanDefinitionParsingException.class) + .isThrownBy(() -> bootStrap("duplicate-handler-id")) + .withMessageContaining("A bean definition is already registered for " + + "beanName: 'foo$child.bar.handler' within the current ."); } - private ApplicationContext bootStrap(String configProperty) throws Exception { - PropertiesFactoryBean pfb = new PropertiesFactoryBean(); - pfb.setLocation(new ClassPathResource("org/springframework/integration/config/xml/chain-elements-config.properties")); - pfb.afterPropertiesSet(); - Properties prop = pfb.getObject(); - StringBuilder buffer = new StringBuilder(); - buffer.append(prop.getProperty("xmlheaders")).append(prop.getProperty(configProperty)).append(prop.getProperty("xmlfooter")); - ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toString().getBytes()); + private static void bootStrap(String configProperty) throws Exception { + Properties prop = + PropertiesLoaderUtils.loadProperties( + new ClassPathResource( + "org/springframework/integration/config/xml/chain-elements-config.properties")); + ByteArrayInputStream stream = + new ByteArrayInputStream((prop.getProperty("xmlheaders") + + prop.getProperty(configProperty) + + prop.getProperty("xmlfooter")).getBytes()); GenericApplicationContext ac = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new InputStreamResource(stream)); ac.refresh(); - return ac; } public static class SampleService { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollingEndpointStub.java b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollingEndpointStub.java index 3f91e4e07c..c4b00d9001 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollingEndpointStub.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollingEndpointStub.java @@ -30,8 +30,10 @@ import org.springframework.scheduling.support.PeriodicTrigger; */ public class PollingEndpointStub extends AbstractPollingEndpoint { - public PollingEndpointStub() { - this.setTrigger(new PeriodicTrigger(Duration.ofMillis(500))); + @Override + protected void onInit() { + super.onInit(); + setTrigger(new PeriodicTrigger(Duration.ofMillis(500))); } @Override diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/server/FtpRequestEvent.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/server/FtpRequestEvent.java index 69d7170d54..4c6c02231e 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/server/FtpRequestEvent.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/server/FtpRequestEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2019-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ public abstract class FtpRequestEvent extends ApacheMinaFtpEvent { private static final long serialVersionUID = 1L; - protected final FtpRequest request; //NOSONAR protected final + protected final transient FtpRequest request; //NOSONAR protected final public FtpRequestEvent(FtpSession source, FtpRequest request) { super(source); diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageSourceTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageSourceTests.java index 4bc8e15467..9197d2304a 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageSourceTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageSourceTests.java @@ -22,8 +22,7 @@ import javax.management.Attribute; import javax.management.MBeanServer; import javax.management.ObjectName; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -37,16 +36,18 @@ import org.springframework.integration.scheduling.PollerMetadata; import org.springframework.jmx.support.MBeanServerFactoryBean; import org.springframework.messaging.PollableChannel; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** * @author Gary Russell + * @author Artem Bilan + * * @since 5.0 * */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext public class MessageSourceTests { @@ -108,7 +109,9 @@ public class MessageSourceTests { public static class MaxFetchSource extends AbstractFetchLimitingMessageSource { - { + @Override + protected void onInit() { + super.onInit(); setMaxFetchSize(123); } diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java index 2c94c23ee1..2c8cc23f6f 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java @@ -59,9 +59,14 @@ public class PollableKafkaChannel extends AbstractKafkaChannel public PollableKafkaChannel(KafkaOperations template, KafkaMessageSource source) { super(template, topic(source)); this.source = source; - if (source.getConsumerProperties().getGroupId() == null) { + } + + @Override + protected void onInit() { + super.onInit(); + if (this.source.getConsumerProperties().getGroupId() == null) { String groupId = getGroupId(); - source.getConsumerProperties().setGroupId(groupId != null ? groupId : getBeanName()); + this.source.getConsumerProperties().setGroupId(groupId != null ? groupId : getBeanName()); } } diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/KafkaSendFailureException.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/KafkaSendFailureException.java index 0f223d1431..5ca48242ca 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/KafkaSendFailureException.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/KafkaSendFailureException.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019 the original author or authors. + * Copyright 2017-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import org.springframework.messaging.MessagingException; * An exception that is the payload of an {@code ErrorMessage} when a send fails. * * @author Gary Russell + * @author Artem Bilan * * @since 5.4 * @@ -33,7 +34,7 @@ public class KafkaSendFailureException extends MessagingException { private static final long serialVersionUID = 1L; - private final ProducerRecord record; + private final transient ProducerRecord record; public KafkaSendFailureException(Message message, ProducerRecord record, Throwable cause) { super(message, cause);