From 6d7bc1fc392d3db5bf14c8c27f25f37b3488f37c Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 3 May 2019 12:39:02 -0400 Subject: [PATCH] Sonar: repeated literals * Polishing - PR Comments * GatewayParser: Restore suppress warnings; remove size from `toArray()`. * Merge conflict resolution --- .../IntegrationMessageHeaderAccessor.java | 20 +++--- .../config/xml/EnricherParser.java | 24 ++++--- .../integration/config/xml/GatewayParser.java | 13 ++-- .../xml/HeaderEnricherParserSupport.java | 10 +-- .../config/xml/IntegrationNamespaceUtils.java | 6 +- .../xml/PublishingInterceptorParser.java | 10 +-- .../ResourceInboundChannelAdapterParser.java | 10 +-- .../core/AsyncMessagingTemplate.java | 20 +++--- .../integration/dsl/HeaderEnricherSpec.java | 10 +-- .../dsl/IntegrationFlowDefinition.java | 32 +++++---- .../integration/history/MessageHistory.java | 23 ++++--- .../PropertiesPersistingMetadataStore.java | 12 ++-- .../store/AbstractKeyValueMessageStore.java | 14 ++-- .../integration/store/SimpleMessageStore.java | 36 +++++----- .../support/SmartLifecycleRoleController.java | 10 +-- ...TransactionSynchronizationFactoryBean.java | 23 ++++--- .../integration/ftp/session/FtpSession.java | 12 ++-- .../metadata/GemfireMetadataStore.java | 12 ++-- .../gemfire/store/GemfireMessageStore.java | 10 +-- .../jdbc/config/StoredProcParserUtils.java | 14 ++-- .../jdbc/metadata/JdbcMetadataStore.java | 12 ++-- ...DerbyChannelMessageStoreQueryProvider.java | 29 ++++---- .../H2ChannelMessageStoreQueryProvider.java | 22 +++---- .../HsqlChannelMessageStoreQueryProvider.java | 17 ++--- ...MySqlChannelMessageStoreQueryProvider.java | 20 +++--- ...racleChannelMessageStoreQueryProvider.java | 17 +++-- ...tgresChannelMessageStoreQueryProvider.java | 20 +++--- ...erverChannelMessageStoreQueryProvider.java | 20 +++--- .../metadata/MongoDbMetadataStore.java | 12 ++-- .../ConfigurableMongoDbMessageStore.java | 14 ++-- .../mongodb/store/MongoDbMessageStore.java | 66 +++++++++++-------- .../redis/metadata/RedisMetadataStore.java | 12 ++-- .../redis/store/RedisMessageStore.java | 10 +-- .../integration/sftp/session/SftpSession.java | 12 ++-- .../integration/test/mail/TestMailServer.java | 24 ++++--- .../test/context/MockIntegrationContext.java | 13 ++-- .../RegexTestXPathMessageSelector.java | 10 +-- .../metadata/ZookeeperMetadataStore.java | 12 ++-- 38 files changed, 382 insertions(+), 281 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/IntegrationMessageHeaderAccessor.java b/spring-integration-core/src/main/java/org/springframework/integration/IntegrationMessageHeaderAccessor.java index d9f5c40e81..86bab5119f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/IntegrationMessageHeaderAccessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/IntegrationMessageHeaderAccessor.java @@ -23,6 +23,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiFunction; import org.springframework.integration.acks.AcknowledgmentCallback; import org.springframework.lang.Nullable; @@ -66,6 +67,9 @@ public class IntegrationMessageHeaderAccessor extends MessageHeaderAccessor { public static final String ACKNOWLEDGMENT_CALLBACK = "acknowledgmentCallback"; + private static final BiFunction TYPE_VERIFY_MESSAGE_FUNCTION = + (name, trailer) -> "The '" + name + trailer; + private Set readOnlyHeaders = new HashSet<>(); public IntegrationMessageHeaderAccessor(@Nullable Message message) { @@ -168,22 +172,22 @@ public class IntegrationMessageHeaderAccessor extends MessageHeaderAccessor { if (headerName != null && headerValue != null) { super.verifyType(headerName, headerValue); if (IntegrationMessageHeaderAccessor.EXPIRATION_DATE.equals(headerName)) { - Assert.isTrue(headerValue instanceof Date || headerValue instanceof Long, "The '" + headerName - + "' header value must be a Date or Long."); + Assert.isTrue(headerValue instanceof Date || headerValue instanceof Long, + TYPE_VERIFY_MESSAGE_FUNCTION.apply(headerName, "' header value must be a Date or Long.")); } else if (IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER.equals(headerName) || IntegrationMessageHeaderAccessor.SEQUENCE_SIZE.equals(headerName) || IntegrationMessageHeaderAccessor.PRIORITY.equals(headerName)) { - Assert.isTrue(Number.class.isAssignableFrom(headerValue.getClass()), "The '" + headerName - + "' header value must be a Number."); + Assert.isTrue(Number.class.isAssignableFrom(headerValue.getClass()), + TYPE_VERIFY_MESSAGE_FUNCTION.apply(headerName, "' header value must be a Number.")); } else if (IntegrationMessageHeaderAccessor.ROUTING_SLIP.equals(headerName)) { - Assert.isTrue(Map.class.isAssignableFrom(headerValue.getClass()), "The '" + headerName - + "' header value must be a Map."); + Assert.isTrue(Map.class.isAssignableFrom(headerValue.getClass()), + TYPE_VERIFY_MESSAGE_FUNCTION.apply(headerName, "' header value must be a Map.")); } else if (IntegrationMessageHeaderAccessor.DUPLICATE_MESSAGE.equals(headerName)) { - Assert.isTrue(Boolean.class.isAssignableFrom(headerValue.getClass()), "The '" + headerName - + "' header value must be an Boolean."); + Assert.isTrue(Boolean.class.isAssignableFrom(headerValue.getClass()), + TYPE_VERIFY_MESSAGE_FUNCTION.apply(headerName, "' header value must be an Boolean.")); } } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java index c02cbddbdc..2e6d557972 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java @@ -47,6 +47,8 @@ import org.springframework.util.xml.DomUtils; */ public class EnricherParser extends AbstractConsumerEndpointParser { + private static final String TYPE_ATTRIBUTE = "type"; + @Override protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) { final BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ContentEnricher.class); @@ -65,8 +67,8 @@ public class EnricherParser extends AbstractConsumerEndpointParser { String name = subElement.getAttribute("name"); String value = subElement.getAttribute("value"); - String type = subElement.getAttribute("type"); - String expression = subElement.getAttribute("expression"); + String type = subElement.getAttribute(TYPE_ATTRIBUTE); + String expression = subElement.getAttribute(EXPRESSION_ATTRIBUTE); String nullResultExpression = subElement.getAttribute("null-result-expression"); boolean hasAttributeValue = StringUtils.hasText(value); boolean hasAttributeExpression = StringUtils.hasText(expression); @@ -131,13 +133,13 @@ public class EnricherParser extends AbstractConsumerEndpointParser { String name = subElement.getAttribute("name"); String nullResultHeaderExpression = subElement.getAttribute("null-result-expression"); String valueElementValue = subElement.getAttribute("value"); - String expressionElementValue = subElement.getAttribute("expression"); + String expressionElementValue = subElement.getAttribute(EXPRESSION_ATTRIBUTE); boolean hasAttributeValue = StringUtils.hasText(valueElementValue); boolean hasAttributeExpression = StringUtils.hasText(expressionElementValue); boolean hasAttributeNullResultExpression = StringUtils.hasText(nullResultHeaderExpression); if (hasAttributeValue && hasAttributeExpression) { parserContext.getReaderContext().error("Only one of '" + "value" + "' or '" - + "expression" + "' is allowed", subElement); + + EXPRESSION_ATTRIBUTE + "' is allowed", subElement); } if (!hasAttributeValue && !hasAttributeExpression && !hasAttributeNullResultExpression) { @@ -151,11 +153,12 @@ public class EnricherParser extends AbstractConsumerEndpointParser { } else if (hasAttributeExpression) { expressionDef = - IntegrationNamespaceUtils.createExpressionDefIfAttributeDefined("expression", subElement); + IntegrationNamespaceUtils.createExpressionDefIfAttributeDefined(EXPRESSION_ATTRIBUTE, + subElement); } - if (StringUtils.hasText(subElement.getAttribute("expression")) - && StringUtils.hasText(subElement.getAttribute("type"))) { + if (StringUtils.hasText(subElement.getAttribute(EXPRESSION_ATTRIBUTE)) + && StringUtils.hasText(subElement.getAttribute(TYPE_ATTRIBUTE))) { parserContext.getReaderContext() .warning("The use of a 'type' attribute is deprecated since 4.0 " + "when using 'expression'", subElement); @@ -164,8 +167,9 @@ public class EnricherParser extends AbstractConsumerEndpointParser { BeanDefinitionBuilder valueProcessorBuilder = BeanDefinitionBuilder .genericBeanDefinition(ExpressionEvaluatingHeaderValueMessageProcessor.class) .addConstructorArgValue(expressionDef) - .addConstructorArgValue(subElement.getAttribute("type")); - IntegrationNamespaceUtils.setValueIfAttributeDefined(valueProcessorBuilder, subElement, "overwrite"); + .addConstructorArgValue(subElement.getAttribute(TYPE_ATTRIBUTE)); + IntegrationNamespaceUtils.setValueIfAttributeDefined(valueProcessorBuilder, subElement, + "overwrite"); expressions.put(name, valueProcessorBuilder.getBeanDefinition()); } if (hasAttributeNullResultExpression) { @@ -174,7 +178,7 @@ public class EnricherParser extends AbstractConsumerEndpointParser { BeanDefinitionBuilder nullResultValueProcessorBuilder = BeanDefinitionBuilder .genericBeanDefinition(ExpressionEvaluatingHeaderValueMessageProcessor.class) .addConstructorArgValue(nullResultExpressionDefinition) - .addConstructorArgValue(subElement.getAttribute("type")); + .addConstructorArgValue(subElement.getAttribute(TYPE_ATTRIBUTE)); IntegrationNamespaceUtils.setValueIfAttributeDefined(nullResultValueProcessorBuilder, subElement, "overwrite"); nullResultHeaderExpressions.put(name, nullResultValueProcessorBuilder.getBeanDefinition()); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GatewayParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GatewayParser.java index faa6664d84..73950101c8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GatewayParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GatewayParser.java @@ -56,7 +56,8 @@ public class GatewayParser implements BeanDefinitionParser { boolean isNested = parserContext.isNested(); final Map gatewayAttributes = new HashMap(); - gatewayAttributes.put("name", element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE)); + gatewayAttributes.put(AbstractBeanDefinitionParser.NAME_ATTRIBUTE, + element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE)); gatewayAttributes.put("defaultPayloadExpression", element.getAttribute("default-payload-expression")); gatewayAttributes.put("defaultRequestChannel", element.getAttribute(isNested ? "request-channel" : "default-request-channel")); @@ -84,19 +85,20 @@ public class GatewayParser implements BeanDefinitionParser { List> headers = new ArrayList>(headerElements.size()); for (Element e : headerElements) { Map header = new HashMap(); - header.put("name", e.getAttribute("name")); + header.put(AbstractBeanDefinitionParser.NAME_ATTRIBUTE, + e.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE)); header.put("value", e.getAttribute("value")); header.put("expression", e.getAttribute("expression")); headers.add(header); } - gatewayAttributes.put("defaultHeaders", headers.toArray(new Map[headers.size()])); + gatewayAttributes.put("defaultHeaders", headers.toArray(new Map[0])); } List methodElements = DomUtils.getChildElementsByTagName(element, "method"); if (!CollectionUtils.isEmpty(methodElements)) { Map methodMetadataMap = new ManagedMap(); for (Element methodElement : methodElements) { - String methodName = methodElement.getAttribute("name"); + String methodName = methodElement.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE); BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition( GatewayMethodMetadata.class); methodMetadataBuilder.addPropertyValue("requestChannelName", @@ -122,7 +124,8 @@ public class GatewayParser implements BeanDefinitionParser { .createExpressionDefinitionFromValueOrExpression("value", "expression", parserContext, headerElement, true); - headerExpressions.put(headerElement.getAttribute("name"), expressionDef); + headerExpressions.put(headerElement.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE), + expressionDef); } methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java index 17fe50b1a3..6cfbd5b75d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java @@ -55,6 +55,8 @@ import org.springframework.util.xml.DomUtils; */ public abstract class HeaderEnricherParserSupport extends AbstractTransformerParser { + private static final String TYPE_ATTRIBUTE = "type"; + private static final Map cannedHeaderElementExpressions = new HashMap<>(); // NOSONAR lower case private final Map elementToNameMap = new HashMap<>(); @@ -114,14 +116,14 @@ public abstract class HeaderEnricherParserSupport extends AbstractTransformerPar else { headerName = this.elementToNameMap.get(elementName); headerType = this.elementToTypeMap.get(elementName); - if (headerType != null && StringUtils.hasText(headerElement.getAttribute("type"))) { + if (headerType != null && StringUtils.hasText(headerElement.getAttribute(TYPE_ATTRIBUTE))) { parserContext.getReaderContext().error("The " + elementName + " header does not accept a 'type' attribute. The required type is [" + headerType + "]", element); } } if (headerType == null) { - headerType = headerElement.getAttribute("type"); + headerType = headerElement.getAttribute(TYPE_ATTRIBUTE); } if (headerName == null) { String ttlExpression = headerElement.getAttribute("time-to-live-expression"); @@ -261,7 +263,7 @@ public abstract class HeaderEnricherParserSupport extends AbstractTransformerPar valueProcessorBuilder.addConstructorArgValue(headerType); } else if (isCustomBean) { - if (StringUtils.hasText(headerElement.getAttribute("type"))) { + if (StringUtils.hasText(headerElement.getAttribute(TYPE_ATTRIBUTE))) { parserContext.getReaderContext().error( "The 'type' attribute cannot be used with an inner bean.", element); } @@ -280,7 +282,7 @@ public abstract class HeaderEnricherParserSupport extends AbstractTransformerPar } } else { - if (StringUtils.hasText(headerElement.getAttribute("type"))) { + if (StringUtils.hasText(headerElement.getAttribute(TYPE_ATTRIBUTE))) { parserContext.getReaderContext().error( "The 'type' attribute cannot be used with the 'ref' attribute.", element); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java index 420c924fa7..f009c405a1 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java @@ -255,7 +255,7 @@ public abstract class IntegrationNamespaceUtils { public static void configurePollerMetadata(Element pollerElement, BeanDefinitionBuilder targetBuilder, ParserContext parserContext) { - if (pollerElement.hasAttribute("ref")) { + if (pollerElement.hasAttribute(REF_ATTRIBUTE)) { int numberOfAttributes = pollerElement.getAttributes().getLength(); if (numberOfAttributes != 1) { /* @@ -273,7 +273,7 @@ public abstract class IntegrationNamespaceUtils { parserContext.getReaderContext().error( "A 'poller' element that provides a 'ref' must have no child elements.", pollerElement); } - targetBuilder.addPropertyReference("pollerMetadata", pollerElement.getAttribute("ref")); + targetBuilder.addPropertyReference("pollerMetadata", pollerElement.getAttribute(REF_ATTRIBUTE)); } else { BeanDefinition beanDefinition = parserContext.getDelegate().parseCustomElement(pollerElement, @@ -519,7 +519,7 @@ public abstract class IntegrationNamespaceUtils { parserContext.registerBeanComponent(new BeanComponentDefinition(holder)); // NOSONAR never null adviceChain.add(new RuntimeBeanReference(holder.getBeanName())); } - else if ("ref".equals(localName)) { + else if (REF_ATTRIBUTE.equals(localName)) { String ref = childElement.getAttribute("bean"); adviceChain.add(new RuntimeBeanReference(ref)); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PublishingInterceptorParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PublishingInterceptorParser.java index 4934add6f0..7797696a3c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PublishingInterceptorParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PublishingInterceptorParser.java @@ -46,6 +46,8 @@ import org.springframework.util.xml.DomUtils; */ public class PublishingInterceptorParser extends AbstractBeanDefinitionParser { + private static final String PAYLOAD = "payload"; + @Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder rootBuilder = BeanDefinitionBuilder.genericBeanDefinition( @@ -54,7 +56,7 @@ public class PublishingInterceptorParser extends AbstractBeanDefinitionParser { .genericBeanDefinition(MethodNameMappingPublisherMetadataSource.class); Map> mappings = this .getMappings(element, element.getAttribute("default-channel"), parserContext); - spelSourceBuilder.addConstructorArgValue(mappings.get("payload")); + spelSourceBuilder.addConstructorArgValue(mappings.get(PAYLOAD)); if (mappings.get("headers") != null) { spelSourceBuilder.addPropertyValue("headerExpressionMap", mappings.get("headers")); } @@ -81,8 +83,8 @@ public class PublishingInterceptorParser extends AbstractBeanDefinitionParser { // set payloadMap String methodPattern = StringUtils.hasText(mapping.getAttribute("pattern")) ? mapping.getAttribute("pattern") : "*"; - String payloadExpression = StringUtils.hasText(mapping.getAttribute("payload")) ? - mapping.getAttribute("payload") : "#return"; + String payloadExpression = StringUtils.hasText(mapping.getAttribute(PAYLOAD)) ? + mapping.getAttribute(PAYLOAD) : "#return"; payloadExpressionMap.put(methodPattern, payloadExpression); // set headersMap @@ -125,7 +127,7 @@ public class PublishingInterceptorParser extends AbstractBeanDefinitionParser { if (payloadExpressionMap.size() == 0) { payloadExpressionMap.put("*", "#return"); } - interceptorMappings.put("payload", payloadExpressionMap); + interceptorMappings.put(PAYLOAD, payloadExpressionMap); if (headersExpressionMap.size() > 0) { interceptorMappings.put("headers", headersExpressionMap); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ResourceInboundChannelAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ResourceInboundChannelAdapterParser.java index 50253c6118..c72e4771c2 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ResourceInboundChannelAdapterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ResourceInboundChannelAdapterParser.java @@ -29,26 +29,28 @@ import org.springframework.util.StringUtils; * Parser for 'resource-inbound-channel-adapter' * * @author Oleg Zhurakousky + * @author Gary Russell * @since 2.1 */ public class ResourceInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser { + private static final String FILTER = "filter"; @Override protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) { BeanDefinitionBuilder sourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(ResourceRetrievingMessageSource.class); sourceBuilder.addConstructorArgValue(element.getAttribute("pattern")); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(sourceBuilder, element, "pattern-resolver"); - boolean hasFilter = element.hasAttribute("filter"); + boolean hasFilter = element.hasAttribute(FILTER); if (hasFilter) { - String filterValue = element.getAttribute("filter"); + String filterValue = element.getAttribute(FILTER); if (StringUtils.hasText(filterValue)) { - sourceBuilder.addPropertyReference("filter", filterValue); + sourceBuilder.addPropertyReference(FILTER, filterValue); } } else { BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder.genericBeanDefinition(AcceptOnceCollectionFilter.class); - sourceBuilder.addPropertyValue("filter", filterBuilder.getBeanDefinition()); + sourceBuilder.addPropertyValue(FILTER, filterBuilder.getBeanDefinition()); } return sourceBuilder.getBeanDefinition(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/core/AsyncMessagingTemplate.java b/spring-integration-core/src/main/java/org/springframework/integration/core/AsyncMessagingTemplate.java index eea346ed7f..fe821bccc3 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/core/AsyncMessagingTemplate.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/core/AsyncMessagingTemplate.java @@ -35,6 +35,8 @@ import org.springframework.util.Assert; */ public class AsyncMessagingTemplate extends MessagingTemplate implements AsyncMessagingOperations { + private static final String UNCHECKED = "unchecked"; + private volatile AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(); @@ -90,19 +92,19 @@ public class AsyncMessagingTemplate extends MessagingTemplate implements AsyncMe } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) public Future asyncReceiveAndConvert() { return this.executor.submit(() -> (R) receiveAndConvert(Object.class)); } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) public Future asyncReceiveAndConvert(final PollableChannel channel) { return this.executor.submit(() -> (R) receiveAndConvert(channel, Object.class)); } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) public Future asyncReceiveAndConvert(final String channelName) { return this.executor.submit(() -> (R) receiveAndConvert(channelName, Object.class)); } @@ -123,32 +125,32 @@ public class AsyncMessagingTemplate extends MessagingTemplate implements AsyncMe } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) public Future asyncConvertSendAndReceive(final Object request) { return this.executor.submit(() -> (R) convertSendAndReceive(request, Object.class)); } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) public Future asyncConvertSendAndReceive(final MessageChannel channel, final Object request) { return this.executor.submit(() -> (R) convertSendAndReceive(channel, request, Object.class)); } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) public Future asyncConvertSendAndReceive(final String channelName, final Object request) { return this.executor.submit(() -> (R) convertSendAndReceive(channelName, request, Object.class)); } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) public Future asyncConvertSendAndReceive(final Object request, final MessagePostProcessor requestPostProcessor) { return this.executor.submit(() -> (R) convertSendAndReceive(request, Object.class, requestPostProcessor)); } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) public Future asyncConvertSendAndReceive(final MessageChannel channel, final Object request, final MessagePostProcessor requestPostProcessor) { return this.executor @@ -156,7 +158,7 @@ public class AsyncMessagingTemplate extends MessagingTemplate implements AsyncMe } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) public Future asyncConvertSendAndReceive(final String channelName, final Object request, final MessagePostProcessor requestPostProcessor) { return this.executor diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/HeaderEnricherSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/HeaderEnricherSpec.java index a206579977..e3f162c3fa 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/HeaderEnricherSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/HeaderEnricherSpec.java @@ -56,6 +56,8 @@ import reactor.util.function.Tuple2; */ public class HeaderEnricherSpec extends ConsumerEndpointSpec { + private static final String HEADERS_MUST_NOT_BE_NULL = "'headers' must not be null"; + private final Map> headerToAdd = new HashMap<>(); private final HeaderEnricher headerEnricher = new HeaderEnricher(this.headerToAdd); @@ -150,7 +152,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec headers, Boolean overwrite) { - Assert.notNull(headers, "'headers' must not be null"); + Assert.notNull(headers, HEADERS_MUST_NOT_BE_NULL); return headers(headers.get(), overwrite); } @@ -176,7 +178,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec headers, Boolean overwrite) { - Assert.notNull(headers, "'headers' must not be null"); + Assert.notNull(headers, HEADERS_MUST_NOT_BE_NULL); for (Entry entry : headers.entrySet()) { String name = entry.getKey(); Object value = entry.getValue(); @@ -214,7 +216,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec headers, Boolean overwrite) { - Assert.notNull(headers, "'headers' must not be null"); + Assert.notNull(headers, HEADERS_MUST_NOT_BE_NULL); return headerExpressions(headers.get(), overwrite); } @@ -283,7 +285,7 @@ public class HeaderEnricherSpec extends ConsumerEndpointSpec headers, Boolean overwrite) { - Assert.notNull(headers, "'headers' must not be null"); + Assert.notNull(headers, HEADERS_MUST_NOT_BE_NULL); for (Entry entry : headers.entrySet()) { AbstractHeaderValueMessageProcessor processor = new ExpressionEvaluatingHeaderValueMessageProcessor<>(entry.getValue(), null); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java index 4288e6a7b6..9972af1610 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java @@ -115,6 +115,12 @@ import reactor.util.function.Tuple2; */ public abstract class IntegrationFlowDefinition> { + private static final String UNCHECKED = "unchecked"; + + private static final String FUNCTION_MUST_NOT_BE_NULL = "'function' must not be null"; + + private static final String MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL = "'messageProcessorSpec' must not be null"; + private static final SpelExpressionParser PARSER = new SpelExpressionParser(); private static final Set REFERENCED_REPLY_PRODUCERS = new HashSet<>(); @@ -582,7 +588,7 @@ public abstract class IntegrationFlowDefinition messageProcessorSpec, Consumer> endpointConfigurer) { - Assert.notNull(messageProcessorSpec, "'messageProcessorSpec' must not be null"); + Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); MessageProcessor processor = messageProcessorSpec.get(); return addComponent(processor) .transform(new MethodInvokingTransformer(processor), endpointConfigurer); @@ -814,7 +820,7 @@ public abstract class IntegrationFlowDefinition messageProcessorSpec, Consumer endpointConfigurer) { - Assert.notNull(messageProcessorSpec, "'messageProcessorSpec' must not be null"); + Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); MessageProcessor processor = messageProcessorSpec.get(); return addComponent(processor) .filter(new MethodInvokingSelector(processor), endpointConfigurer); @@ -1133,7 +1139,7 @@ public abstract class IntegrationFlowDefinition messageProcessorSpec, Consumer> endpointConfigurer) { - Assert.notNull(messageProcessorSpec, "'messageProcessorSpec' must not be null"); + Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); MessageProcessor processor = messageProcessorSpec.get(); return addComponent(processor) .handle(new ServiceActivatingHandler(processor), endpointConfigurer); @@ -1518,7 +1524,7 @@ public abstract class IntegrationFlowDefinition messageProcessorSpec, Consumer> endpointConfigurer) { - Assert.notNull(messageProcessorSpec, "'messageProcessorSpec' must not be null"); + Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); MessageProcessor processor = messageProcessorSpec.get(); return addComponent(processor) .split(new MethodInvokingSplitter(processor), endpointConfigurer); @@ -2056,7 +2062,7 @@ public abstract class IntegrationFlowDefinition messageProcessorSpec, Consumer> routerConfigurer) { - Assert.notNull(messageProcessorSpec, "'messageProcessorSpec' must not be null"); + Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); MessageProcessor processor = messageProcessorSpec.get(); addComponent(processor); @@ -2371,7 +2377,7 @@ public abstract class IntegrationFlowDefinition B log(Function, Object> function) { - Assert.notNull(function, "'function' must not be null"); + Assert.notNull(function, FUNCTION_MUST_NOT_BE_NULL); return log(new FunctionExpression<>(function)); } @@ -2488,7 +2494,7 @@ public abstract class IntegrationFlowDefinition B log(LoggingHandler.Level level, String category, Function, Object> function) { - Assert.notNull(function, "'function' must not be null"); + Assert.notNull(function, FUNCTION_MUST_NOT_BE_NULL); return log(level, category, new FunctionExpression<>(function)); } @@ -2632,7 +2638,7 @@ public abstract class IntegrationFlowDefinition IntegrationFlow logAndReply(Function, Object> function) { - Assert.notNull(function, "'function' must not be null"); + Assert.notNull(function, FUNCTION_MUST_NOT_BE_NULL); return logAndReply(new FunctionExpression<>(function)); } @@ -2757,7 +2763,7 @@ public abstract class IntegrationFlowDefinition IntegrationFlow logAndReply(LoggingHandler.Level level, String category, Function, Object> function) { - Assert.notNull(function, "'function' must not be null"); + Assert.notNull(function, FUNCTION_MUST_NOT_BE_NULL); return logAndReply(level, category, new FunctionExpression<>(function)); } @@ -2961,7 +2967,7 @@ public abstract class IntegrationFlowDefinition the output type. * @return the current {@link IntegrationFlowDefinition}. */ - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) public B fluxTransform(Function>, ? extends Publisher> fluxFunction) { if (!(this.currentMessageChannel instanceof FluxMessageChannel)) { channel(new FluxMessageChannel()); @@ -2984,7 +2990,7 @@ public abstract class IntegrationFlowDefinition the expected {@code payload} type * @return the Reactive Streams {@link Publisher} */ - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) public Publisher> toReactivePublisher() { MessageChannel channelForPublisher = this.currentMessageChannel; Publisher> publisher; @@ -3022,7 +3028,7 @@ public abstract class IntegrationFlowDefinition> B register(S endpointSpec, Consumer endpointConfigurer) { @@ -3113,7 +3119,7 @@ public abstract class IntegrationFlowDefinition, Serializable { private static final Log logger = LogFactory.getLog(MessageHistory.class); + private static final UnsupportedOperationException UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE = + new UnsupportedOperationException("MessageHistory is immutable."); + public static final String HEADER_NAME = "history"; public static final String NAME_PROPERTY = "name"; @@ -215,52 +218,52 @@ public final class MessageHistory implements List, Serializable { @Override public boolean add(Properties e) { - throw new UnsupportedOperationException("MessageHistory is immutable."); + throw UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE; } @Override public void add(int index, Properties element) { - throw new UnsupportedOperationException("MessageHistory is immutable."); + throw UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE; } @Override public boolean addAll(Collection c) { - throw new UnsupportedOperationException("MessageHistory is immutable."); + throw UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE; } @Override public boolean addAll(int index, Collection c) { - throw new UnsupportedOperationException("MessageHistory is immutable."); + throw UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE; } @Override public Properties set(int index, Properties element) { - throw new UnsupportedOperationException("MessageHistory is immutable."); + throw UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE; } @Override public Properties remove(int index) { - throw new UnsupportedOperationException("MessageHistory is immutable."); + throw UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE; } @Override public boolean remove(Object o) { - throw new UnsupportedOperationException("MessageHistory is immutable."); + throw UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE; } @Override public boolean removeAll(Collection c) { - throw new UnsupportedOperationException("MessageHistory is immutable."); + throw UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE; } @Override public boolean retainAll(Collection c) { - throw new UnsupportedOperationException("MessageHistory is immutable."); + throw UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE; } @Override public void clear() { - throw new UnsupportedOperationException("MessageHistory is immutable."); + throw UNSUPPORTED_OPERATION_EXCEPTION_IMMUTABLE; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java b/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java index 5776c0646b..2b5aa0739c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java @@ -55,6 +55,8 @@ import org.springframework.util.DefaultPropertiesPersister; public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStore, InitializingBean, DisposableBean, Closeable, Flushable { + private static final String KEY_CANNOT_BE_NULL = "'key' cannot be null"; + private final Log logger = LogFactory.getLog(getClass()); private final Properties metadata = new Properties(); @@ -111,7 +113,7 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor @Override public void put(String key, String value) { - Assert.notNull(key, "'key' cannot be null"); + Assert.notNull(key, KEY_CANNOT_BE_NULL); Assert.notNull(value, "'value' cannot be null"); Lock lock = this.lockRegistry.obtain(key); lock.lock(); @@ -126,7 +128,7 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor @Override public String get(String key) { - Assert.notNull(key, "'key' cannot be null"); + Assert.notNull(key, KEY_CANNOT_BE_NULL); Lock lock = this.lockRegistry.obtain(key); lock.lock(); try { @@ -139,7 +141,7 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor @Override public String remove(String key) { - Assert.notNull(key, "'key' cannot be null"); + Assert.notNull(key, KEY_CANNOT_BE_NULL); Lock lock = this.lockRegistry.obtain(key); lock.lock(); try { @@ -153,7 +155,7 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor @Override public String putIfAbsent(String key, String value) { - Assert.notNull(key, "'key' cannot be null"); + Assert.notNull(key, KEY_CANNOT_BE_NULL); Assert.notNull(value, "'value' cannot be null"); Lock lock = this.lockRegistry.obtain(key); lock.lock(); @@ -175,7 +177,7 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor @Override public boolean replace(String key, String oldValue, String newValue) { - Assert.notNull(key, "'key' cannot be null"); + Assert.notNull(key, KEY_CANNOT_BE_NULL); Assert.notNull(oldValue, "'oldValue' cannot be null"); Assert.notNull(newValue, "'newValue' cannot be null"); Lock lock = this.lockRegistry.obtain(key); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractKeyValueMessageStore.java b/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractKeyValueMessageStore.java index 10a145c4b0..d7f8aa0c2f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractKeyValueMessageStore.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractKeyValueMessageStore.java @@ -40,6 +40,8 @@ import org.springframework.util.Assert; */ public abstract class AbstractKeyValueMessageStore extends AbstractMessageGroupStore implements MessageStore { + private static final String GROUP_ID_MUST_NOT_BE_NULL = "'groupId' must not be null"; + protected static final String MESSAGE_KEY_PREFIX = "MESSAGE_"; protected static final String MESSAGE_GROUP_KEY_PREFIX = "MESSAGE_GROUP_"; @@ -193,7 +195,7 @@ public abstract class AbstractKeyValueMessageStore extends AbstractMessageGroupS @Override public MessageGroupMetadata getGroupMetadata(Object groupId) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Object mgm = this.doRetrieve(this.groupPrefix + groupId); if (mgm != null) { Assert.isInstanceOf(MessageGroupMetadata.class, mgm); @@ -204,7 +206,7 @@ public abstract class AbstractKeyValueMessageStore extends AbstractMessageGroupS @Override public void addMessagesToGroup(Object groupId, Message... messages) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Assert.notNull(messages, "'messages' must not be null"); MessageGroupMetadata metadata = getGroupMetadata(groupId); @@ -239,7 +241,7 @@ public abstract class AbstractKeyValueMessageStore extends AbstractMessageGroupS @Override public void removeMessagesFromGroup(Object groupId, Collection> messages) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Assert.notNull(messages, "'messages' must not be null"); Object mgm = doRetrieve(this.groupPrefix + groupId); @@ -268,7 +270,7 @@ public abstract class AbstractKeyValueMessageStore extends AbstractMessageGroupS @Override public void completeGroup(Object groupId) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); MessageGroupMetadata metadata = getGroupMetadata(groupId); if (metadata != null) { metadata.complete(); @@ -282,7 +284,7 @@ public abstract class AbstractKeyValueMessageStore extends AbstractMessageGroupS */ @Override public void removeMessageGroup(Object groupId) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Object mgm = doRemove(this.groupPrefix + groupId); if (mgm != null) { Assert.isInstanceOf(MessageGroupMetadata.class, mgm); @@ -300,7 +302,7 @@ public abstract class AbstractKeyValueMessageStore extends AbstractMessageGroupS @Override public void setLastReleasedSequenceNumberForGroup(Object groupId, int sequenceNumber) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); MessageGroupMetadata metadata = getGroupMetadata(groupId); if (metadata == null) { SimpleMessageGroup messageGroup = new SimpleMessageGroup(groupId); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/store/SimpleMessageStore.java b/spring-integration-core/src/main/java/org/springframework/integration/store/SimpleMessageStore.java index 2d06d94dc9..bbc021173a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/store/SimpleMessageStore.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/store/SimpleMessageStore.java @@ -50,6 +50,12 @@ import org.springframework.util.CollectionUtils; public class SimpleMessageStore extends AbstractMessageGroupStore implements MessageStore, ChannelMessageStore { + private static final String MESSAGE_GROUP_FOR_GROUP_ID = "MessageGroup for groupId '"; + + private static final String UPPER_BOUND_MUST_NOT_BE_NULL = "'upperBound' must not be null."; + + private static final String INTERRUPTED_WHILE_OBTAINING_LOCK = "Interrupted while obtaining lock"; + private final ConcurrentMap> idToMessage = new ConcurrentHashMap>(); private final ConcurrentMap groupIdToMessageGroup = @@ -256,7 +262,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new MessagingException("Interrupted while obtaining lock", e); + throw new MessagingException(INTERRUPTED_WHILE_OBTAINING_LOCK, e); } } @@ -291,7 +297,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore } else { upperBound = this.groupToUpperBound.get(groupId); - Assert.state(upperBound != null, "'upperBound' must not be null."); + Assert.state(upperBound != null, UPPER_BOUND_MUST_NOT_BE_NULL); for (Message message : messages) { lock.unlock(); if (!upperBound.tryAcquire(this.upperBoundTimeout)) { @@ -313,7 +319,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new MessagingException("Interrupted while obtaining lock", e); + throw new MessagingException(INTERRUPTED_WHILE_OBTAINING_LOCK, e); } } @@ -326,7 +332,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore MessageGroup messageGroup = this.groupIdToMessageGroup.remove(groupId); if (messageGroup != null) { UpperBound upperBound = this.groupToUpperBound.remove(groupId); - Assert.state(upperBound != null, "'upperBound' must not be null."); + Assert.state(upperBound != null, UPPER_BOUND_MUST_NOT_BE_NULL); upperBound.release(this.groupCapacity); } } @@ -336,7 +342,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new MessagingException("Interrupted while obtaining lock", e); + throw new MessagingException(INTERRUPTED_WHILE_OBTAINING_LOCK, e); } } @@ -347,10 +353,10 @@ public class SimpleMessageStore extends AbstractMessageGroupStore lock.lockInterruptibly(); try { MessageGroup group = this.groupIdToMessageGroup.get(groupId); - Assert.notNull(group, "MessageGroup for groupId '" + groupId + "' " + + Assert.notNull(group, MESSAGE_GROUP_FOR_GROUP_ID + groupId + "' " + "can not be located while attempting to remove Message(s) from the MessageGroup"); UpperBound upperBound = this.groupToUpperBound.get(groupId); - Assert.state(upperBound != null, "'upperBound' must not be null."); + Assert.state(upperBound != null, UPPER_BOUND_MUST_NOT_BE_NULL); boolean modified = false; for (Message messageToRemove : messages) { if (group.remove(messageToRemove)) { @@ -368,7 +374,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new MessagingException("Interrupted while obtaining lock", e); + throw new MessagingException(INTERRUPTED_WHILE_OBTAINING_LOCK, e); } } @@ -384,7 +390,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore lock.lockInterruptibly(); try { MessageGroup group = this.groupIdToMessageGroup.get(groupId); - Assert.notNull(group, "MessageGroup for groupId '" + groupId + "' " + + Assert.notNull(group, MESSAGE_GROUP_FOR_GROUP_ID + groupId + "' " + "can not be located while attempting to set 'lastReleasedSequenceNumber'"); group.setLastReleasedMessageSequenceNumber(sequenceNumber); group.setLastModified(System.currentTimeMillis()); @@ -395,7 +401,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new MessagingException("Interrupted while obtaining lock", e); + throw new MessagingException(INTERRUPTED_WHILE_OBTAINING_LOCK, e); } } @@ -406,7 +412,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore lock.lockInterruptibly(); try { MessageGroup group = this.groupIdToMessageGroup.get(groupId); - Assert.notNull(group, "MessageGroup for groupId '" + groupId + "' " + + Assert.notNull(group, MESSAGE_GROUP_FOR_GROUP_ID + groupId + "' " + "can not be located while attempting to complete the MessageGroup"); group.complete(); group.setLastModified(System.currentTimeMillis()); @@ -417,7 +423,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new MessagingException("Interrupted while obtaining lock", e); + throw new MessagingException(INTERRUPTED_WHILE_OBTAINING_LOCK, e); } } @@ -460,12 +466,12 @@ public class SimpleMessageStore extends AbstractMessageGroupStore lock.lockInterruptibly(); try { MessageGroup group = this.groupIdToMessageGroup.get(groupId); - Assert.notNull(group, "MessageGroup for groupId '" + groupId + "' " + + Assert.notNull(group, MESSAGE_GROUP_FOR_GROUP_ID + groupId + "' " + "can not be located while attempting to complete the MessageGroup"); group.clear(); group.setLastModified(System.currentTimeMillis()); UpperBound upperBound = this.groupToUpperBound.get(groupId); - Assert.state(upperBound != null, "'upperBound' must not be null."); + Assert.state(upperBound != null, UPPER_BOUND_MUST_NOT_BE_NULL); upperBound.release(this.groupCapacity); } finally { @@ -474,7 +480,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new MessagingException("Interrupted while obtaining lock", e); + throw new MessagingException(INTERRUPTED_WHILE_OBTAINING_LOCK, e); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java b/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java index 964107d014..3c609c87c8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java @@ -59,6 +59,8 @@ import org.springframework.util.MultiValueMap; public class SmartLifecycleRoleController implements ApplicationListener, ApplicationContextAware { + private static final String IN_ROLE = " in role "; + private static final Log logger = LogFactory.getLog(SmartLifecycleRoleController.class); private final MultiValueMap lifecycles = new LinkedMultiValueMap(); @@ -162,7 +164,7 @@ public class SmartLifecycleRoleController implements ApplicationListener(componentsInRole); componentsInRole.sort(Comparator.comparingInt(Phased::getPhase)); if (logger.isDebugEnabled()) { - logger.debug("Starting " + componentsInRole + " in role " + role); + logger.debug("Starting " + componentsInRole + IN_ROLE + role); } componentsInRole.forEach(lifecycle -> { @@ -170,7 +172,7 @@ public class SmartLifecycleRoleController implements ApplicationListener(componentsInRole); componentsInRole.sort((o1, o2) -> Integer.compare(o2.getPhase(), o1.getPhase())); if (logger.isDebugEnabled()) { - logger.debug("Stopping " + componentsInRole + " in role " + role); + logger.debug("Stopping " + componentsInRole + IN_ROLE + role); } componentsInRole.forEach(lifecycle -> { @@ -202,7 +204,7 @@ public class SmartLifecycleRoleController implements ApplicationListener, BeanFactoryAware { + private static final String EXPRESSION_OR_CHANNEL_NEEDED = + "At least one attribute ('expression' and/or 'messageChannel') must be defined"; + private static final SpelExpressionParser PARSER = new SpelExpressionParser(); private final AtomicInteger counter = new AtomicInteger(); @@ -77,13 +80,13 @@ public class TransactionSynchronizationFactoryBean implements FactoryBean channelResolver) { - Assert.notNull(channelResolver, "'channelResolver' must not be null"); - this.channelResolver = channelResolver; + public TransactionSynchronizationFactoryBean channelResolver(DestinationResolver resolver) { + Assert.notNull(resolver, "'channelResolver' must not be null"); + this.channelResolver = resolver; return this; } @@ -94,7 +97,7 @@ public class TransactionSynchronizationFactoryBean implements FactoryBean { + private static final String SERVER_REPLIED_WITH = "'. Server replied with: "; + private final Log logger = LogFactory.getLog(this.getClass()); private final FTPClient client; @@ -58,7 +60,7 @@ public class FtpSession implements Session { public boolean remove(String path) throws IOException { Assert.hasText(path, "path must not be null"); if (!this.client.deleteFile(path)) { - throw new IOException("Failed to delete '" + path + "'. Server replied with: " + this.client.getReplyString()); + throw new IOException("Failed to delete '" + path + SERVER_REPLIED_WITH + this.client.getReplyString()); } else { return true; @@ -82,7 +84,7 @@ public class FtpSession implements Session { boolean completed = this.client.retrieveFile(path, fos); if (!completed) { throw new IOException("Failed to copy '" + path + - "'. Server replied with: " + this.client.getReplyString()); + SERVER_REPLIED_WITH + this.client.getReplyString()); } this.logger.info("File has been successfully transferred from: " + path); } @@ -122,7 +124,7 @@ public class FtpSession implements Session { boolean completed = this.client.storeFile(path, inputStream); if (!completed) { throw new IOException("Failed to write to '" + path - + "'. Server replied with: " + this.client.getReplyString()); + + SERVER_REPLIED_WITH + this.client.getReplyString()); } if (this.logger.isInfoEnabled()) { this.logger.info("File has been successfully transferred to: " + path); @@ -136,7 +138,7 @@ public class FtpSession implements Session { boolean completed = this.client.appendFile(path, inputStream); if (!completed) { throw new IOException("Failed to append to '" + path - + "'. Server replied with: " + this.client.getReplyString()); + + SERVER_REPLIED_WITH + this.client.getReplyString()); } if (this.logger.isInfoEnabled()) { this.logger.info("File has been successfully appended to: " + path); @@ -179,7 +181,7 @@ public class FtpSession implements Session { boolean completed = this.client.rename(pathFrom, pathTo); if (!completed) { throw new IOException("Failed to rename '" + pathFrom + - "' to " + pathTo + "'. Server replied with: " + this.client.getReplyString()); + "' to " + pathTo + SERVER_REPLIED_WITH + this.client.getReplyString()); } if (this.logger.isInfoEnabled()) { this.logger.info("File has been successfully renamed from: " + pathFrom + " to " + pathTo); diff --git a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/metadata/GemfireMetadataStore.java b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/metadata/GemfireMetadataStore.java index 7a725b85ad..0bc8ee1079 100644 --- a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/metadata/GemfireMetadataStore.java +++ b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/metadata/GemfireMetadataStore.java @@ -44,6 +44,8 @@ import org.springframework.util.Assert; */ public class GemfireMetadataStore implements ListenableMetadataStore { + private static final String KEY_MUST_NOT_BE_NULL = "'key' must not be null."; + public static final String KEY = "MetaData"; private final GemfireCacheListener cacheListener = new GemfireCacheListener(); @@ -66,21 +68,21 @@ public class GemfireMetadataStore implements ListenableMetadataStore { @Override public void put(String key, String value) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(value, "'value' must not be null."); this.region.put(key, value); } @Override public String putIfAbsent(String key, String value) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(value, "'value' must not be null."); return this.region.putIfAbsent(key, value); } @Override public boolean replace(String key, String oldValue, String newValue) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(oldValue, "'oldValue' must not be null."); Assert.notNull(newValue, "'newValue' must not be null."); return this.region.replace(key, oldValue, newValue); @@ -88,13 +90,13 @@ public class GemfireMetadataStore implements ListenableMetadataStore { @Override public String get(String key) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); return this.region.get(key); } @Override public String remove(String key) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); return this.region.remove(key); } diff --git a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/GemfireMessageStore.java b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/GemfireMessageStore.java index 7b3aebd6e1..966a3bcaa2 100644 --- a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/GemfireMessageStore.java +++ b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/GemfireMessageStore.java @@ -41,6 +41,8 @@ import org.springframework.util.PatternMatchUtils; */ public class GemfireMessageStore extends AbstractKeyValueMessageStore { + private static final String ID_MUST_NOT_BE_NULL = "'id' must not be null"; + private final Region messageStoreRegion; /** @@ -68,20 +70,20 @@ public class GemfireMessageStore extends AbstractKeyValueMessageStore { @Override protected Object doRetrieve(Object id) { - Assert.notNull(id, "'id' must not be null"); + Assert.notNull(id, ID_MUST_NOT_BE_NULL); return this.messageStoreRegion.get(id); } @Override protected void doStore(Object id, Object objectToStore) { - Assert.notNull(id, "'id' must not be null"); + Assert.notNull(id, ID_MUST_NOT_BE_NULL); Assert.notNull(objectToStore, "'objectToStore' must not be null"); this.messageStoreRegion.put(id, objectToStore); } @Override protected void doStoreIfAbsent(Object id, Object objectToStore) { - Assert.notNull(id, "'id' must not be null"); + Assert.notNull(id, ID_MUST_NOT_BE_NULL); Assert.notNull(objectToStore, "'objectToStore' must not be null"); Object present = this.messageStoreRegion.putIfAbsent(id, objectToStore); if (present != null && logger.isDebugEnabled()) { @@ -92,7 +94,7 @@ public class GemfireMessageStore extends AbstractKeyValueMessageStore { @Override protected Object doRemove(Object id) { - Assert.notNull(id, "'id' must not be null"); + Assert.notNull(id, ID_MUST_NOT_BE_NULL); return this.messageStoreRegion.remove(id); } diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/config/StoredProcParserUtils.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/config/StoredProcParserUtils.java index 6c6e3d9440..85a8079896 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/config/StoredProcParserUtils.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/config/StoredProcParserUtils.java @@ -30,6 +30,7 @@ import org.springframework.beans.factory.config.TypedStringValue; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.support.ManagedMap; +import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.expression.common.LiteralExpression; import org.springframework.integration.config.ExpressionFactoryBean; @@ -65,12 +66,13 @@ public final class StoredProcParserUtils { */ public static ManagedList getSqlParameterDefinitionBeanDefinitions( Element storedProcComponent, ParserContext parserContext) { - List sqlParameterDefinitionChildElements = DomUtils.getChildElementsByTagName(storedProcComponent, "sql-parameter-definition"); + List sqlParameterDefinitionChildElements = + DomUtils.getChildElementsByTagName(storedProcComponent, "sql-parameter-definition"); ManagedList sqlParameterList = new ManagedList(); for (Element childElement : sqlParameterDefinitionChildElements) { - String name = childElement.getAttribute("name"); + String name = childElement.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE); String sqlType = childElement.getAttribute("type"); String direction = childElement.getAttribute("direction"); String scale = childElement.getAttribute("scale"); @@ -163,13 +165,13 @@ public final class StoredProcParserUtils { BeanDefinitionBuilder parameterBuilder = BeanDefinitionBuilder.genericBeanDefinition(ProcedureParameter.class); - String name = childElement.getAttribute("name"); + String name = childElement.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE); String expression = childElement.getAttribute("expression"); String value = childElement.getAttribute("value"); String type = childElement.getAttribute("type"); if (StringUtils.hasText(name)) { - parameterBuilder.addPropertyValue("name", name); + parameterBuilder.addPropertyValue(AbstractBeanDefinitionParser.NAME_ATTRIBUTE, name); } if (StringUtils.hasText(expression)) { @@ -219,7 +221,7 @@ public final class StoredProcParserUtils { for (Element childElement : returningResultsetChildElements) { - String name = childElement.getAttribute("name"); + String name = childElement.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE); String rowMapperAsString = childElement.getAttribute("row-mapper"); BeanMetadataElement rowMapperBeanDefinition = null; @@ -229,7 +231,7 @@ public final class StoredProcParserUtils { ClassUtils.forName(rowMapperAsString, parserContext.getReaderContext().getBeanClassLoader()); rowMapperBeanDefinition = BeanDefinitionBuilder.genericBeanDefinition(rowMapperAsString).getBeanDefinition(); } - catch (ClassNotFoundException e) { + catch (@SuppressWarnings("unused") ClassNotFoundException e) { //Ignore it and fallback to bean reference rowMapperBeanDefinition = new RuntimeBeanReference(rowMapperAsString); } diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/metadata/JdbcMetadataStore.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/metadata/JdbcMetadataStore.java index b1d25c1718..0738e64bef 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/metadata/JdbcMetadataStore.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/metadata/JdbcMetadataStore.java @@ -42,6 +42,8 @@ import org.springframework.util.Assert; */ public class JdbcMetadataStore implements ConcurrentMetadataStore, InitializingBean { + private static final String KEY_CANNOT_BE_NULL = "'key' cannot be null"; + /** * Default value for the table prefix property. */ @@ -134,7 +136,7 @@ public class JdbcMetadataStore implements ConcurrentMetadataStore, InitializingB @Override @Transactional public String putIfAbsent(String key, String value) { - Assert.notNull(key, "'key' cannot be null"); + Assert.notNull(key, KEY_CANNOT_BE_NULL); Assert.notNull(value, "'value' cannot be null"); while (true) { //try to insert if does not exists @@ -169,7 +171,7 @@ public class JdbcMetadataStore implements ConcurrentMetadataStore, InitializingB @Override @Transactional public boolean replace(String key, String oldValue, String newValue) { - Assert.notNull(key, "'key' cannot be null"); + Assert.notNull(key, KEY_CANNOT_BE_NULL); Assert.notNull(oldValue, "'oldValue' cannot be null"); Assert.notNull(newValue, "'newValue' cannot be null"); int affectedRows = this.jdbcTemplate.update(this.replaceValueQuery, @@ -185,7 +187,7 @@ public class JdbcMetadataStore implements ConcurrentMetadataStore, InitializingB @Override @Transactional public void put(String key, String value) { - Assert.notNull(key, "'key' cannot be null"); + Assert.notNull(key, KEY_CANNOT_BE_NULL); Assert.notNull(value, "'value' cannot be null"); while (true) { //try to insert if does not exist, if exists we will try to update it @@ -215,7 +217,7 @@ public class JdbcMetadataStore implements ConcurrentMetadataStore, InitializingB @Override @Transactional public String get(String key) { - Assert.notNull(key, "'key' cannot be null"); + Assert.notNull(key, KEY_CANNOT_BE_NULL); try { return this.jdbcTemplate.queryForObject(this.getValueQuery, String.class, key, this.region); } @@ -228,7 +230,7 @@ public class JdbcMetadataStore implements ConcurrentMetadataStore, InitializingB @Override @Transactional public String remove(String key) { - Assert.notNull(key, "'key' cannot be null"); + Assert.notNull(key, KEY_CANNOT_BE_NULL); String oldValue; try { //select old value and lock row for removal diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/DerbyChannelMessageStoreQueryProvider.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/DerbyChannelMessageStoreQueryProvider.java index 2d466f05fa..bc8e6be97d 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/DerbyChannelMessageStoreQueryProvider.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/DerbyChannelMessageStoreQueryProvider.java @@ -19,39 +19,42 @@ package org.springframework.integration.jdbc.store.channel; /** * @author Gunnar Hillert * @author Artem Bilan + * @author Gary Russell * @since 2.2 * * https://blogs.oracle.com/kah/entry/derby_10_5_preview_fetch */ public class DerbyChannelMessageStoreQueryProvider extends AbstractChannelMessageStoreQueryProvider { + private static final String SELECT_COMMON = + "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + + "from %PREFIX%CHANNEL_MESSAGE " + + "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region "; + @Override public String getPollFromGroupExcludeIdsQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + - "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) order by CREATED_DATE, MESSAGE_SEQUENCE FETCH FIRST ROW ONLY"; + return SELECT_COMMON + + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + + "order by CREATED_DATE, MESSAGE_SEQUENCE FETCH FIRST ROW ONLY"; } @Override public String getPollFromGroupQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + - "order by CREATED_DATE, MESSAGE_SEQUENCE FETCH FIRST ROW ONLY"; + return SELECT_COMMON + + "order by CREATED_DATE, MESSAGE_SEQUENCE FETCH FIRST ROW ONLY"; } @Override public String getPriorityPollFromGroupExcludeIdsQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + - "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + - "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE FETCH FIRST ROW ONLY"; + return SELECT_COMMON + + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + + "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE FETCH FIRST ROW ONLY"; } @Override public String getPriorityPollFromGroupQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + - "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE FETCH FIRST ROW ONLY"; + return SELECT_COMMON + + "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE FETCH FIRST ROW ONLY"; } } diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/H2ChannelMessageStoreQueryProvider.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/H2ChannelMessageStoreQueryProvider.java index 9453c49e14..542ae519ba 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/H2ChannelMessageStoreQueryProvider.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/H2ChannelMessageStoreQueryProvider.java @@ -20,11 +20,17 @@ package org.springframework.integration.jdbc.store.channel; * @author Gunnar Hillert * @author Artem Bilan * @author Manuel Jordan + * @author Gary Russell * @since 4.3 * */ public class H2ChannelMessageStoreQueryProvider extends AbstractChannelMessageStoreQueryProvider { + private static final String SELECT_COMMON = + "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + + "from %PREFIX%CHANNEL_MESSAGE " + + "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region "; + @Override public String getCreateMessageQuery() { return "INSERT into %PREFIX%CHANNEL_MESSAGE(MESSAGE_ID, GROUP_KEY, REGION, CREATED_DATE, MESSAGE_PRIORITY, " + @@ -34,35 +40,27 @@ public class H2ChannelMessageStoreQueryProvider extends AbstractChannelMessageSt @Override public String getPollFromGroupExcludeIdsQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + - "from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + "order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } @Override public String getPollFromGroupQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + - "from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } @Override public String getPriorityPollFromGroupExcludeIdsQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + - "from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } @Override public String getPriorityPollFromGroupQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + - "from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/HsqlChannelMessageStoreQueryProvider.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/HsqlChannelMessageStoreQueryProvider.java index 67b4cffab6..f0e0529a74 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/HsqlChannelMessageStoreQueryProvider.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/HsqlChannelMessageStoreQueryProvider.java @@ -24,6 +24,11 @@ package org.springframework.integration.jdbc.store.channel; */ public class HsqlChannelMessageStoreQueryProvider extends AbstractChannelMessageStoreQueryProvider { + private static final String SELECT_COMMON = + "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + + "from %PREFIX%CHANNEL_MESSAGE " + + "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region "; + @Override public String getCreateMessageQuery() { return "INSERT into %PREFIX%CHANNEL_MESSAGE(MESSAGE_ID, GROUP_KEY, REGION, CREATED_DATE, MESSAGE_PRIORITY, MESSAGE_SEQUENCE, MESSAGE_BYTES)" @@ -32,30 +37,26 @@ public class HsqlChannelMessageStoreQueryProvider extends AbstractChannelMessage @Override public String getPollFromGroupExcludeIdsQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } @Override public String getPollFromGroupQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } @Override public String getPriorityPollFromGroupExcludeIdsQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } @Override public String getPriorityPollFromGroupQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/MySqlChannelMessageStoreQueryProvider.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/MySqlChannelMessageStoreQueryProvider.java index 039096e67e..a2afd5b946 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/MySqlChannelMessageStoreQueryProvider.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/MySqlChannelMessageStoreQueryProvider.java @@ -23,32 +23,34 @@ package org.springframework.integration.jdbc.store.channel; */ public class MySqlChannelMessageStoreQueryProvider extends AbstractChannelMessageStoreQueryProvider { + private static final String SELECT_COMMON = + "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + + "from %PREFIX%CHANNEL_MESSAGE " + + "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region "; + @Override public String getPollFromGroupExcludeIdsQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + - "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; + return SELECT_COMMON + + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + + "order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } @Override public String getPollFromGroupQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } @Override public String getPriorityPollFromGroupExcludeIdsQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + "order by MESSAGE_PRIORITY DESC, CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } @Override public String getPriorityPollFromGroupQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "order by MESSAGE_PRIORITY DESC, CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; } diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/OracleChannelMessageStoreQueryProvider.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/OracleChannelMessageStoreQueryProvider.java index 0b7460c679..d89dffdca5 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/OracleChannelMessageStoreQueryProvider.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/OracleChannelMessageStoreQueryProvider.java @@ -33,23 +33,28 @@ package org.springframework.integration.jdbc.store.channel; */ public class OracleChannelMessageStoreQueryProvider extends AbstractChannelMessageStoreQueryProvider { + private static final String SELECT_COMMON = + "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + + "from %PREFIX%CHANNEL_MESSAGE " + + "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region "; + @Override public String getCreateMessageQuery() { - return "INSERT into %PREFIX%CHANNEL_MESSAGE(MESSAGE_ID, GROUP_KEY, REGION, CREATED_DATE, MESSAGE_PRIORITY, MESSAGE_SEQUENCE, MESSAGE_BYTES)" + return "INSERT into %PREFIX%CHANNEL_MESSAGE(MESSAGE_ID, GROUP_KEY, REGION, CREATED_DATE, MESSAGE_PRIORITY, " + + "MESSAGE_SEQUENCE, MESSAGE_BYTES)" + " values (?, ?, ?, ?, ?, %PREFIX%MESSAGE_SEQ.NEXTVAL, ?)"; } @Override public String getPollFromGroupExcludeIdsQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + - "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) order by CREATED_DATE, MESSAGE_SEQUENCE FOR UPDATE SKIP LOCKED"; + return SELECT_COMMON + + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + + "order by CREATED_DATE, MESSAGE_SEQUENCE FOR UPDATE SKIP LOCKED"; } @Override public String getPollFromGroupQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "order by CREATED_DATE, MESSAGE_SEQUENCE FOR UPDATE SKIP LOCKED"; } diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/PostgresChannelMessageStoreQueryProvider.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/PostgresChannelMessageStoreQueryProvider.java index e86d4c96d5..8b36df8049 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/PostgresChannelMessageStoreQueryProvider.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/PostgresChannelMessageStoreQueryProvider.java @@ -23,32 +23,34 @@ package org.springframework.integration.jdbc.store.channel; */ public class PostgresChannelMessageStoreQueryProvider extends AbstractChannelMessageStoreQueryProvider { + private static final String SELECT_COMMON = + "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + + "from %PREFIX%CHANNEL_MESSAGE " + + "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region "; + @Override public String getPollFromGroupExcludeIdsQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + - "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1 FOR UPDATE"; + return SELECT_COMMON + + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + + "order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1 FOR UPDATE"; } @Override public String getPollFromGroupQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1 FOR UPDATE"; } @Override public String getPriorityPollFromGroupExcludeIdsQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1 FOR UPDATE"; } @Override public String getPriorityPollFromGroupQuery() { - return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1 FOR UPDATE"; } diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/SqlServerChannelMessageStoreQueryProvider.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/SqlServerChannelMessageStoreQueryProvider.java index c2a7bdfa46..1264c89e89 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/SqlServerChannelMessageStoreQueryProvider.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/SqlServerChannelMessageStoreQueryProvider.java @@ -23,38 +23,40 @@ package org.springframework.integration.jdbc.store.channel; */ public class SqlServerChannelMessageStoreQueryProvider extends AbstractChannelMessageStoreQueryProvider { + private static final String SELECT_COMMON = + "SELECT TOP 1 %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + + "from %PREFIX%CHANNEL_MESSAGE " + + "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region "; + @Override public String getPollFromGroupExcludeIdsQuery() { - return "SELECT TOP 1 %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) order by CREATED_DATE, MESSAGE_SEQUENCE"; } @Override public String getPollFromGroupQuery() { - return "SELECT TOP 1 %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "order by CREATED_DATE, MESSAGE_SEQUENCE"; } @Override public String getPriorityPollFromGroupExcludeIdsQuery() { - return "SELECT TOP 1 %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + "order by MESSAGE_PRIORITY DESC, CREATED_DATE, MESSAGE_SEQUENCE"; } @Override public String getPriorityPollFromGroupQuery() { - return "SELECT TOP 1 %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " + - "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + return SELECT_COMMON + "order by MESSAGE_PRIORITY DESC, CREATED_DATE, MESSAGE_SEQUENCE"; } @Override public String getCreateMessageQuery() { - return "INSERT into %PREFIX%CHANNEL_MESSAGE(MESSAGE_ID, GROUP_KEY, REGION, CREATED_DATE, MESSAGE_PRIORITY, MESSAGE_SEQUENCE, MESSAGE_BYTES)" + return "INSERT into %PREFIX%CHANNEL_MESSAGE(MESSAGE_ID, GROUP_KEY, REGION, CREATED_DATE, MESSAGE_PRIORITY, " + + "MESSAGE_SEQUENCE, MESSAGE_BYTES)" + " values (?, ?, ?, ?, ?,(NEXT VALUE FOR %PREFIX%MESSAGE_SEQ), ?)"; } diff --git a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/metadata/MongoDbMetadataStore.java b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/metadata/MongoDbMetadataStore.java index 9191730a49..9e872280ba 100644 --- a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/metadata/MongoDbMetadataStore.java +++ b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/metadata/MongoDbMetadataStore.java @@ -44,6 +44,8 @@ import org.springframework.util.Assert; */ public class MongoDbMetadataStore implements ConcurrentMetadataStore { + private static final String KEY_MUST_NOT_BE_EMPTY = "'key' must not be empty."; + private static final String DEFAULT_COLLECTION_NAME = "metadataStore"; private static final String ID_FIELD = "_id"; @@ -107,7 +109,7 @@ public class MongoDbMetadataStore implements ConcurrentMetadataStore { */ @Override public void put(String key, String value) { - Assert.hasText(key, "'key' must not be empty."); + Assert.hasText(key, KEY_MUST_NOT_BE_EMPTY); Assert.hasText(value, "'value' must not be empty."); final Map entry = new HashMap<>(); entry.put(ID_FIELD, key); @@ -123,7 +125,7 @@ public class MongoDbMetadataStore implements ConcurrentMetadataStore { */ @Override public String get(String key) { - Assert.hasText(key, "'key' must not be empty."); + Assert.hasText(key, KEY_MUST_NOT_BE_EMPTY); Query query = new Query(Criteria.where(ID_FIELD).is(key)); query.fields().exclude(ID_FIELD); @SuppressWarnings("unchecked") @@ -141,7 +143,7 @@ public class MongoDbMetadataStore implements ConcurrentMetadataStore { */ @Override public String remove(String key) { - Assert.hasText(key, "'key' must not be empty."); + Assert.hasText(key, KEY_MUST_NOT_BE_EMPTY); Query query = new Query(Criteria.where(ID_FIELD).is(key)); query.fields().exclude(ID_FIELD); @SuppressWarnings("unchecked") @@ -167,7 +169,7 @@ public class MongoDbMetadataStore implements ConcurrentMetadataStore { */ @Override public String putIfAbsent(String key, String value) { - Assert.hasText(key, "'key' must not be empty."); + Assert.hasText(key, KEY_MUST_NOT_BE_EMPTY); Assert.hasText(value, "'value' must not be empty."); Query query = new Query(Criteria.where(ID_FIELD).is(key)); @@ -190,7 +192,7 @@ public class MongoDbMetadataStore implements ConcurrentMetadataStore { */ @Override public boolean replace(String key, String oldValue, String newValue) { - Assert.hasText(key, "'key' must not be empty."); + Assert.hasText(key, KEY_MUST_NOT_BE_EMPTY); Assert.hasText(oldValue, "'oldValue' must not be empty."); Assert.hasText(newValue, "'newValue' must not be empty."); Query query = new Query(Criteria.where(ID_FIELD).is(key).and(VALUE).is(oldValue)); diff --git a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageStore.java b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageStore.java index 274684f409..9feee1ba4c 100644 --- a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageStore.java +++ b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageStore.java @@ -55,6 +55,8 @@ import org.springframework.util.Assert; public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDbMessageStore implements MessageStore { + private static final String GROUP_ID_MUST_NOT_BE_NULL = "'groupId' must not be null"; + public static final String DEFAULT_COLLECTION_NAME = "configurableStoreMessages"; @@ -109,7 +111,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb @Override public MessageGroup getMessageGroup(Object groupId) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Query query = groupOrderQuery(groupId); MessageDocument messageDocument = getMongoTemplate().findOne(query, MessageDocument.class, this.collectionName); @@ -140,7 +142,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb @Override public void addMessagesToGroup(Object groupId, Message... messages) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Assert.notNull(messages, "'message' must not be null"); Query query = groupOrderQuery(groupId); @@ -171,7 +173,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb @Override public void removeMessagesFromGroup(Object groupId, Collection> messages) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Assert.notNull(messages, "'messageToRemove' must not be null"); Collection ids = new ArrayList<>(); @@ -196,7 +198,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb @Override public Message pollMessageFromGroup(final Object groupId) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Sort sort = Sort.by(MessageDocumentFields.LAST_MODIFIED_TIME, MessageDocumentFields.SEQUENCE); Query query = groupIdQuery(groupId).with(sort); @@ -253,7 +255,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb @Override public Message getOneMessageFromGroup(Object groupId) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Query query = groupOrderQuery(groupId); MessageDocument messageDocument = getMongoTemplate().findOne(query, MessageDocument.class, this.collectionName); if (messageDocument != null) { @@ -266,7 +268,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb @Override public Collection> getMessagesForGroup(Object groupId) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Query query = groupOrderQuery(groupId); List documents = getMongoTemplate().find(query, MessageDocument.class, this.collectionName); diff --git a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbMessageStore.java b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbMessageStore.java index bb63733eb2..f88f250238 100644 --- a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbMessageStore.java +++ b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbMessageStore.java @@ -101,6 +101,12 @@ import com.mongodb.DBObject; public class MongoDbMessageStore extends AbstractMessageGroupStore implements MessageStore, BeanClassLoaderAware, ApplicationContextAware, InitializingBean { + private static final String HEADERS = "headers"; + + private static final String UNCHECKED = "unchecked"; + + private static final String GROUP_ID_MUST_NOT_BE_NULL = "'groupId' must not be null"; + public static final String SEQUENCE_NAME = "messagesSequence"; private static final String DEFAULT_COLLECTION_NAME = "messages"; @@ -249,7 +255,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore @Override public MessageGroup getMessageGroup(Object groupId) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Query query = whereGroupIdOrder(groupId); MessageWrapper messageWrapper = this.template.findOne(query, MessageWrapper.class, this.collectionName); @@ -273,7 +279,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore @Override public void addMessagesToGroup(Object groupId, Message... messages) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Assert.notNull(messages, "'message' must not be null"); Query query = whereGroupIdOrder(groupId); MessageWrapper messageDocument = this.template.findOne(query, MessageWrapper.class, this.collectionName); @@ -303,7 +309,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore @Override public void removeMessagesFromGroup(Object groupId, Collection> messages) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Assert.notNull(messages, "'messageToRemove' must not be null"); Collection ids = new ArrayList<>(); @@ -352,7 +358,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore @Override public Message pollMessageFromGroup(final Object groupId) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Query query = whereGroupIdIs(groupId).with(Sort.by(GROUP_UPDATE_TIMESTAMP_KEY, SEQUENCE)); MessageWrapper messageWrapper = this.template.findAndRemove(query, MessageWrapper.class, this.collectionName); Message message = null; @@ -382,7 +388,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore @Override public Message getOneMessageFromGroup(Object groupId) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Query query = whereGroupIdOrder(groupId); MessageWrapper messageWrapper = this.template.findOne(query, MessageWrapper.class, this.collectionName); if (messageWrapper != null) { @@ -395,7 +401,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore @Override public Collection> getMessagesForGroup(Object groupId) { - Assert.notNull(groupId, "'groupId' must not be null"); + Assert.notNull(groupId, GROUP_ID_MUST_NOT_BE_NULL); Query query = whereGroupIdOrder(groupId); List messageWrappers = this.template.find(query, MessageWrapper.class, this.collectionName); @@ -463,10 +469,10 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore this.collectionName).get(SEQUENCE); // NOSONAR - never returns null } - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) private static void enhanceHeaders(MessageHeaders messageHeaders, Map headers) { Map innerMap = - (Map) new DirectFieldAccessor(messageHeaders).getPropertyValue("headers"); + (Map) new DirectFieldAccessor(messageHeaders).getPropertyValue(HEADERS); // using reflection to set ID and TIMESTAMP since they are immutable through MessageHeaders Object idHeader = headers.get(MessageHeaders.ID); if (idHeader != null) { @@ -478,7 +484,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore } } - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) private static Map asMap(Bson bson) { if (bson instanceof Document) { return (Document) bson; @@ -498,6 +504,8 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore */ private final class MessageReadingMongoConverter extends MappingMongoConverter { + private static final String CLASS = "_class"; + MessageReadingMongoConverter(MongoDbFactory mongoDbFactory, MappingContext, MongoPersistentProperty> mappingContext) { super(new DefaultDbRefResolver(mongoDbFactory), mappingContext); @@ -531,7 +539,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore } @Override - @SuppressWarnings({ "unchecked" }) + @SuppressWarnings({ UNCHECKED }) public S read(Class clazz, Bson source) { if (!MessageWrapper.class.equals(clazz)) { return super.read(clazz, source); @@ -590,8 +598,8 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore Map document = asMap(source); try { Class typeClass = null; - if (document.containsKey("_class")) { - Object type = document.get("_class"); + if (document.containsKey(CLASS)) { + Object type = document.get(CLASS); typeClass = ClassUtils.forName(type.toString(), MongoDbMessageStore.this.classLoader); } else if (source instanceof BasicDBList) { @@ -618,7 +626,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore if (payload instanceof Bson) { Bson payloadObject = (Bson) payload; - Object payloadType = asMap(payloadObject).get("_class"); + Object payloadType = asMap(payloadObject).get(CLASS); try { Class payloadClass = ClassUtils.forName(payloadType.toString(), MongoDbMessageStore.this.classLoader); @@ -667,9 +675,9 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore @Override public GenericMessage convert(Document source) { - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) Map headers = - MongoDbMessageStore.this.converter.normalizeHeaders((Map) source.get("headers")); + MongoDbMessageStore.this.converter.normalizeHeaders((Map) source.get(HEADERS)); GenericMessage message = new GenericMessage<>(MongoDbMessageStore.this.converter.extractPayload(source), headers); @@ -688,9 +696,9 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore @Override public MutableMessage convert(Document source) { - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) Map headers = - MongoDbMessageStore.this.converter.normalizeHeaders((Map) source.get("headers")); + MongoDbMessageStore.this.converter.normalizeHeaders((Map) source.get(HEADERS)); Object payload = MongoDbMessageStore.this.converter.extractPayload(source); return (MutableMessage) MutableMessageBuilder.withPayload(payload) @@ -709,9 +717,9 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore @Override public AdviceMessage convert(Document source) { - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) Map headers = - MongoDbMessageStore.this.converter.normalizeHeaders((Map) source.get("headers")); + MongoDbMessageStore.this.converter.normalizeHeaders((Map) source.get(HEADERS)); Message inputMessage = null; @@ -749,9 +757,9 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore @Override public ErrorMessage convert(Document source) { - @SuppressWarnings("unchecked") + @SuppressWarnings(UNCHECKED) Map headers = - MongoDbMessageStore.this.converter.normalizeHeaders((Map) source.get("headers")); + MongoDbMessageStore.this.converter.normalizeHeaders((Map) source.get(HEADERS)); Object payload = this.deserializingConverter.convert(((Binary) source.get("payload")).getData()); ErrorMessage message = new ErrorMessage((Throwable) payload, headers); // NOSONAR not null @@ -784,12 +792,14 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore */ private static final class MessageWrapper { + private static final String UNUSED = "unused"; + /* * Needed as a persistence property to suppress 'Cannot determine IsNewStrategy' MappingException * when the application context is configured with auditing. The document is not * currently Auditable. */ - @SuppressWarnings("unused") + @SuppressWarnings(UNUSED) @Id private String _id; // NOSONAR name @@ -798,16 +808,16 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore @Transient private final Message message; // NOSONAR name - @SuppressWarnings("unused") + @SuppressWarnings(UNUSED) private final String _messageType; // NOSONAR name - @SuppressWarnings("unused") + @SuppressWarnings(UNUSED) private final Object payload; - @SuppressWarnings("unused") + @SuppressWarnings(UNUSED) private final Map headers; - @SuppressWarnings("unused") + @SuppressWarnings(UNUSED) private final Message inputMessage; private long _message_timestamp; // NOSONAR name @@ -820,7 +830,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore private volatile boolean _group_complete; // NOSONAR name - @SuppressWarnings("unused") + @SuppressWarnings(UNUSED) private int sequence; MessageWrapper(Message message) { @@ -849,7 +859,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore return this._group_complete; } - @SuppressWarnings("unused") + @SuppressWarnings(UNUSED) public Object get_GroupId() { // NOSONAR name return this._groupId; } diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/metadata/RedisMetadataStore.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/metadata/RedisMetadataStore.java index f063232678..f84149a4b1 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/metadata/RedisMetadataStore.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/metadata/RedisMetadataStore.java @@ -40,6 +40,8 @@ import org.springframework.util.Assert; */ public class RedisMetadataStore implements ConcurrentMetadataStore { + private static final String KEY_MUST_NOT_BE_NULL = "'key' must not be null."; + public static final String KEY = "MetaData"; private final RedisProperties properties; @@ -109,7 +111,7 @@ public class RedisMetadataStore implements ConcurrentMetadataStore { */ @Override public void put(String key, String value) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(value, "'value' must not be null."); this.properties.put(key, value); } @@ -121,7 +123,7 @@ public class RedisMetadataStore implements ConcurrentMetadataStore { */ @Override public String get(String key) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Object value = this.properties.get(key); if (value != null) { Assert.isInstanceOf(String.class, value, "Invalid type in the store"); @@ -132,7 +134,7 @@ public class RedisMetadataStore implements ConcurrentMetadataStore { @Override public String remove(String key) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Object removed = this.properties.remove(key); if (removed != null) { Assert.isInstanceOf(String.class, removed, "The removed value was an invalid type"); @@ -142,7 +144,7 @@ public class RedisMetadataStore implements ConcurrentMetadataStore { @Override public String putIfAbsent(String key, String value) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(value, "'value' must not be null."); Object oldValue = this.properties.putIfAbsent(key, value); if (oldValue != null) { @@ -153,7 +155,7 @@ public class RedisMetadataStore implements ConcurrentMetadataStore { @Override public boolean replace(String key, String oldValue, String newValue) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(oldValue, "'oldValue' must not be null."); Assert.notNull(newValue, "'newValue' must not be null."); return this.properties.replace(key, oldValue, newValue); diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisMessageStore.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisMessageStore.java index a078978dae..aec079cc65 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisMessageStore.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisMessageStore.java @@ -43,6 +43,8 @@ import org.springframework.util.Assert; */ public class RedisMessageStore extends AbstractKeyValueMessageStore implements BeanClassLoaderAware { + private static final String ID_MUST_NOT_BE_NULL = "'id' must not be null"; + private final RedisTemplate redisTemplate; private final boolean unlinkAvailable; @@ -92,7 +94,7 @@ public class RedisMessageStore extends AbstractKeyValueMessageStore implements B @Override protected Object doRetrieve(Object id) { - Assert.notNull(id, "'id' must not be null"); + Assert.notNull(id, ID_MUST_NOT_BE_NULL); BoundValueOperations ops = this.redisTemplate.boundValueOps(id); return ops.get(); } @@ -100,7 +102,7 @@ public class RedisMessageStore extends AbstractKeyValueMessageStore implements B @Override protected void doStore(Object id, Object objectToStore) { - Assert.notNull(id, "'id' must not be null"); + Assert.notNull(id, ID_MUST_NOT_BE_NULL); Assert.notNull(objectToStore, "'objectToStore' must not be null"); BoundValueOperations ops = this.redisTemplate.boundValueOps(id); try { @@ -114,7 +116,7 @@ public class RedisMessageStore extends AbstractKeyValueMessageStore implements B @Override protected void doStoreIfAbsent(Object id, Object objectToStore) { - Assert.notNull(id, "'id' must not be null"); + Assert.notNull(id, ID_MUST_NOT_BE_NULL); Assert.notNull(objectToStore, "'objectToStore' must not be null"); BoundValueOperations ops = this.redisTemplate.boundValueOps(id); try { @@ -131,7 +133,7 @@ public class RedisMessageStore extends AbstractKeyValueMessageStore implements B @Override protected Object doRemove(Object id) { - Assert.notNull(id, "'id' must not be null"); + Assert.notNull(id, ID_MUST_NOT_BE_NULL); Object removedObject = this.doRetrieve(id); if (removedObject != null) { if (this.unlinkAvailable) { diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java index a41da3d74a..7955b6a985 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java @@ -49,6 +49,8 @@ import com.jcraft.jsch.SftpException; */ public class SftpSession implements Session { + private static final String SESSION_IS_NOT_CONNECTED = "session is not connected"; + private final Log logger = LogFactory.getLog(this.getClass()); private final com.jcraft.jsch.Session jschSession; @@ -74,7 +76,7 @@ public class SftpSession implements Session { @Override public boolean remove(String path) throws IOException { - Assert.state(this.channel != null, "session is not connected"); + Assert.state(this.channel != null, SESSION_IS_NOT_CONNECTED); try { this.channel.rm(path); return true; @@ -86,7 +88,7 @@ public class SftpSession implements Session { @Override public LsEntry[] list(String path) throws IOException { - Assert.state(this.channel != null, "session is not connected"); + Assert.state(this.channel != null, SESSION_IS_NOT_CONNECTED); try { Vector lsEntries = this.channel.ls(path); // NOSONAR (Vector) if (lsEntries != null) { @@ -123,7 +125,7 @@ public class SftpSession implements Session { @Override public void read(String source, OutputStream os) throws IOException { - Assert.state(this.channel != null, "session is not connected"); + Assert.state(this.channel != null, SESSION_IS_NOT_CONNECTED); try { InputStream is = this.channel.get(source); FileCopyUtils.copy(is, os); @@ -150,7 +152,7 @@ public class SftpSession implements Session { @Override public void write(InputStream inputStream, String destination) throws IOException { - Assert.state(this.channel != null, "session is not connected"); + Assert.state(this.channel != null, SESSION_IS_NOT_CONNECTED); try { this.channel.put(inputStream, destination); } @@ -161,7 +163,7 @@ public class SftpSession implements Session { @Override public void append(InputStream inputStream, String destination) throws IOException { - Assert.state(this.channel != null, "session is not connected"); + Assert.state(this.channel != null, SESSION_IS_NOT_CONNECTED); try { this.channel.put(inputStream, destination, ChannelSftp.APPEND); } diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java index bb09db171d..5da366ee3a 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java @@ -169,6 +169,8 @@ public final class TestMailServer { class Pop3Handler extends MailHandler { + private static final String PLUS_OK = "+OK"; + Pop3Handler(Socket socket) { super(socket); } @@ -180,29 +182,29 @@ public final class TestMailServer { while (!socket.isClosed()) { String line = reader.readLine(); if ("CAPA".equals(line)) { - write("+OK"); + write(PLUS_OK); write("USER"); write("."); } else if ("USER user".equals(line)) { - write("+OK"); + write(PLUS_OK); } else if ("PASS pw".equals(line)) { - write("+OK"); + write(PLUS_OK); } else if ("STAT".equals(line)) { write("+OK 1 3"); } else if ("NOOP".equals(line)) { - write("+OK"); + write(PLUS_OK); } else if ("RETR 1".equals(line)) { - write("+OK"); + write(PLUS_OK); write(MESSAGE); write("."); } else if ("QUIT".equals(line)) { - write("+OK"); + write(PLUS_OK); socket.close(); } } @@ -240,6 +242,8 @@ public final class TestMailServer { class ImapHandler extends MailHandler { + private static final String OK_FETCH_COMPLETED = "OK FETCH completed"; + /** * Time to wait while IDLE before returning a result. */ @@ -314,13 +318,13 @@ public final class TestMailServer { + "\"\") " // msgid + "BODYSTRUCTURE " + "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1 5)))"); - write(tag + "OK FETCH completed"); + write(tag + OK_FETCH_COMPLETED); } else if (line.contains("FETCH 2 (BODYSTRUCTURE)")) { write("* 2 FETCH " + "BODYSTRUCTURE " + "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1 5)))"); - write(tag + "OK FETCH completed"); + write(tag + OK_FETCH_COMPLETED); } else if (line.contains("STORE 1 +FLAGS (\\Flagged)")) { write("* 1 FETCH (FLAGS (\\Flagged))"); @@ -333,13 +337,13 @@ public final class TestMailServer { } else if (line.contains("FETCH 1 FLAGS")) { write("* 1 FLAGS(\\Seen)"); - write(tag + "OK FETCH completed"); + write(tag + OK_FETCH_COMPLETED); } else if (line.contains("FETCH 1 (BODY.PEEK")) { write("* 1 FETCH (BODY[]<0> {" + (MESSAGE.length() + 2) + "}"); write(MESSAGE); write(")"); - write(tag + "OK FETCH completed"); + write(tag + OK_FETCH_COMPLETED); } else if (line.contains("CLOSE")) { write(tag + "OK CLOSE completed"); diff --git a/spring-integration-test/src/main/java/org/springframework/integration/test/context/MockIntegrationContext.java b/spring-integration-test/src/main/java/org/springframework/integration/test/context/MockIntegrationContext.java index 34b1a0ca69..d0e89265b1 100644 --- a/spring-integration-test/src/main/java/org/springframework/integration/test/context/MockIntegrationContext.java +++ b/spring-integration-test/src/main/java/org/springframework/integration/test/context/MockIntegrationContext.java @@ -58,6 +58,11 @@ import reactor.util.function.Tuples; */ public class MockIntegrationContext implements BeanFactoryAware { + private static final String HANDLER = "handler"; + + /** + * The bean name for the mock integration context. + */ public static final String MOCK_INTEGRATION_CONTEXT_BEAN_NAME = "mockIntegrationContext"; private final Map beans = new HashMap<>(); @@ -97,11 +102,11 @@ public class MockIntegrationContext implements BeanFactoryAware { } else if (endpoint instanceof ReactiveStreamsConsumer) { Tuple2 value = (Tuple2) e.getValue(); - directFieldAccessor.setPropertyValue("handler", value.getT1()); + directFieldAccessor.setPropertyValue(HANDLER, value.getT1()); directFieldAccessor.setPropertyValue("subscriber", value.getT2()); } else if (endpoint instanceof IntegrationConsumer) { - directFieldAccessor.setPropertyValue("handler", e.getValue()); + directFieldAccessor.setPropertyValue(HANDLER, e.getValue()); } }); @@ -147,7 +152,7 @@ public class MockIntegrationContext implements BeanFactoryAware { ((Lifecycle) endpoint).stop(); } DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(endpoint); - Object targetMessageHandler = directFieldAccessor.getPropertyValue("handler"); + Object targetMessageHandler = directFieldAccessor.getPropertyValue(HANDLER); Assert.notNull(targetMessageHandler, () -> "'handler' must not be null in the: " + endpoint); if (endpoint instanceof ReactiveStreamsConsumer) { Object targetSubscriber = directFieldAccessor.getPropertyValue("subscriber"); @@ -177,7 +182,7 @@ public class MockIntegrationContext implements BeanFactoryAware { } } - directFieldAccessor.setPropertyValue("handler", mockMessageHandler); + directFieldAccessor.setPropertyValue(HANDLER, mockMessageHandler); if (endpoint instanceof ReactiveStreamsConsumer) { directFieldAccessor.setPropertyValue("subscriber", mockMessageHandler); diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/selector/RegexTestXPathMessageSelector.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/selector/RegexTestXPathMessageSelector.java index f4a35d6791..08c22115e8 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/selector/RegexTestXPathMessageSelector.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/selector/RegexTestXPathMessageSelector.java @@ -35,6 +35,8 @@ import org.springframework.xml.xpath.XPathExpression; */ public class RegexTestXPathMessageSelector extends AbstractXPathMessageSelector { + private static final String REGEX_MUST_NOT_BE_NULL = "regex must not be null"; + private final String regex; @@ -47,7 +49,7 @@ public class RegexTestXPathMessageSelector extends AbstractXPathMessageSelector */ public RegexTestXPathMessageSelector(String expression, Map namespaces, String regex) { super(expression, namespaces); - Assert.notNull(regex, "regex must not be null"); + Assert.notNull(regex, REGEX_MUST_NOT_BE_NULL); this.regex = regex; } @@ -61,7 +63,7 @@ public class RegexTestXPathMessageSelector extends AbstractXPathMessageSelector */ public RegexTestXPathMessageSelector(String expression, String prefix, String namespace, String regex) { super(expression, prefix, namespace); - Assert.notNull(regex, "regex must not be null"); + Assert.notNull(regex, REGEX_MUST_NOT_BE_NULL); this.regex = regex; } @@ -73,7 +75,7 @@ public class RegexTestXPathMessageSelector extends AbstractXPathMessageSelector */ public RegexTestXPathMessageSelector(String expression, String regex) { super(expression); - Assert.notNull(regex, "regex must not be null"); + Assert.notNull(regex, REGEX_MUST_NOT_BE_NULL); this.regex = regex; } @@ -86,7 +88,7 @@ public class RegexTestXPathMessageSelector extends AbstractXPathMessageSelector */ public RegexTestXPathMessageSelector(XPathExpression expression, String regex) { super(expression); - Assert.notNull(regex, "regex must not be null"); + Assert.notNull(regex, REGEX_MUST_NOT_BE_NULL); this.regex = regex; } diff --git a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java index 72c8e05bc0..381c6e30da 100644 --- a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java +++ b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java @@ -48,6 +48,8 @@ import org.springframework.util.Assert; */ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLifecycle { + private static final String KEY_MUST_NOT_BE_NULL = "'key' must not be null."; + private static final String UNUSED = "unused"; private final Object lifecycleMonitor = new Object(); @@ -113,7 +115,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif @Override public String putIfAbsent(String key, String value) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(value, "'value' must not be null."); synchronized (this.updateMap) { try { @@ -132,7 +134,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif @Override public boolean replace(String key, String oldValue, String newValue) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(oldValue, "'oldValue' must not be null."); Assert.notNull(newValue, "'newValue' must not be null."); synchronized (this.updateMap) { @@ -171,7 +173,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif @Override public void put(String key, String value) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(value, "'value' must not be null."); synchronized (this.updateMap) { try { @@ -196,7 +198,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif @Override public String get(String key) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.state(isRunning(), "ZookeeperMetadataStore has to be started before using."); synchronized (this.updateMap) { ChildData currentData = this.cache.getCurrentData(getPath(key)); @@ -225,7 +227,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif @Override public String remove(String key) { - Assert.notNull(key, "'key' must not be null."); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); synchronized (this.updateMap) { try { byte[] bytes = this.client.getData().forPath(getPath(key));