diff --git a/spring-integration-camel/src/main/java/org/springframework/integration/camel/outbound/CamelMessageHandler.java b/spring-integration-camel/src/main/java/org/springframework/integration/camel/outbound/CamelMessageHandler.java index c56b38678f..73fc8f0377 100644 --- a/spring-integration-camel/src/main/java/org/springframework/integration/camel/outbound/CamelMessageHandler.java +++ b/spring-integration-camel/src/main/java/org/springframework/integration/camel/outbound/CamelMessageHandler.java @@ -165,18 +165,19 @@ public class CamelMessageHandler extends AbstractReplyProducingMessageHandler { "The 'endpointUri' option is mutually exclusive with 'route'"); BeanFactory beanFactory = getBeanFactory(); - if (this.producerTemplate == null) { + if (this.producerTemplate == null) { // NOSONAR this.producerTemplate = beanFactory.getBean(CamelContext.class).createProducerTemplate(); } - if (this.route != null) { + LambdaRouteBuilder lambdaRouteBuilder = this.route; + if (lambdaRouteBuilder != null) { CamelContext camelContext = this.producerTemplate.getCamelContext(); RouteBuilder routeBuilder = new RouteBuilder(camelContext) { @Override public void configure() throws Exception { - CamelMessageHandler.this.route.accept(this); + lambdaRouteBuilder.accept(this); } }; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationComponentScanRegistrar.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationComponentScanRegistrar.java index 09e5fb0f14..1ad92b868a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationComponentScanRegistrar.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationComponentScanRegistrar.java @@ -92,6 +92,8 @@ public class IntegrationComponentScanRegistrar implements ImportBeanDefinitionRe AnnotationAttributes.fromMap( importingClassMetadata.getAnnotationAttributes(IntegrationComponentScan.class.getName())); + Assert.notNull(componentScan, "The '@IntegrationComponentScan' must be present for using this registrar"); + Collection basePackages = getBasePackages(componentScan, registry); if (basePackages.isEmpty()) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/MessagingAnnotationPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/MessagingAnnotationPostProcessor.java index e25fb7c64b..766ad1a251 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/MessagingAnnotationPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/MessagingAnnotationPostProcessor.java @@ -134,7 +134,7 @@ public class MessagingAnnotationPostProcessor private void processCandidate(String beanName, AnnotatedBeanDefinition beanDefinition) { MethodMetadata methodMetadata = beanDefinition.getFactoryMethodMetadata(); - MergedAnnotations annotations = methodMetadata.getAnnotations(); + MergedAnnotations annotations = methodMetadata.getAnnotations(); // NOSONAR if (methodMetadata instanceof StandardMethodMetadata standardMethodMetadata) { annotations = MergedAnnotations.from(standardMethodMetadata.getIntrospectedMethod()); } @@ -179,7 +179,7 @@ public class MessagingAnnotationPostProcessor if (messagingAnnotationProcessor != null) { if (messagingAnnotationProcessor.beanAnnotationAware()) { if (messagingAnnotationProcessor.shouldCreateEndpoint( - beanDefinition.getFactoryMethodMetadata().getAnnotations(), annotationChain)) { + beanDefinition.getFactoryMethodMetadata().getAnnotations(), annotationChain)) { // NOSONAR messagingAnnotationProcessor.processBeanDefinition(beanName, beanDefinition, annotationChain); } @@ -311,11 +311,10 @@ public class MessagingAnnotationPostProcessor MethodAnnotationPostProcessor postProcessor, Method targetMethod) { Object result = postProcessor.postProcess(bean, beanName, targetMethod, annotations); - ConfigurableListableBeanFactory beanFactory = getBeanFactory(); if (result instanceof AbstractEndpoint endpoint) { String autoStartup = MessagingAnnotationUtils.resolveAttribute(annotations, "autoStartup", String.class); if (StringUtils.hasText(autoStartup)) { - autoStartup = beanFactory.resolveEmbeddedValue(autoStartup); + autoStartup = this.beanFactory.resolveEmbeddedValue(autoStartup); if (StringUtils.hasText(autoStartup)) { endpoint.setAutoStartup(Boolean.parseBoolean(autoStartup)); } @@ -323,7 +322,7 @@ public class MessagingAnnotationPostProcessor String phase = MessagingAnnotationUtils.resolveAttribute(annotations, "phase", String.class); if (StringUtils.hasText(phase)) { - phase = beanFactory.resolveEmbeddedValue(phase); + phase = this.beanFactory.resolveEmbeddedValue(phase); if (StringUtils.hasText(phase)) { endpoint.setPhase(Integer.parseInt(phase)); } @@ -339,7 +338,7 @@ public class MessagingAnnotationPostProcessor getBeanDefinitionRegistry() .registerBeanDefinition(endpointBeanName, new RootBeanDefinition((Class) endpoint.getClass(), () -> endpoint)); - beanFactory.getBean(endpointBeanName); + this.beanFactory.getBean(endpointBeanName); } } @@ -352,8 +351,7 @@ public class MessagingAnnotationPostProcessor + ClassUtils.getShortNameAsProperty(annotationType); name = baseName; int count = 1; - ConfigurableListableBeanFactory beanFactory = getBeanFactory(); - while (beanFactory.containsBean(name)) { + while (this.beanFactory.containsBean(name)) { name = baseName + "#" + (++count); } } 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 622e1de7de..2be7ac97d7 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 @@ -67,6 +67,10 @@ public class GatewayParser implements BeanDefinitionParser { private static final String PROXY_DEFAULT_METHODS_ATTR = "proxyDefaultMethods"; + private static final String ASYNC_EXECUTOR_ATTR = "asyncExecutor"; + + private static final String MAPPER_ATTR = "mapper"; + @Override public BeanDefinition parse(final Element element, ParserContext parserContext) { boolean isNested = parserContext.isNested(); @@ -83,13 +87,13 @@ public class GatewayParser implements BeanDefinitionParser { String asyncExecutor = element.getAttribute("async-executor"); if (!element.hasAttribute("async-executor") || StringUtils.hasLength(asyncExecutor)) { - gatewayAttributes.put("asyncExecutor", asyncExecutor); + gatewayAttributes.put(ASYNC_EXECUTOR_ATTR, asyncExecutor); } else { - gatewayAttributes.put("asyncExecutor", null); + gatewayAttributes.put(ASYNC_EXECUTOR_ATTR, null); } - gatewayAttributes.put("mapper", element.getAttribute("mapper")); + gatewayAttributes.put(MAPPER_ATTR, element.getAttribute(MAPPER_ATTR)); gatewayAttributes.put("defaultReplyTimeout", element.getAttribute(isNested ? "reply-timeout" : "default-reply-timeout")); gatewayAttributes.put("defaultRequestTimeout", @@ -122,8 +126,10 @@ public class GatewayParser implements BeanDefinitionParser { Map header = new HashMap<>(); header.put(AbstractBeanDefinitionParser.NAME_ATTRIBUTE, e.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE)); - header.put("value", e.getAttribute("value")); - header.put("expression", e.getAttribute("expression")); + header.put(IntegrationNamespaceUtils.VALUE_ATTRIBUTE, + e.getAttribute(IntegrationNamespaceUtils.VALUE_ATTRIBUTE)); + header.put(IntegrationNamespaceUtils.EXPRESSION_ATTRIBUTE, + e.getAttribute(IntegrationNamespaceUtils.EXPRESSION_ATTRIBUTE)); headers.add(header); } gatewayAttributes.put("defaultHeaders", headers.toArray(new Map[0])); @@ -146,7 +152,7 @@ public class GatewayParser implements BeanDefinitionParser { methodMetadataBuilder.addPropertyValue("requestTimeout", methodElement.getAttribute("request-timeout")); methodMetadataBuilder.addPropertyValue("replyTimeout", methodElement.getAttribute("reply-timeout")); - boolean hasMapper = StringUtils.hasText(element.getAttribute("mapper")); + boolean hasMapper = StringUtils.hasText(element.getAttribute(MAPPER_ATTR)); String payloadExpression = methodElement.getAttribute("payload-expression"); Assert.state(!hasMapper || !StringUtils.hasText(payloadExpression), "'payload-expression' is not allowed when a 'mapper' is provided"); @@ -165,7 +171,8 @@ public class GatewayParser implements BeanDefinitionParser { Map headerExpressions = new ManagedMap<>(); for (Element headerElement : invocationHeaders) { BeanDefinition expressionDef = IntegrationNamespaceUtils - .createExpressionDefinitionFromValueOrExpression("value", "expression", parserContext, + .createExpressionDefinitionFromValueOrExpression( + IntegrationNamespaceUtils.VALUE_ATTRIBUTE, "expression", parserContext, headerElement, true); headerExpressions.put(headerElement.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE), @@ -193,8 +200,8 @@ public class GatewayParser implements BeanDefinitionParser { String defaultRequestChannel = (String) gatewayAttributes.get("defaultRequestChannel"); String defaultReplyChannel = (String) gatewayAttributes.get("defaultReplyChannel"); String errorChannel = (String) gatewayAttributes.get("errorChannel"); - String asyncExecutor = (String) gatewayAttributes.get("asyncExecutor"); - String mapper = (String) gatewayAttributes.get("mapper"); + String asyncExecutor = (String) gatewayAttributes.get(ASYNC_EXECUTOR_ATTR); + String mapper = (String) gatewayAttributes.get(MAPPER_ATTR); String proxyDefaultMethods = (String) gatewayAttributes.get(PROXY_DEFAULT_METHODS_ATTR); boolean hasMapper = StringUtils.hasText(mapper); @@ -229,13 +236,13 @@ public class GatewayParser implements BeanDefinitionParser { gatewayProxyBuilder.addPropertyValue("errorChannelName", errorChannel); } if (asyncExecutor == null || AnnotationConstants.NULL.equals(asyncExecutor)) { - gatewayProxyBuilder.addPropertyValue("asyncExecutor", null); + gatewayProxyBuilder.addPropertyValue(ASYNC_EXECUTOR_ATTR, null); } else if (StringUtils.hasText(asyncExecutor)) { - gatewayProxyBuilder.addPropertyReference("asyncExecutor", asyncExecutor); + gatewayProxyBuilder.addPropertyReference(ASYNC_EXECUTOR_ATTR, asyncExecutor); } if (StringUtils.hasText(mapper)) { - gatewayProxyBuilder.addPropertyReference("mapper", mapper); + gatewayProxyBuilder.addPropertyReference(MAPPER_ATTR, mapper); } if (StringUtils.hasText(proxyDefaultMethods)) { gatewayProxyBuilder.addPropertyValue(PROXY_DEFAULT_METHODS_ATTR, proxyDefaultMethods); @@ -247,7 +254,7 @@ public class GatewayParser implements BeanDefinitionParser { gatewayAttributes.get("defaultReplyTimeout")); gatewayProxyBuilder.addPropertyValue("methodMetadataMap", gatewayAttributes.get("methods")); - String id = (String) gatewayAttributes.get("name"); + String id = (String) gatewayAttributes.get(AbstractBeanDefinitionParser.NAME_ATTRIBUTE); if (!StringUtils.hasText(id)) { BeanNameGenerator beanNameGenerator = IntegrationConfigUtils.annotationBeanNameGenerator(registry); @@ -281,8 +288,8 @@ public class GatewayParser implements BeanDefinitionParser { if (!ObjectUtils.isEmpty(defaultHeaders)) { Map headerExpressions = new ManagedMap<>(); for (Map header : defaultHeaders) { - String headerValue = (String) header.get("value"); - String headerExpression = (String) header.get("expression"); + String headerValue = (String) header.get(IntegrationNamespaceUtils.VALUE_ATTRIBUTE); + String headerExpression = (String) header.get(IntegrationNamespaceUtils.EXPRESSION_ATTRIBUTE); boolean hasValue = StringUtils.hasText(headerValue); if (hasValue == StringUtils.hasText(headerExpression)) { @@ -295,7 +302,7 @@ public class GatewayParser implements BeanDefinitionParser { expressionDef.getConstructorArgumentValues() .addGenericArgumentValue(hasValue ? headerValue : headerExpression); - headerExpressions.put((String) header.get("name"), expressionDef); + headerExpressions.put((String) header.get(AbstractBeanDefinitionParser.NAME_ATTRIBUTE), expressionDef); } methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions); } 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 a3b0755394..9e8c0462bd 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,6 +71,8 @@ public abstract class IntegrationNamespaceUtils { public static final String REF_ATTRIBUTE = "ref"; + public static final String VALUE_ATTRIBUTE = "value"; + public static final String METHOD_ATTRIBUTE = "method"; public static final String ORDER = "order"; diff --git a/spring-integration-graphql/src/main/java/org/springframework/integration/graphql/dsl/package-info.java b/spring-integration-graphql/src/main/java/org/springframework/integration/graphql/dsl/package-info.java new file mode 100644 index 0000000000..d06699f4c4 --- /dev/null +++ b/spring-integration-graphql/src/main/java/org/springframework/integration/graphql/dsl/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides classes for Java DSL to support GraphQL components. + */ +package org.springframework.integration.graphql.dsl; diff --git a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/outbound/HazelcastCacheWritingMessageHandler.java b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/outbound/HazelcastCacheWritingMessageHandler.java index 27c7dfc9c6..32e9cd829c 100644 --- a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/outbound/HazelcastCacheWritingMessageHandler.java +++ b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/outbound/HazelcastCacheWritingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,59 +78,55 @@ public class HazelcastCacheWritingMessageHandler extends AbstractMessageHandler } @Override - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({ "unchecked", "rawtypes" }) protected void handleMessageInternal(final Message message) { Object objectToStore = message; if (this.extractPayload) { objectToStore = message.getPayload(); } - DistributedObject distributedObject = getDistributedObject(message); + DistributedObject object = getDistributedObject(message); - if (distributedObject instanceof Map) { - Map map = (Map) distributedObject; + if (object instanceof Map map) { if (objectToStore instanceof Map) { map.putAll((Map) objectToStore); } - else if (objectToStore instanceof Map.Entry) { - Map.Entry entry = (Map.Entry) objectToStore; + else if (objectToStore instanceof Map.Entry entry) { map.put(entry.getKey(), entry.getValue()); } else { map.put(getKey(message), objectToStore); } } - else if (distributedObject instanceof MultiMap) { - MultiMap map = (MultiMap) distributedObject; + else if (object instanceof MultiMap map) { if (objectToStore instanceof Map) { Map mapToStore = (Map) objectToStore; for (Map.Entry entry : mapToStore.entrySet()) { map.put(entry.getKey(), entry.getValue()); } } - else if (objectToStore instanceof Map.Entry) { - Map.Entry entry = (Map.Entry) objectToStore; + else if (objectToStore instanceof Map.Entry entry) { map.put(entry.getKey(), entry.getValue()); } else { map.put(getKey(message), objectToStore); } } - else if (distributedObject instanceof ITopic) { - ((ITopic) distributedObject).publish(objectToStore); + else if (object instanceof ITopic) { + ((ITopic) object).publish(objectToStore); } - else if (distributedObject instanceof Collection) { + else if (object instanceof Collection) { if (objectToStore instanceof Collection) { - ((Collection) distributedObject).addAll((Collection) objectToStore); + ((Collection) object).addAll((Collection) objectToStore); } else { - ((Collection) distributedObject).add(objectToStore); + ((Collection) object).add(objectToStore); } } else { - throw new IllegalStateException("The 'distributedObject' for 'HazelcastCacheWritingMessageHandler' " + + throw new IllegalStateException("The 'object' for 'HazelcastCacheWritingMessageHandler' " + "must be of 'IMap', 'MultiMap', 'ITopic', 'ISet' or 'IList' type, " + - "but gotten: [" + distributedObject + "]."); + "but gotten: [" + object + "]."); } } @@ -144,7 +140,7 @@ public class HazelcastCacheWritingMessageHandler extends AbstractMessageHandler } else if (message.getHeaders().containsKey(HazelcastHeaders.CACHE_NAME)) { return getBeanFactory() - .getBean(message.getHeaders().get(HazelcastHeaders.CACHE_NAME, String.class), + .getBean(message.getHeaders().get(HazelcastHeaders.CACHE_NAME, String.class), // NOSONAR DistributedObject.class); } else { diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/util/TestUtils.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/util/TestUtils.java index abb2090e6a..e21ecac45c 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/util/TestUtils.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/util/TestUtils.java @@ -257,10 +257,10 @@ public abstract class TestUtils { try { sent = errorChannel.send(new ErrorMessage(throwable), 10000); // NOSONAR } - catch (Throwable errorDeliveryError) { //NOSONAR + catch (Throwable errorDeliveryError) { // NOSONAR // message will be logged only logger.warn("Error message was not delivered.", errorDeliveryError); - if (errorDeliveryError instanceof Error) { // NOSONAR + if (errorDeliveryError instanceof Error) { // NOSONAR throw (Error) errorDeliveryError; } }