Skip to content

Commit 18fcd21

Browse files
committed
Fix latest Sonar fixes
* Some code style improvement for SMB classes * Make an `SmbSessionTests` based on the `SmbTestSupport` for faster execution, but not blocking on fake URL connection attempt * Remove `AbstractMqttMessageDrivenChannelAdapter.Topic` model in favor of `LinkedHashMap` handling
1 parent d31f309 commit 18fcd21

File tree

14 files changed

+210
-341
lines changed

14 files changed

+210
-341
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/RouterAnnotationPostProcessor.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,21 @@
4949
*/
5050
public class RouterAnnotationPostProcessor extends AbstractMethodAnnotationPostProcessor<Router> {
5151

52+
private static final String APPLY_SEQUENCE_ATTR = "applySequence";
53+
54+
private static final String IGNORE_SEND_FAILURES_ATTR = "ignoreSendFailures";
55+
56+
private static final String CHANNEL_MAPPINGS_ATTR = "channelMappings";
57+
58+
private static final String RESOLUTION_REQUIRED_ATTR = "resolutionRequired";
59+
60+
private static final String PREFIX_ATTR = "prefix";
61+
62+
private static final String SUFFIX_ATTR = "suffix";
63+
5264
public RouterAnnotationPostProcessor() {
53-
this.messageHandlerAttributes.addAll(Arrays.asList("defaultOutputChannel", "applySequence",
54-
"ignoreSendFailures", "resolutionRequired", "channelMappings", "prefix", "suffix"));
65+
this.messageHandlerAttributes.addAll(Arrays.asList("defaultOutputChannel", APPLY_SEQUENCE_ATTR,
66+
IGNORE_SEND_FAILURES_ATTR, RESOLUTION_REQUIRED_ATTR, CHANNEL_MAPPINGS_ATTR, PREFIX_ATTR, SUFFIX_ATTR));
5567
}
5668

5769
@Override
@@ -76,13 +88,13 @@ protected BeanDefinition resolveHandlerBeanDefinition(String beanName, Annotated
7688
.getBeanDefinition();
7789

7890
new BeanDefinitionPropertiesMapper(routerBeanDefinition, annotations)
79-
.setPropertyValue("applySequence")
80-
.setPropertyValue("ignoreSendFailures")
81-
.setPropertyValue("resolutionRequired")
82-
.setPropertyValue("prefix")
83-
.setPropertyValue("suffix");
91+
.setPropertyValue(APPLY_SEQUENCE_ATTR)
92+
.setPropertyValue(IGNORE_SEND_FAILURES_ATTR)
93+
.setPropertyValue(RESOLUTION_REQUIRED_ATTR)
94+
.setPropertyValue(PREFIX_ATTR)
95+
.setPropertyValue(SUFFIX_ATTR);
8496

85-
String[] channelMappings = MessagingAnnotationUtils.resolveAttribute(annotations, "channelMappings",
97+
String[] channelMappings = MessagingAnnotationUtils.resolveAttribute(annotations, CHANNEL_MAPPINGS_ATTR,
8698
String[].class);
8799
if (!ObjectUtils.isEmpty(channelMappings)) {
88100
Map<String, String> mappings =
@@ -94,7 +106,7 @@ protected BeanDefinition resolveHandlerBeanDefinition(String beanName, Annotated
94106
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
95107

96108
routerBeanDefinition.getPropertyValues()
97-
.addPropertyValue("channelMappings", mappings);
109+
.addPropertyValue(CHANNEL_MAPPINGS_ATTR, mappings);
98110
}
99111

100112
return routerBeanDefinition;
@@ -109,12 +121,12 @@ protected MessageHandler createHandler(Object bean, Method method, List<Annotati
109121
router.setDefaultOutputChannelName(defaultOutputChannelName);
110122
}
111123

112-
String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, "applySequence", String.class);
124+
String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, APPLY_SEQUENCE_ATTR, String.class);
113125
if (StringUtils.hasText(applySequence)) {
114126
router.setApplySequence(resolveAttributeToBoolean(applySequence));
115127
}
116128

117-
String ignoreSendFailures = MessagingAnnotationUtils.resolveAttribute(annotations, "ignoreSendFailures",
129+
String ignoreSendFailures = MessagingAnnotationUtils.resolveAttribute(annotations, IGNORE_SEND_FAILURES_ATTR,
118130
String.class);
119131
if (StringUtils.hasText(ignoreSendFailures)) {
120132
router.setIgnoreSendFailures(resolveAttributeToBoolean(ignoreSendFailures));
@@ -130,25 +142,25 @@ private void routerAttributes(List<Annotation> annotations, AbstractMessageRoute
130142

131143
MethodInvokingRouter methodInvokingRouter = (MethodInvokingRouter) router;
132144

133-
String resolutionRequired = MessagingAnnotationUtils.resolveAttribute(annotations, "resolutionRequired",
145+
String resolutionRequired = MessagingAnnotationUtils.resolveAttribute(annotations, RESOLUTION_REQUIRED_ATTR,
134146
String.class);
135147
if (StringUtils.hasText(resolutionRequired)) {
136148
methodInvokingRouter.setResolutionRequired(resolveAttributeToBoolean(resolutionRequired));
137149
}
138150

139151
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
140152

141-
String prefix = MessagingAnnotationUtils.resolveAttribute(annotations, "prefix", String.class);
153+
String prefix = MessagingAnnotationUtils.resolveAttribute(annotations, PREFIX_ATTR, String.class);
142154
if (StringUtils.hasText(prefix)) {
143155
methodInvokingRouter.setPrefix(beanFactory.resolveEmbeddedValue(prefix));
144156
}
145157

146-
String suffix = MessagingAnnotationUtils.resolveAttribute(annotations, "suffix", String.class);
158+
String suffix = MessagingAnnotationUtils.resolveAttribute(annotations, SUFFIX_ATTR, String.class);
147159
if (StringUtils.hasText(suffix)) {
148160
methodInvokingRouter.setSuffix(beanFactory.resolveEmbeddedValue(suffix));
149161
}
150162

151-
String[] channelMappings = MessagingAnnotationUtils.resolveAttribute(annotations, "channelMappings",
163+
String[] channelMappings = MessagingAnnotationUtils.resolveAttribute(annotations, CHANNEL_MAPPINGS_ATTR,
152164
String[].class);
153165
if (!ObjectUtils.isEmpty(channelMappings)) {
154166
StringBuilder mappings = new StringBuilder();
@@ -166,14 +178,14 @@ private void routerAttributes(List<Annotation> annotations, AbstractMessageRoute
166178
private boolean routerAttributesProvided(List<Annotation> annotations) {
167179
String defaultOutputChannel = MessagingAnnotationUtils.resolveAttribute(annotations, "defaultOutputChannel",
168180
String.class);
169-
String[] channelMappings = MessagingAnnotationUtils.resolveAttribute(annotations, "channelMappings",
181+
String[] channelMappings = MessagingAnnotationUtils.resolveAttribute(annotations, CHANNEL_MAPPINGS_ATTR,
170182
String[].class);
171-
String prefix = MessagingAnnotationUtils.resolveAttribute(annotations, "prefix", String.class);
172-
String suffix = MessagingAnnotationUtils.resolveAttribute(annotations, "suffix", String.class);
173-
String resolutionRequired = MessagingAnnotationUtils.resolveAttribute(annotations, "resolutionRequired",
183+
String prefix = MessagingAnnotationUtils.resolveAttribute(annotations, PREFIX_ATTR, String.class);
184+
String suffix = MessagingAnnotationUtils.resolveAttribute(annotations, SUFFIX_ATTR, String.class);
185+
String resolutionRequired = MessagingAnnotationUtils.resolveAttribute(annotations, RESOLUTION_REQUIRED_ATTR,
174186
String.class);
175-
String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, "applySequence", String.class);
176-
String ignoreSendFailures = MessagingAnnotationUtils.resolveAttribute(annotations, "ignoreSendFailures",
187+
String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, APPLY_SEQUENCE_ATTR, String.class);
188+
String ignoreSendFailures = MessagingAnnotationUtils.resolveAttribute(annotations, IGNORE_SEND_FAILURES_ATTR,
177189
String.class);
178190
return StringUtils.hasText(defaultOutputChannel) || !ObjectUtils.isEmpty(channelMappings) // NOSONAR complexity
179191
|| StringUtils.hasText(prefix) || StringUtils.hasText(suffix) || StringUtils.hasText(resolutionRequired)

spring-integration-core/src/main/java/org/springframework/integration/config/SplitterAnnotationPostProcessor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
*/
4444
public class SplitterAnnotationPostProcessor extends AbstractMethodAnnotationPostProcessor<Splitter> {
4545

46+
private static final String APPLY_SEQUENCE_ATTR = "applySequence";
47+
4648
public SplitterAnnotationPostProcessor() {
47-
this.messageHandlerAttributes.addAll(Arrays.asList("outputChannel", "applySequence", "adviceChain"));
49+
this.messageHandlerAttributes.addAll(Arrays.asList("outputChannel", APPLY_SEQUENCE_ATTR, "adviceChain"));
4850
}
4951

5052
@Override
@@ -67,9 +69,9 @@ protected BeanDefinition resolveHandlerBeanDefinition(String beanName, Annotated
6769
BeanDefinitionBuilder.genericBeanDefinition(SplitterFactoryBean.class)
6870
.addPropertyValue("targetObject", targetObjectBeanDefinition);
6971

70-
String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, "applySequence", String.class);
72+
String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, APPLY_SEQUENCE_ATTR, String.class);
7173
if (StringUtils.hasText(applySequence)) {
72-
splitterBeanDefinition.addPropertyValue("applySequence", applySequence);
74+
splitterBeanDefinition.addPropertyValue(APPLY_SEQUENCE_ATTR, applySequence);
7375
}
7476
return splitterBeanDefinition.getBeanDefinition();
7577
}
@@ -78,7 +80,7 @@ protected BeanDefinition resolveHandlerBeanDefinition(String beanName, Annotated
7880
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
7981
AbstractMessageSplitter splitter = new MethodInvokingSplitter(bean, method);
8082

81-
String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, "applySequence", String.class);
83+
String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, APPLY_SEQUENCE_ATTR, String.class);
8284
if (StringUtils.hasText(applySequence)) {
8385
splitter.setApplySequence(resolveAttributeToBoolean(applySequence));
8486
}

spring-integration-core/src/main/java/org/springframework/integration/handler/LambdaMessageProcessor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ public Object processMessage(Message<?> message) {
126126
logClassCastException(ex);
127127
throw ex;
128128
}
129-
catch (RuntimeException ex) {
130-
throw ex;
131-
}
132129
catch (InvocationTargetException e) {
133130
final Throwable cause = e.getCause();
134131
if (e.getTargetException() instanceof ClassCastException classCastException) {
@@ -140,10 +137,13 @@ public Object processMessage(Message<?> message) {
140137
throw new IllegalStateException(// NOSONAR lost stack trace
141138
"Could not invoke the method '" + this.method + "'", cause);
142139
}
143-
catch (Exception e) {
140+
catch (Exception ex) {
141+
if (ex instanceof RuntimeException) { // NOSONAR
142+
throw (RuntimeException) ex;
143+
}
144144
throw new IllegalStateException(
145145
"error occurred during processing message in 'LambdaMessageProcessor' for method [" +
146-
this.method + "]", e);
146+
this.method + "]", ex);
147147
}
148148
}
149149

spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/config/xml/HazelcastContinuousQueryInboundChannelAdapterParser.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,8 @@
3333
* {@code <int-hazelcast:cq-inbound-channel-adapter/>} configuration.
3434
*
3535
* @author Eren Avsarogullari
36+
* @author Artem Bilan
37+
*
3638
* @since 6.0
3739
*/
3840
public class HazelcastContinuousQueryInboundChannelAdapterParser extends AbstractSingleBeanDefinitionParser {
@@ -82,27 +84,30 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
8284
}
8385

8486
if (!StringUtils.hasText(element.getAttribute(CACHE_ATTRIBUTE))) {
85-
parserContext.getReaderContext().error("'" + CACHE_ATTRIBUTE + "' attribute is required.", element);
87+
errorAttributeRequired(element, parserContext, CACHE_ATTRIBUTE);
8688
}
8789
else if (!StringUtils.hasText(element.getAttribute(CACHE_EVENTS_ATTRIBUTE))) {
88-
parserContext.getReaderContext().error("'" + CACHE_EVENTS_ATTRIBUTE + "' attribute is required.", element);
90+
errorAttributeRequired(element, parserContext, CACHE_EVENTS_ATTRIBUTE);
8991
}
9092
else if (!StringUtils.hasText(element.getAttribute(PREDICATE_ATTRIBUTE))) {
91-
parserContext.getReaderContext().error("'" + PREDICATE_ATTRIBUTE + "' attribute is required.", element);
93+
errorAttributeRequired(element, parserContext, PREDICATE_ATTRIBUTE);
9294
}
9395
else if (!StringUtils.hasText(element.getAttribute(CACHE_LISTENING_POLICY_ATTRIBUTE))) {
94-
parserContext.getReaderContext().error("'" + CACHE_LISTENING_POLICY_ATTRIBUTE + "' attribute is required.",
95-
element);
96+
errorAttributeRequired(element, parserContext, CACHE_LISTENING_POLICY_ATTRIBUTE);
9697
}
9798

98-
builder.addPropertyReference(OUTPUT_CHANNEL, channelName);
99-
builder.addConstructorArgReference(element.getAttribute(CACHE_ATTRIBUTE));
100-
builder.addConstructorArgValue(element.getAttribute(PREDICATE_ATTRIBUTE));
99+
builder.addPropertyReference(OUTPUT_CHANNEL, channelName)
100+
.addConstructorArgReference(element.getAttribute(CACHE_ATTRIBUTE))
101+
.addConstructorArgValue(element.getAttribute(PREDICATE_ATTRIBUTE));
101102
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, CACHE_EVENTS_ATTRIBUTE, CACHE_EVENT_TYPES);
102103
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, INCLUDE_VALUE_ATTRIBUTE);
103104
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, CACHE_LISTENING_POLICY_ATTRIBUTE);
104105
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.AUTO_STARTUP);
105106
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.PHASE);
106107
}
107108

109+
private static void errorAttributeRequired(Element element, ParserContext parserContext, String attribute) {
110+
parserContext.getReaderContext().error("'" + attribute + "' attribute is required.", element);
111+
}
112+
108113
}

0 commit comments

Comments
 (0)