From 93d7c58b64e2bcc95f73e7fd47ccb3e8926683df Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 20 Dec 2018 19:19:47 -0500 Subject: [PATCH] Enable ModifierOrderCheck Checkstyle rule (#2673) * Enable ModifierOrderCheck Checkstyle rule * Fix violations for `static` and `abstract` modifier * Remove redundant code in the `TcpNioConnection` * Mark `connectionFactoryName` as `@Nullable` in the `TcpConnectionSupport` ctor and its inheritors * Fix some smells according IDEA suggestions in the affected classes * This should fix some Sonar smells as well * * Fix `HeaderMapperTests` * * Polishing `TcpConnection` code style and fix Javdocs --- .../AbstractAmqpOutboundEndpoint.java | 2 +- .../codec/kryo/AbstractKryoRegistrar.java | 8 +- .../codec/kryo/RegistrationIds.java | 6 +- ...ltConfiguringBeanFactoryPostProcessor.java | 17 +- .../config/ExpressionFactoryBean.java | 15 +- .../config/xml/ConverterParser.java | 12 +- .../dsl/IntegrationComponentSpec.java | 2 +- .../integration/dsl/Transformers.java | 46 ++- .../GatewayMethodInboundMessageMapper.java | 34 +- .../handler/AbstractMessageProcessor.java | 6 +- .../integration/support/MapBuilder.java | 7 +- .../channel/BeanFactoryChannelResolver.java | 8 +- .../micrometer/MicrometerMetricsCaptor.java | 3 +- .../annotation/SubscriberOrderTests.java | 9 +- .../core/TimeBasedUUIDGenerator.java | 28 +- .../mapping/HeaderMapperTests.java | 19 +- .../integration/message/TestHandlers.java | 18 +- .../DefaultMessageChannelMetricsTests.java | 7 +- .../ExponentialMovingAverageRateTests.java | 18 +- .../FeedInboundChannelAdapterParserTests.java | 6 +- .../integration/feed/dsl/FeedDslTests.java | 8 +- ...tractRemoteFileStreamingMessageSource.java | 22 +- .../AbstractRemoteFileOutboundGateway.java | 371 +++++++++--------- ...FileOutboundChannelAdapterParserTests.java | 45 +-- .../FileOutboundGatewayParserTests.java | 41 +- .../IntegrationGraphController.java | 2 +- .../DefaultTcpNioConnectionSupport.java | 9 +- .../tcp/connection/TcpConnectionSupport.java | 5 +- .../ip/tcp/connection/TcpNioConnection.java | 27 +- .../tcp/connection/TcpNioSSLConnection.java | 9 +- .../tcp/connection/TcpNioConnectionTests.java | 6 +- ...onEvaluatingSqlParameterSourceFactory.java | 34 +- .../integration/jms/JmsHeaderMapper.java | 5 +- .../jms/config/JmsChannelParser.java | 24 +- ...ssionEvaluatingParameterSourceFactory.java | 14 +- .../mail/AbstractMailReceiver.java | 15 +- .../mail/ImapMailReceiverTests.java | 4 +- .../integration/mail/dsl/MailTests.java | 10 +- ...stractConfigurableMongoDbMessageStore.java | 5 +- .../ConfigurableMongoDbMessageStore.java | 2 +- .../store/MongoDbChannelMessageStore.java | 7 +- .../mongodb/store/MongoDbMessageStore.java | 21 +- .../metadata/MongoDbMetadataStoreTests.java | 20 +- .../outbound/RedisQueueOutboundGateway.java | 5 +- .../rmi/RmiOutboundGatewayTests.java | 35 +- .../config/RmiOutboundGatewayParserTests.java | 4 +- ...yContextPropagationChannelInterceptor.java | 11 +- .../integration/sftp/session/JschLogger.java | 66 ++-- .../support/LongRunningIntegrationTest.java | 7 +- .../support/SubProtocolHandlerRegistry.java | 15 +- .../ClientWebSocketContainerTests.java | 22 +- .../server/WebSocketServerTests.java | 9 +- .../ws/AbstractWebServiceInboundGateway.java | 7 +- .../TestXmlApplicationContextHelper.java | 31 +- .../xmpp/config/XmppNamespaceHandler.java | 6 +- src/checkstyle/checkstyle.xml | 1 + 56 files changed, 633 insertions(+), 563 deletions(-) diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java index 7b8c9f729f..93a36ee63e 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java @@ -310,7 +310,7 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin this.errorMessageStrategy = errorMessageStrategy; } - protected synchronized final void setConnectionFactory(ConnectionFactory connectionFactory) { + protected final synchronized void setConnectionFactory(ConnectionFactory connectionFactory) { this.connectionFactory = connectionFactory; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/AbstractKryoRegistrar.java b/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/AbstractKryoRegistrar.java index 8cb755153a..c381552594 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/AbstractKryoRegistrar.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/AbstractKryoRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 the original author or authors. + * Copyright 2015-2018 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. @@ -28,11 +28,13 @@ import com.esotericsoftware.kryo.Registration; * Base class for {@link KryoRegistrar} implementations. * * @author David Turanski + * @author Artem Bilan + * * @since 4.2 */ public abstract class AbstractKryoRegistrar implements KryoRegistrar { - protected final static Kryo kryo = new Kryo(); + protected static final Kryo kryo = new Kryo(); protected final Log log = LogFactory.getLog(this.getClass()); @@ -55,7 +57,7 @@ public abstract class AbstractKryoRegistrar implements KryoRegistrar { Registration existing = kryo.getRegistration(id); if (existing != null) { - throw new RuntimeException((String.format("registration already exists %s", existing))); + throw new RuntimeException("registration already exists " + existing); } if (this.log.isInfoEnabled()) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/RegistrationIds.java b/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/RegistrationIds.java index c44c968d8b..70f97598e2 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/RegistrationIds.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/RegistrationIds.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 the original author or authors. + * Copyright 2015-2018 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. @@ -20,12 +20,14 @@ package org.springframework.integration.codec.kryo; * Default registration ids for serializers provided by the framework. * * @author Gary Russell + * @author Artem Bilan + * * @since 4.2 * */ public final class RegistrationIds { - public final static int DEFAULT_FILE_REGISTRATION_ID = 40; + public static final int DEFAULT_FILE_REGISTRATION_ID = 40; public static final int DEFAULT_MESSAGEHEADERS_ID = 41; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java index 118091e857..00a410e049 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java @@ -89,7 +89,7 @@ class DefaultConfiguringBeanFactoryPostProcessor private static final Log logger = LogFactory.getLog(DefaultConfiguringBeanFactoryPostProcessor.class); - private final static IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER = + private static final IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER = new IntegrationConverterInitializer(); private static final Set registriesProcessed = new HashSet<>(); @@ -152,17 +152,22 @@ class DefaultConfiguringBeanFactoryPostProcessor */ private void registerNullChannel() { if (this.beanFactory.containsBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) { - BeanDefinition nullChannelDefinition; + BeanDefinition nullChannelDefinition = null; if (this.beanFactory.containsBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) { nullChannelDefinition = this.beanFactory.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); } else { - nullChannelDefinition = - ((BeanDefinitionRegistry) this.beanFactory.getParentBeanFactory()) - .getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); // NOSONAR not null + BeanDefinitionRegistry parentBeanFactory = + (BeanDefinitionRegistry) this.beanFactory.getParentBeanFactory(); + if (parentBeanFactory != null) { + nullChannelDefinition = + parentBeanFactory.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); + } } - if (!NullChannel.class.getName().equals(nullChannelDefinition.getBeanClassName())) { + + if (nullChannelDefinition != null && + !NullChannel.class.getName().equals(nullChannelDefinition.getBeanClassName())) { throw new IllegalStateException("The bean name '" + IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME + "' is reserved."); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/ExpressionFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/ExpressionFactoryBean.java index 25079ed7e9..331a8b4537 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/ExpressionFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/ExpressionFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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,26 +27,27 @@ import org.springframework.util.Assert; * FactoryBean for creating Expression instances. * * @author Mark Fisher + * @author Artem Bilan + * * @since 2.0 */ public class ExpressionFactoryBean extends AbstractFactoryBean { - private final static ExpressionParser DEFAULT_PARSER = new SpelExpressionParser(); - + private static final ExpressionParser DEFAULT_PARSER = new SpelExpressionParser(); private final String expressionString; - private volatile ExpressionParser parser = DEFAULT_PARSER; + private ExpressionParser parser = DEFAULT_PARSER; public ExpressionFactoryBean(String expressionString) { - Assert.hasText(expressionString, "expressionString must not be empty or null"); + Assert.hasText(expressionString, "'expressionString' must not be empty or null"); this.expressionString = expressionString; } public void setParserConfiguration(SpelParserConfiguration parserConfiguration) { - Assert.notNull(parserConfiguration, "parserConfiguration must not be null"); + Assert.notNull(parserConfiguration, "'parserConfiguration' must not be null"); this.parser = new SpelExpressionParser(parserConfiguration); } @@ -57,7 +58,7 @@ public class ExpressionFactoryBean extends AbstractFactoryBean { } @Override - protected Expression createInstance() throws Exception { + protected Expression createInstance() { return this.parser.parseExpression(this.expressionString); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ConverterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ConverterParser.java index e438fa1468..41abcecebb 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ConverterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ConverterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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,23 +32,27 @@ import org.springframework.util.StringUtils; * @author Oleg Zhurakousky * @author Mark Fisher * @author Artem Bilan + * * @since 2.0 */ public class ConverterParser extends AbstractBeanDefinitionParser { - private final static IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER = new IntegrationConverterInitializer(); + private static final IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER = + new IntegrationConverterInitializer(); @Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionRegistry registry = parserContext.getRegistry(); - BeanComponentDefinition converterDefinition = IntegrationNamespaceUtils.parseInnerHandlerDefinition(element, parserContext); + BeanComponentDefinition converterDefinition = + IntegrationNamespaceUtils.parseInnerHandlerDefinition(element, parserContext); if (converterDefinition != null) { INTEGRATION_CONVERTER_INITIALIZER.registerConverter(registry, converterDefinition); } else { String beanName = element.getAttribute("ref"); Assert.isTrue(StringUtils.hasText(beanName), - "Either a 'ref' attribute pointing to a Converter or a sub-element defining a Converter is required."); + "Either a 'ref' attribute pointing to a Converter " + + "or a sub-element defining a Converter is required."); INTEGRATION_CONVERTER_INITIALIZER.registerConverter(registry, new RuntimeBeanReference(beanName)); } return null; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationComponentSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationComponentSpec.java index 5b58ce103c..9326ba97ed 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationComponentSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationComponentSpec.java @@ -37,7 +37,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; public abstract class IntegrationComponentSpec, T> implements FactoryBean, InitializingBean, DisposableBean { - protected final static SpelExpressionParser PARSER = new SpelExpressionParser(); + protected static final SpelExpressionParser PARSER = new SpelExpressionParser(); protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/Transformers.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/Transformers.java index b7978beef5..5166792e31 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/Transformers.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/Transformers.java @@ -42,8 +42,8 @@ import org.springframework.integration.transformer.PayloadSerializingTransformer import org.springframework.integration.transformer.PayloadTypeConvertingTransformer; import org.springframework.integration.transformer.StreamTransformer; import org.springframework.integration.transformer.SyslogToMapTransformer; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; -import org.springframework.util.Assert; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -58,14 +58,16 @@ import reactor.core.publisher.Mono; */ public abstract class Transformers { - private final static SpelExpressionParser PARSER = new SpelExpressionParser(); + private static final SpelExpressionParser PARSER = new SpelExpressionParser(); public static ObjectToStringTransformer objectToString() { return objectToString(null); } - public static ObjectToStringTransformer objectToString(String charset) { - return charset != null ? new ObjectToStringTransformer(charset) : new ObjectToStringTransformer(); + public static ObjectToStringTransformer objectToString(@Nullable String charset) { + return charset != null + ? new ObjectToStringTransformer(charset) + : new ObjectToStringTransformer(); } public static ObjectToMapTransformer toMap() { @@ -100,20 +102,21 @@ public abstract class Transformers { return toJson(null, null, null); } - public static ObjectToJsonTransformer toJson(JsonObjectMapper jsonObjectMapper) { + public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper jsonObjectMapper) { return toJson(jsonObjectMapper, null, null); } - public static ObjectToJsonTransformer toJson(JsonObjectMapper jsonObjectMapper, - ObjectToJsonTransformer.ResultType resultType) { + public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper jsonObjectMapper, + @Nullable ObjectToJsonTransformer.ResultType resultType) { return toJson(jsonObjectMapper, resultType, null); } - public static ObjectToJsonTransformer toJson(String contentType) { + public static ObjectToJsonTransformer toJson(@Nullable String contentType) { return toJson(null, null, contentType); } - public static ObjectToJsonTransformer toJson(JsonObjectMapper jsonObjectMapper, String contentType) { + public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper jsonObjectMapper, + @Nullable String contentType) { return toJson(jsonObjectMapper, null, contentType); } @@ -124,16 +127,18 @@ public abstract class Transformers { * @return the ObjectToJsonTransformer * @since 5.0.9 */ - public static ObjectToJsonTransformer toJson(ObjectToJsonTransformer.ResultType resultType) { + public static ObjectToJsonTransformer toJson(@Nullable ObjectToJsonTransformer.ResultType resultType) { return toJson(null, resultType, null); } - public static ObjectToJsonTransformer toJson(ObjectToJsonTransformer.ResultType resultType, String contentType) { + public static ObjectToJsonTransformer toJson(@Nullable ObjectToJsonTransformer.ResultType resultType, + @Nullable String contentType) { return toJson(null, resultType, contentType); } - public static ObjectToJsonTransformer toJson(JsonObjectMapper jsonObjectMapper, - ObjectToJsonTransformer.ResultType resultType, String contentType) { + public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper jsonObjectMapper, + @Nullable ObjectToJsonTransformer.ResultType resultType, @Nullable String contentType) { + ObjectToJsonTransformer transformer; if (jsonObjectMapper != null) { if (resultType != null) { @@ -159,15 +164,17 @@ public abstract class Transformers { return fromJson(null, null); } - public static JsonToObjectTransformer fromJson(Class targetClass) { + public static JsonToObjectTransformer fromJson(@Nullable Class targetClass) { return fromJson(targetClass, null); } - public static JsonToObjectTransformer fromJson(JsonObjectMapper jsonObjectMapper) { + public static JsonToObjectTransformer fromJson(@Nullable JsonObjectMapper jsonObjectMapper) { return fromJson(null, jsonObjectMapper); } - public static JsonToObjectTransformer fromJson(Class targetClass, JsonObjectMapper jsonObjectMapper) { + public static JsonToObjectTransformer fromJson(@Nullable Class targetClass, + @Nullable JsonObjectMapper jsonObjectMapper) { + return new JsonToObjectTransformer(targetClass, jsonObjectMapper); } @@ -175,7 +182,7 @@ public abstract class Transformers { return serializer(null); } - public static PayloadSerializingTransformer serializer(Serializer serializer) { + public static PayloadSerializingTransformer serializer(@Nullable Serializer serializer) { PayloadSerializingTransformer transformer = new PayloadSerializingTransformer(); if (serializer != null) { transformer.setSerializer(serializer); @@ -187,7 +194,7 @@ public abstract class Transformers { return deserializer(null, whiteListPatterns); } - public static PayloadDeserializingTransformer deserializer(Deserializer deserializer, + public static PayloadDeserializingTransformer deserializer(@Nullable Deserializer deserializer, String... whiteListPatterns) { PayloadDeserializingTransformer transformer = new PayloadDeserializingTransformer(); transformer.setWhiteListPatterns(whiteListPatterns); @@ -198,7 +205,6 @@ public abstract class Transformers { } public static PayloadTypeConvertingTransformer converter(Converter converter) { - Assert.notNull(converter, "The Converter is required for the PayloadTypeConvertingTransformer"); PayloadTypeConvertingTransformer transformer = new PayloadTypeConvertingTransformer<>(); transformer.setConverter(converter); return transformer; @@ -276,7 +282,7 @@ public abstract class Transformers { * @param charset the charset. * @return the {@link StreamTransformer} instance. */ - public static StreamTransformer fromStream(String charset) { + public static StreamTransformer fromStream(@Nullable String charset) { return new StreamTransformer(charset); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java index dfcc4bcf78..e4e7fbd540 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java @@ -84,10 +84,12 @@ import org.springframework.util.StringUtils; */ class GatewayMethodInboundMessageMapper implements InboundMessageMapper, BeanFactoryAware { - private final static Log logger = LogFactory.getLog(GatewayMethodInboundMessageMapper.class); + private static final Log logger = LogFactory.getLog(GatewayMethodInboundMessageMapper.class); private static final SpelExpressionParser PARSER = new SpelExpressionParser(); + private final Map parameterPayloadExpressions = new HashMap<>(); + private final Method method; private final Map headerExpressions; @@ -102,13 +104,11 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper parameterPayloadExpressions = new HashMap(); + private EvaluationContext payloadExpressionEvaluationContext; - private volatile StandardEvaluationContext payloadExpressionEvaluationContext; - - private volatile BeanFactory beanFactory; + private BeanFactory beanFactory; private Expression sendTimeoutExpression; @@ -127,6 +127,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper globalHeaderExpressions, @Nullable MethodArgsMessageMapper mapper, @Nullable MessageBuilderFactory messageBuilderFactory) { + this(method, headerExpressions, globalHeaderExpressions, null, mapper, messageBuilderFactory); } @@ -189,7 +190,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper mapArgumentsToMessage(Object[] arguments, Map headers) { + private Message mapArgumentsToMessage(Object[] arguments, @Nullable Map headers) { try { return this.argsMapper.toMessage(new MethodArgsHolder(this.method, arguments), headers); } @@ -205,6 +206,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper evaluateHeaders(EvaluationContext methodInvocationEvaluationContext, Map headerExpressions) { + Map evaluatedHeaders = new HashMap<>(); for (Map.Entry entry : headerExpressions.entrySet()) { Object value = entry.getValue().getValue(methodInvocationEvaluationContext); @@ -277,7 +279,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper toMessage(MethodArgsHolder holder, @Nullable Map headers) throws Exception { + public Message toMessage(MethodArgsHolder holder, @Nullable Map headers) { Object messageOrPayload = null; boolean foundPayloadAnnotation = false; Object[] arguments = holder.getArgs(); @@ -296,13 +298,15 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper(); if (GatewayMethodInboundMessageMapper.this.payloadExpression != null) { messageOrPayload = - GatewayMethodInboundMessageMapper.this.payloadExpression.getValue(methodInvocationEvaluationContext); + GatewayMethodInboundMessageMapper.this.payloadExpression.getValue( + methodInvocationEvaluationContext); } for (int i = 0; i < GatewayMethodInboundMessageMapper.this.parameterList.size(); i++) { Object argumentValue = arguments[i]; MethodParameter methodParameter = GatewayMethodInboundMessageMapper.this.parameterList.get(i); Annotation annotation = - MessagingAnnotationUtils.findMessagePartAnnotation(methodParameter.getParameterAnnotations(), false); + MessagingAnnotationUtils.findMessagePartAnnotation(methodParameter.getParameterAnnotations(), + false); if (annotation != null) { if (annotation.annotationType().equals(Payload.class)) { if (messageOrPayload != null) { @@ -329,7 +333,8 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper) argumentValue).keySet()) { Assert.isInstanceOf(String.class, key, "Invalid header name [" + key + @@ -369,10 +374,11 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper GatewayMethodInboundMessageMapper.this.replyTimeoutExpression .getValue(methodInvocationEvaluationContext, Long.class)); } + MessageBuilderFactory messageBuilderFactory = GatewayMethodInboundMessageMapper.this.messageBuilderFactory; AbstractIntegrationMessageBuilder builder = (messageOrPayload instanceof Message) - ? GatewayMethodInboundMessageMapper.this.messageBuilderFactory.fromMessage((Message) messageOrPayload) - : GatewayMethodInboundMessageMapper.this.messageBuilderFactory.withPayload(messageOrPayload); + ? messageBuilderFactory.fromMessage((Message) messageOrPayload) + : messageBuilderFactory.withPayload(messageOrPayload); builder.copyHeadersIfAbsent(headers); // Explicit headers in XML override any @Header annotations... if (!CollectionUtils.isEmpty(GatewayMethodInboundMessageMapper.this.headerExpressions)) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageProcessor.java index fb496ffcc3..6b50c61923 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -22,10 +22,12 @@ import org.springframework.messaging.Message; /** * @author Mark Fisher * @author Dave Syer + * @author Artem Bilan + * * @since 2.0 */ public abstract class AbstractMessageProcessor extends AbstractExpressionEvaluator implements MessageProcessor { - abstract public T processMessage(Message message); + public abstract T processMessage(Message message); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/MapBuilder.java b/spring-integration-core/src/main/java/org/springframework/integration/support/MapBuilder.java index b813227ee5..f38a82dd8c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/MapBuilder.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/MapBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2018 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. @@ -29,13 +29,14 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; * @param The Map value type. * * @author Artem Bilan + * * @since 5.0 */ public class MapBuilder, K, V> { - protected final static SpelExpressionParser PARSER = new SpelExpressionParser(); + protected static final SpelExpressionParser PARSER = new SpelExpressionParser(); - private final Map map = new HashMap(); + private final Map map = new HashMap<>(); public B put(K key, V value) { this.map.put(key, value); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/channel/BeanFactoryChannelResolver.java b/spring-integration-core/src/main/java/org/springframework/integration/support/channel/BeanFactoryChannelResolver.java index c2e3aa39df..7eef6b9143 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/channel/BeanFactoryChannelResolver.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/channel/BeanFactoryChannelResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -45,11 +45,11 @@ import org.springframework.util.Assert; */ public class BeanFactoryChannelResolver implements DestinationResolver, BeanFactoryAware { - private final static Log logger = LogFactory.getLog(BeanFactoryChannelResolver.class); + private static final Log logger = LogFactory.getLog(BeanFactoryChannelResolver.class); - private volatile BeanFactory beanFactory; + private BeanFactory beanFactory; - private volatile HeaderChannelRegistry replyChannelRegistry; + private HeaderChannelRegistry replyChannelRegistry; private volatile boolean initialized; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/micrometer/MicrometerMetricsCaptor.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/micrometer/MicrometerMetricsCaptor.java index 72dd0ebe8a..18aed71657 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/micrometer/MicrometerMetricsCaptor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/micrometer/MicrometerMetricsCaptor.java @@ -40,6 +40,7 @@ import io.micrometer.core.instrument.Timer; * The Micrometer implementation of {@link MetricsCaptor}. * * @author Gary Russell + * @author Artem Bilan * * @since 5.0.4 * @@ -148,7 +149,7 @@ public class MicrometerMetricsCaptor implements MetricsCaptor { } - protected static abstract class AbstractMeter implements MeterFacade { + protected abstract static class AbstractMeter implements MeterFacade { protected final MeterRegistry meterRegistry; // NOSONAR diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/SubscriberOrderTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/SubscriberOrderTests.java index 8f0b7375d1..765f818e34 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/SubscriberOrderTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/SubscriberOrderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -141,7 +141,7 @@ public class SubscriberOrderTests { } - static abstract class AbstractTestBean { + abstract static class AbstractTestBean { @Order(4) abstract void fourth(Message message); @@ -157,7 +157,7 @@ public class SubscriberOrderTests { private final int maxCallsPerMethod; - private volatile List calls = new ArrayList(); + private final List calls = new ArrayList<>(); TestBean(int maxCallsPerMethod) { @@ -166,7 +166,7 @@ public class SubscriberOrderTests { void reset() { - this.calls = new ArrayList(); + this.calls.clear(); } @Order(3) @@ -211,6 +211,7 @@ public class SubscriberOrderTests { } this.calls.add(methodNumber); } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/core/TimeBasedUUIDGenerator.java b/spring-integration-core/src/test/java/org/springframework/integration/core/TimeBasedUUIDGenerator.java index 20b9c982fb..672038b269 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/core/TimeBasedUUIDGenerator.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/core/TimeBasedUUIDGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,18 +24,22 @@ import java.util.logging.Logger; /** * @author Oleg Zhurakousky + * @author Artem Bilan * */ class TimeBasedUUIDGenerator { + static final Object lock = new Object(); + private static final Logger logger = Logger.getLogger(TimeBasedUUIDGenerator.class.getName()); - public static final Object lock = new Object(); + private static final long macAddress = getMac(); private static boolean canNotDetermineMac = true; + private static long lastTime; + private static long clockSequence = 0; - private static final long macAddress = getMac(); private TimeBasedUUIDGenerator() { super(); @@ -45,11 +49,11 @@ class TimeBasedUUIDGenerator { * Will generate unique time based UUID where the next UUID is * always greater then the previous. */ - public final static UUID generateId() { + static UUID generateId() { return generateIdFromTimestamp(System.currentTimeMillis()); } - public final static UUID generateIdFromTimestamp(long currentTimeMillis) { + static UUID generateIdFromTimestamp(long currentTimeMillis) { long time; synchronized (lock) { @@ -78,11 +82,12 @@ class TimeBasedUUIDGenerator { clock_seq_hi_and_reserved <<= 48; - long cls = 0 | clock_seq_hi_and_reserved; + long cls = clock_seq_hi_and_reserved; long lsb = cls | macAddress; if (canNotDetermineMac) { - logger.warning("UUID generation process was not able to determine your MAC address. Returning random UUID (non version 1 UUID)"); + logger.warning("UUID generation process was not able to determine your MAC address. " + + "Returning random UUID (non version 1 UUID)"); return UUID.randomUUID(); } else { @@ -98,11 +103,9 @@ class TimeBasedUUIDGenerator { //byte[] mac = ni.getHardwareAddress(); // availabe since Java 1.6 byte[] mac = "01:23:45:67:89:ab".getBytes(); //Converts array of unsigned bytes to an long - if (mac != null) { - for (int i = 0; i < mac.length; i++) { - macAddressAsLong <<= 8; - macAddressAsLong ^= (long) mac[i] & 0xFF; - } + for (byte aMac : mac) { + macAddressAsLong <<= 8; + macAddressAsLong ^= (long) aMac & 0xFF; } } canNotDetermineMac = false; @@ -112,4 +115,5 @@ class TimeBasedUUIDGenerator { } return macAddressAsLong; } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/mapping/HeaderMapperTests.java b/spring-integration-core/src/test/java/org/springframework/integration/mapping/HeaderMapperTests.java index 9ad7ea7aef..a4ea731385 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/mapping/HeaderMapperTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/mapping/HeaderMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -34,11 +34,14 @@ import org.springframework.integration.mapping.AbstractHeaderMapper.HeaderMatche import org.springframework.integration.mapping.AbstractHeaderMapper.PatternBasedHeaderMatcher; import org.springframework.integration.mapping.AbstractHeaderMapper.PrefixBasedMatcher; import org.springframework.integration.mapping.AbstractHeaderMapper.SinglePatternBasedHeaderMatcher; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessageHeaders; import org.springframework.util.StringUtils; /** * @author Stephane Nicoll + * @author Artem Bilan + * * @since 4.1 */ public class HeaderMapperTests { @@ -75,8 +78,8 @@ public class HeaderMapperTests { GenericTestProperties properties = createSimpleGenericTestProperties(); Map attributes = this.mapper.toHeadersFromRequest(properties); - assertEquals(null, attributes.get(GenericTestHeaders.APP_ID)); - assertEquals(null, attributes.get(GenericTestHeaders.REQUEST_ONLY)); + assertNull(attributes.get(GenericTestHeaders.APP_ID)); + assertNull(attributes.get(GenericTestHeaders.REQUEST_ONLY)); assertEquals("reply-123", attributes.get(GenericTestHeaders.REPLY_ONLY)); assertEquals("bar", attributes.get("foo")); assertEquals("Wrong number of mapped header(s)", 2, attributes.size()); @@ -310,7 +313,7 @@ public class HeaderMapperTests { } public MessageHeaders createSimpleMessageHeaders() { - Map headers = new HashMap(); + Map headers = new HashMap<>(); headers.put(GenericTestHeaders.APP_ID, "myAppId"); headers.put(GenericTestHeaders.REDELIVERED, true); headers.put(GenericTestHeaders.REQUEST_ONLY, "request-456"); @@ -324,7 +327,6 @@ public class HeaderMapperTests { @Test public void prefixHeaderPatternMatching() { - @SuppressWarnings("deprecation") PatternBasedHeaderMatcher strategy = new PatternBasedHeaderMatcher(Collections.singleton("fOo*")); @@ -338,7 +340,6 @@ public class HeaderMapperTests { @Test public void suffixHeaderPatternMatching() { - @SuppressWarnings("deprecation") PatternBasedHeaderMatcher strategy = new PatternBasedHeaderMatcher(Collections.singleton("*fOo")); @@ -435,7 +436,7 @@ public class HeaderMapperTests { } - private static abstract class GenericTestHeaders { + private abstract static class GenericTestHeaders { public static final String PREFIX = "generic_"; @@ -464,7 +465,7 @@ public class HeaderMapperTests { @Override protected Map extractStandardHeaders(GenericTestProperties source) { - Map result = new HashMap(); + Map result = new HashMap<>(); if (StringUtils.hasText(source.getAppId())) { result.put(GenericTestHeaders.APP_ID, source.getAppId()); } @@ -547,6 +548,7 @@ public class HeaderMapperTests { this.appId = appId; } + @Nullable public Integer getTransactionSize() { return transactionSize; } @@ -555,6 +557,7 @@ public class HeaderMapperTests { this.transactionSize = transactionSize; } + @Nullable public Boolean getRedelivered() { return redelivered; } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/message/TestHandlers.java b/spring-integration-core/src/test/java/org/springframework/integration/message/TestHandlers.java index 63adef57c3..f97db11f87 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/message/TestHandlers.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/message/TestHandlers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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.Message; * Factory for handler beans that are useful for testing. * * @author Mark Fisher + * @author Artem Bilan */ @SuppressWarnings("unused") public abstract class TestHandlers { @@ -32,8 +33,9 @@ public abstract class TestHandlers { /** * Create a handler that always returns null. */ - public final static Object nullHandler() { + public static final Object nullHandler() { return new Object() { + public Message handle(Message message) { return null; } @@ -43,8 +45,9 @@ public abstract class TestHandlers { /** * Create a handler that simply returns the {@link Message} it receives. */ - public final static Object echoHandler() { + public static final Object echoHandler() { return new Object() { + public Message handle(Message message) { return message; } @@ -54,8 +57,9 @@ public abstract class TestHandlers { /** * Create a handler that increments the provided counter. */ - public final static Object countingHandler(final AtomicInteger counter) { + public static final Object countingHandler(final AtomicInteger counter) { return new Object() { + public Message handle(Message message) { counter.incrementAndGet(); return null; @@ -66,8 +70,9 @@ public abstract class TestHandlers { /** * Create a handler that counts down on the provided latch. */ - public final static Object countDownHandler(final CountDownLatch latch) { + public static final Object countDownHandler(final CountDownLatch latch) { return new Object() { + public Message handle(Message message) { latch.countDown(); return null; @@ -79,8 +84,9 @@ public abstract class TestHandlers { * Create a handler that counts down on the provided latch * and also increments the provided counter. */ - public final static Object countingCountDownHandler(final AtomicInteger counter, final CountDownLatch latch) { + public static final Object countingCountDownHandler(final AtomicInteger counter, final CountDownLatch latch) { return new Object() { + public Message handle(Message message) { counter.incrementAndGet(); latch.countDown(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/management/DefaultMessageChannelMetricsTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/management/DefaultMessageChannelMetricsTests.java index ba380c0769..edc3a3ffdb 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/support/management/DefaultMessageChannelMetricsTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/support/management/DefaultMessageChannelMetricsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2018 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,12 +25,13 @@ import org.springframework.messaging.Message; /** * @author Ivan Krizsan + * @author Artem Bilan */ public class DefaultMessageChannelMetricsTests { - protected final static int MESSAGE_COUNT = 10; + protected static final int MESSAGE_COUNT = 10; - protected final static long SEND_TIMEOUT = 1; + protected static final long SEND_TIMEOUT = 1; @Test public void errorCountWithCountsEnabledOnlySuccessTest() { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageRateTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageRateTests.java index c46bfcaf0b..296560f165 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageRateTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageRateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -18,7 +18,6 @@ package org.springframework.integration.support.management; import static org.hamcrest.Matchers.lessThan; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -37,11 +36,12 @@ import org.springframework.util.StopWatch; * @author Dave Syer * @author Gary Russell * @author Steven Swor + * @author Artem Bilan */ @Ignore("Very sensitive to the time. Don't forget to test after some changes.") public class ExponentialMovingAverageRateTests { - private final static Log logger = LogFactory.getLog(ExponentialMovingAverageRateTests.class); + private static final Log logger = LogFactory.getLog(ExponentialMovingAverageRateTests.class); private final ExponentialMovingAverageRate history = new ExponentialMovingAverageRate(1., 10., 10, true); @@ -54,7 +54,7 @@ public class ExponentialMovingAverageRateTests { @Test @SuppressWarnings("unchecked") - public void testGetTimeSinceLastMeasurement() throws Exception { + public void testGetTimeSinceLastMeasurement() { long sleepTime = 20L; // fill history with the same value. @@ -67,7 +67,7 @@ public class ExponentialMovingAverageRateTests { assertEquals(Long.valueOf(now), times.peekLast()); //increment just so we'll have a different value between first and last - history.increment(System.nanoTime() - sleepTime * 1000000); + history.increment(System.nanoTime() - sleepTime * 1000000); assertNotEquals(times.peekFirst(), times.peekLast()); /* @@ -76,7 +76,7 @@ public class ExponentialMovingAverageRateTests { * the queue, then we should be closer to the sleep time than we are to * 2 x sleepTime, but we should definitely be greater than the sleep * time. - */ + */ double timeSinceLastMeasurement = history.getTimeSinceLastMeasurement(); assertTrue(timeSinceLastMeasurement > sleepTime); assertTrue(timeSinceLastMeasurement <= (1.5 * sleepTime)); @@ -126,7 +126,6 @@ public class ExponentialMovingAverageRateTests { } @Test - @Ignore public void testGetStandardDeviation() throws Exception { assertEquals(0, history.getStandardDeviation(), 0.01); Thread.sleep(20L); @@ -138,13 +137,12 @@ public class ExponentialMovingAverageRateTests { } @Test - @Ignore public void testReset() throws Exception { assertEquals(0, history.getStandardDeviation(), 0.01); history.increment(); Thread.sleep(30L); history.increment(); - assertFalse(0 == history.getStandardDeviation()); + assertNotEquals(0, history.getStandardDeviation(), 0.0); history.reset(); assertEquals(0, history.getStandardDeviation(), 0.01); assertEquals(0, history.getCount()); @@ -155,7 +153,6 @@ public class ExponentialMovingAverageRateTests { } @Test - @Ignore // tolerance needed is too dependent on hardware public void testRate() { ExponentialMovingAverageRate rate = new ExponentialMovingAverageRate(1, 60, 10); int count = 1000000; @@ -170,7 +167,6 @@ public class ExponentialMovingAverageRateTests { } @Test - @Ignore public void testPerf() { ExponentialMovingAverageRate rate = new ExponentialMovingAverageRate(1, 60, 10); for (int i = 0; i < 1000000; i++) { diff --git a/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests.java b/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests.java index 393ceec742..f038d568d9 100644 --- a/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests.java +++ b/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -63,7 +63,7 @@ import com.rometools.rome.io.SyndFeedInput; public class FeedInboundChannelAdapterParserTests { @ClassRule - public final static TemporaryFolder tempFolder = new TemporaryFolder(); + public static final TemporaryFolder tempFolder = new TemporaryFolder(); private static CountDownLatch latch; @@ -144,7 +144,7 @@ public class FeedInboundChannelAdapterParserTests { public void receiveFeedEntry(Message message) { MessageHistory history = MessageHistory.read(message); - assertTrue(history.size() == 3); + assertEquals(3, history.size()); Properties historyItem = history.get(0); assertEquals("feedAdapterUsage", historyItem.get("name")); assertEquals("feed:inbound-channel-adapter", historyItem.get("type")); diff --git a/spring-integration-feed/src/test/java/org/springframework/integration/feed/dsl/FeedDslTests.java b/spring-integration-feed/src/test/java/org/springframework/integration/feed/dsl/FeedDslTests.java index 40344defe3..ef51f8bdb5 100644 --- a/spring-integration-feed/src/test/java/org/springframework/integration/feed/dsl/FeedDslTests.java +++ b/spring-integration-feed/src/test/java/org/springframework/integration/feed/dsl/FeedDslTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2018 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. @@ -16,6 +16,7 @@ package org.springframework.integration.feed.dsl; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; @@ -56,7 +57,7 @@ import com.rometools.rome.feed.synd.SyndEntry; public class FeedDslTests { @ClassRule - public final static TemporaryFolder tempFolder = new TemporaryFolder(); + public static final TemporaryFolder tempFolder = new TemporaryFolder(); @Autowired private PollableChannel entries; @@ -70,6 +71,9 @@ public class FeedDslTests { Message message1 = (Message) this.entries.receive(10000); Message message2 = (Message) this.entries.receive(10000); Message message3 = (Message) this.entries.receive(10000); + assertThat(message1).isNotNull(); + assertThat(message2).isNotNull(); + assertThat(message3).isNotNull(); long time1 = message1.getPayload().getPublishedDate().getTime(); long time2 = message2.getPayload().getPublishedDate().getTime(); long time3 = message3.getPayload().getPublishedDate().getTime(); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/AbstractRemoteFileStreamingMessageSource.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/AbstractRemoteFileStreamingMessageSource.java index 3edbed7ae1..b4b6757350 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/AbstractRemoteFileStreamingMessageSource.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/AbstractRemoteFileStreamingMessageSource.java @@ -37,6 +37,7 @@ import org.springframework.integration.file.filters.FileListFilter; import org.springframework.integration.file.filters.ReversibleFileListFilter; import org.springframework.integration.file.remote.session.Session; import org.springframework.integration.file.support.FileUtils; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessagingException; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -56,7 +57,7 @@ public abstract class AbstractRemoteFileStreamingMessageSource private final RemoteFileTemplate remoteFileTemplate; - private final BlockingQueue> toBeReceived = new LinkedBlockingQueue>(); + private final BlockingQueue> toBeReceived = new LinkedBlockingQueue<>(); private final Comparator comparator; @@ -65,24 +66,25 @@ public abstract class AbstractRemoteFileStreamingMessageSource /** * the path on the remote server. */ - private volatile Expression remoteDirectoryExpression; + private Expression remoteDirectoryExpression; - private volatile String remoteFileSeparator = "/"; + private String remoteFileSeparator = "/"; /** * An {@link FileListFilter} that runs against the remote file system view. */ - private volatile FileListFilter filter; + private FileListFilter filter; protected AbstractRemoteFileStreamingMessageSource(RemoteFileTemplate template, - Comparator comparator) { + @Nullable Comparator comparator) { + + Assert.notNull(template, "'template' must not be null"); this.remoteFileTemplate = template; this.comparator = comparator; } /** * Specify the full path to the remote directory. - * * @param remoteDirectory The remote directory. */ public void setRemoteDirectory(String remoteDirectory) { @@ -91,7 +93,6 @@ public abstract class AbstractRemoteFileStreamingMessageSource /** * Specify an expression that evaluates to the full path to the remote directory. - * * @param remoteDirectoryExpression The remote directory expression. */ public void setRemoteDirectoryExpression(Expression remoteDirectoryExpression) { @@ -183,10 +184,9 @@ public abstract class AbstractRemoteFileStreamingMessageSource } protected String remotePath(AbstractFileInfo file) { - String remotePath = file.getRemoteDirectory().endsWith(this.remoteFileSeparator) + return file.getRemoteDirectory().endsWith(this.remoteFileSeparator) ? file.getRemoteDirectory() + file.getFilename() : file.getRemoteDirectory() + this.remoteFileSeparator + file.getFilename(); - return remotePath; } private void listFiles() { @@ -219,8 +219,8 @@ public abstract class AbstractRemoteFileStreamingMessageSource } } - abstract protected List> asFileInfoList(Collection files); + protected abstract List> asFileInfoList(Collection files); - abstract protected boolean isDirectory(F file); + protected abstract boolean isDirectory(F file); } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java index 09b5bc38d7..8c3da6ff9b 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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,7 +27,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -53,6 +52,7 @@ import org.springframework.integration.handler.AbstractReplyProducingMessageHand import org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor; import org.springframework.integration.support.MutableMessage; import org.springframework.integration.support.PartialSuccessException; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandlingException; import org.springframework.messaging.MessagingException; @@ -70,185 +70,42 @@ import org.springframework.util.StringUtils; */ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReplyProducingMessageHandler { - protected final RemoteFileTemplate remoteFileTemplate; - protected final Command command; + protected final RemoteFileTemplate remoteFileTemplate; // NOSONAR - /** - * Enumeration of commands supported by the gateways. - */ - public enum Command { + protected final Command command; // NOSONAR - /** - * (ls) List remote files. - */ - LS("ls"), - - /** - * (nlst) List remote file names. - */ - NLST("nlst"), - - /** - * (get) Retrieve a remote file. - */ - GET("get"), - - /** - * (rm) Remove a remote file (path - including wildcards). - */ - RM("rm"), - - /** - * (mget) Retrieve multiple files matching a wildcard path. - */ - MGET("mget"), - - /** - * (mv) Move (rename) a remote file. - */ - MV("mv"), - - /** - * (put) Put a local file to the remote system. - */ - PUT("put"), - - /** - * (mput) Put multiple local files to the remote system. - */ - MPUT("mput"); - - private String command; - - Command(String command) { - this.command = command; - } - - public String getCommand() { - return this.command; - } - - public static Command toCommand(String cmd) { - for (Command command : values()) { - if (command.getCommand().equals(cmd)) { - return command; - } - } - throw new IllegalArgumentException("No Command with value '" + cmd + "'"); - } - - } - - /** - * Enumeration of options supported by various commands. - * - */ - public enum Option { - - /** - * (-1) Don't return full file information; just the name (ls). - */ - NAME_ONLY("-1"), - - /** - * (-a) Include files beginning with {@code .}, including directories {@code .} - * and {@code ..} in the results (ls). - */ - ALL("-a"), - - /** - * (-f) Do not sort the results (ls with NAME_ONLY). - */ - NOSORT("-f"), - - /** - * (-dirs) Include directories in the results (ls). - */ - SUBDIRS("-dirs"), - - /** - * (-links) Include links in the results (ls). - */ - LINKS("-links"), - - /** - * (-P) Preserve the server timestamp (get, mget). - */ - PRESERVE_TIMESTAMP("-P"), - - /** - * (-x) Throw an exception if no files returned (mget). - */ - EXCEPTION_WHEN_EMPTY("-x"), - - /** - * (-R) Recursive (ls, mget) - */ - RECURSIVE("-R"), - - /** - * (-stream) Streaming 'get' (returns InputStream); user must call {@link Session#close()}. - */ - STREAM("-stream"), - - /** - * (-D) Delete the remote file after successful transfer (get, mget). - */ - DELETE("-D"); - - private String option; - - Option(String option) { - this.option = option; - } - - public String getOption() { - return this.option; - } - - public static Option toOption(String opt) { - for (Option option : values()) { - if (option.getOption().equals(opt)) { - return option; - } - } - throw new IllegalArgumentException("No option with value '" + opt + "'"); - } - - } + protected final Set