diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpOutboundChannelAdapterSpec.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpOutboundChannelAdapterSpec.java index 7107f0a389..061bdeafe4 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpOutboundChannelAdapterSpec.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpOutboundChannelAdapterSpec.java @@ -17,12 +17,13 @@ package org.springframework.integration.amqp.dsl; import org.springframework.amqp.core.AmqpTemplate; -import org.springframework.messaging.Message; /** * Spec for an outbound AMQP channel adapter * * @author Gary Russell + * @author Artme Bilan + * * @since 5.3 * */ @@ -33,8 +34,8 @@ public class AmqpOutboundChannelAdapterSpec extends AmqpOutboundEndpointSpec adviceChain) { @@ -193,19 +198,16 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement return; } Assert.notNull(this.trigger, "Trigger is required"); - if (this.taskExecutor != null) { - if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor)) { - if (this.errorHandler == null) { - this.errorHandler = ChannelUtils.getErrorHandler(getBeanFactory()); - this.errorHandlerIsDefault = true; - } - this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, this.errorHandler); + if (this.taskExecutor != null && !(this.taskExecutor instanceof ErrorHandlingTaskExecutor)) { + if (this.errorHandler == null) { + this.errorHandler = ChannelUtils.getErrorHandler(getBeanFactory()); + this.errorHandlerIsDefault = true; } + this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, this.errorHandler); } - if (this.transactionSynchronizationFactory == null && this.adviceChain != null) { - if (this.adviceChain.stream().anyMatch(TransactionInterceptor.class::isInstance)) { - this.transactionSynchronizationFactory = new PassThroughTransactionSynchronizationFactory(); - } + if (this.transactionSynchronizationFactory == null && this.adviceChain != null && + this.adviceChain.stream().anyMatch(TransactionInterceptor.class::isInstance)) { + this.transactionSynchronizationFactory = new PassThroughTransactionSynchronizationFactory(); } this.initialized = true; } @@ -328,7 +330,7 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement return this.pollingTask.call(); } catch (Exception e) { - if (e instanceof MessagingException) { + if (e instanceof MessagingException) { // NOSONAR throw (MessagingException) e; } else { @@ -395,13 +397,11 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement try { handleMessage(message); } - catch (Exception e) { - if (e instanceof MessagingException) { - throw new MessagingExceptionWrapper(message, (MessagingException) e); - } - else { - throw new MessagingException(message, e); - } + catch (MessagingException ex) { + throw new MessagingExceptionWrapper(message, ex); + } + catch (Exception ex) { + throw new MessagingException(message, ex); } } } 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 92772ed77a..6ae85adcdd 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Properties; +import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -35,22 +36,23 @@ import org.springframework.integration.support.MessageBuilderFactory; import org.springframework.integration.support.MutableMessage; import org.springframework.integration.support.MutableMessageBuilderFactory; import org.springframework.integration.support.context.NamedComponent; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.support.ErrorMessage; import org.springframework.messaging.support.GenericMessage; import org.springframework.util.Assert; -import org.springframework.util.StringUtils; /** * @author Mark Fisher * @author Artem Bilan * @author Gary Russell + * * @since 2.0 */ @SuppressWarnings("serial") public final class MessageHistory implements List, Serializable { - private static final Log logger = LogFactory.getLog(MessageHistory.class); + private static final Log LOGGER = LogFactory.getLog(MessageHistory.class); private static final UnsupportedOperationException UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE = new UnsupportedOperationException("MessageHistory is immutable."); @@ -68,9 +70,11 @@ public final class MessageHistory implements List, Serializable { private final List components; - - public static MessageHistory read(Message message) { - return message != null ? message.getHeaders().get(HEADER_NAME, MessageHistory.class) : null; + @Nullable + public static MessageHistory read(@Nullable Message message) { + return message != null + ? message.getHeaders().get(HEADER_NAME, MessageHistory.class) + : null; } public static Message write(Message message, NamedComponent component) { @@ -87,8 +91,10 @@ public final class MessageHistory implements List, Serializable { Properties metadata = extractMetadata(component); if (!metadata.isEmpty()) { MessageHistory previousHistory = message.getHeaders().get(HEADER_NAME, MessageHistory.class); - List components = (previousHistory != null) ? - new ArrayList(previousHistory) : new ArrayList(); + List components = + previousHistory != null + ? new ArrayList<>(previousHistory) + : new ArrayList<>(); components.add(metadata); MessageHistory history = new MessageHistory(components); @@ -111,13 +117,13 @@ public final class MessageHistory implements List, Serializable { else { if (!(message instanceof GenericMessage) && (messageBuilderFactory instanceof DefaultMessageBuilderFactory || - messageBuilderFactory instanceof MutableMessageBuilderFactory)) { - if (logger.isWarnEnabled()) { - logger.warn("MessageHistory rebuilds the message and produces the result of the [" + - messageBuilderFactory + "], not an instance of the provided type [" + - message.getClass() + "]. Consider to supply a custom MessageBuilderFactory " + - "to retain custom messages during MessageHistory tracking."); - } + messageBuilderFactory instanceof MutableMessageBuilderFactory) + && LOGGER.isWarnEnabled()) { + + LOGGER.warn("MessageHistory rebuilds the message and produces the result of the [" + + messageBuilderFactory + "], not an instance of the provided type [" + + message.getClass() + "]. Consider to supply a custom MessageBuilderFactory " + + "to retain custom messages during MessageHistory tracking."); } message = messageBuilderFactory.fromMessage(message) .setHeader(HEADER_NAME, history) @@ -201,14 +207,10 @@ public final class MessageHistory implements List, Serializable { @Override public String toString() { - List names = new ArrayList(); - for (Properties p : this.components) { - String name = p.getProperty(NAME_PROPERTY); - if (name != null) { - names.add(name); - } - } - return StringUtils.collectionToCommaDelimitedString(names); + return this.components + .stream() + .map((props) -> props.getProperty(NAME_PROPERTY)) + .collect(Collectors.joining(",")); }