Skip to content

Commit a40f20f

Browse files
garyrussellartembilan
authored andcommitted
Resolve new tangles
- `MessagePublishingErrorHandler <-> IntegrationContextUtils`
1 parent 6c3ffcb commit a40f20f

File tree

17 files changed

+146
-71
lines changed

17 files changed

+146
-71
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
import org.springframework.core.ParameterNameDiscoverer;
3232
import org.springframework.expression.Expression;
3333
import org.springframework.expression.spel.support.StandardEvaluationContext;
34-
import org.springframework.integration.context.IntegrationContextUtils;
3534
import org.springframework.integration.core.MessagingTemplate;
3635
import org.springframework.integration.expression.ExpressionEvalMap;
3736
import org.springframework.integration.expression.ExpressionUtils;
3837
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
3938
import org.springframework.integration.support.DefaultMessageBuilderFactory;
4039
import org.springframework.integration.support.MessageBuilderFactory;
40+
import org.springframework.integration.support.channel.ChannelResolverUtils;
4141
import org.springframework.integration.support.utils.IntegrationUtils;
4242
import org.springframework.messaging.Message;
4343
import org.springframework.messaging.MessageChannel;
@@ -104,7 +104,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
104104
this.beanFactory = beanFactory;
105105
this.messagingTemplate.setBeanFactory(beanFactory);
106106
if (this.channelResolver == null) {
107-
this.channelResolver = IntegrationContextUtils.getChannelResolver(this.beanFactory);
107+
this.channelResolver = ChannelResolverUtils.getChannelResolver(this.beanFactory);
108108
}
109109
}
110110

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.channel;
18+
19+
import org.springframework.beans.factory.BeanFactory;
20+
import org.springframework.integration.support.channel.ChannelResolverUtils;
21+
import org.springframework.messaging.core.DestinationResolver;
22+
import org.springframework.util.Assert;
23+
import org.springframework.util.ErrorHandler;
24+
25+
/**
26+
* Channel utilities.
27+
*
28+
* @author Artem Bilan
29+
* @author Gary Russell
30+
* @since 5.2
31+
*
32+
*/
33+
public final class ChannelUtils {
34+
35+
public static final String MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME = "integrationMessagePublishingErrorHandler";
36+
37+
private ChannelUtils() {
38+
super();
39+
}
40+
41+
/**
42+
* Obtain an {@link ErrorHandler} registered with the
43+
* {@value MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME} bean name.
44+
* By default resolves to the {@link org.springframework.integration.channel.MessagePublishingErrorHandler}
45+
* with the {@value ChannelResolverUtils#CHANNEL_RESOLVER_BEAN_NAME} {@link DestinationResolver} bean.
46+
* @param beanFactory BeanFactory for lookup, must not be null.
47+
* @return the instance of {@link ErrorHandler} bean whose name is
48+
* {@value MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME}.
49+
*/
50+
public static ErrorHandler getErrorHandler(BeanFactory beanFactory) {
51+
Assert.notNull(beanFactory, "'beanFactory' must not be null");
52+
if (!beanFactory.containsBean(MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME)) {
53+
return new MessagePublishingErrorHandler(ChannelResolverUtils.getChannelResolver(beanFactory));
54+
}
55+
return beanFactory.getBean(MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME, ErrorHandler.class);
56+
}
57+
58+
59+
}

spring-integration-core/src/main/java/org/springframework/integration/channel/ExecutorChannel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.concurrent.Executor;
2020

21-
import org.springframework.integration.context.IntegrationContextUtils;
2221
import org.springframework.integration.context.IntegrationProperties;
2322
import org.springframework.integration.dispatcher.LoadBalancingStrategy;
2423
import org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy;
@@ -103,7 +102,7 @@ public final void onInit() {
103102
+ "bean is fully initialized by the framework. Do not subscribe in a @Bean definition");
104103
super.onInit();
105104
if (!(this.executor instanceof ErrorHandlingTaskExecutor)) {
106-
ErrorHandler errorHandler = IntegrationContextUtils.getErrorHandler(getBeanFactory());
105+
ErrorHandler errorHandler = ChannelUtils.getErrorHandler(getBeanFactory());
107106
this.executor = new ErrorHandlingTaskExecutor(this.executor, errorHandler);
108107
}
109108
UnicastingDispatcher unicastingDispatcher = new UnicastingDispatcher(this.executor);

spring-integration-core/src/main/java/org/springframework/integration/channel/PublishSubscribeChannel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.concurrent.Executor;
2020

2121
import org.springframework.beans.factory.BeanFactory;
22-
import org.springframework.integration.context.IntegrationContextUtils;
2322
import org.springframework.integration.context.IntegrationProperties;
2423
import org.springframework.integration.dispatcher.BroadcastingDispatcher;
2524
import org.springframework.integration.util.ErrorHandlingTaskExecutor;
@@ -139,7 +138,7 @@ public final void onInit() {
139138
+ "bean is fully initialized by the framework. Do not subscribe in a @Bean definition");
140139
if (!(this.executor instanceof ErrorHandlingTaskExecutor)) {
141140
if (this.errorHandler == null) {
142-
this.errorHandler = IntegrationContextUtils.getErrorHandler(beanFactory);
141+
this.errorHandler = ChannelUtils.getErrorHandler(beanFactory);
143142
}
144143
this.executor = new ErrorHandlingTaskExecutor(this.executor, this.errorHandler);
145144
}

spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import org.springframework.beans.factory.BeanFactory;
2424
import org.springframework.beans.factory.BeanFactoryAware;
2525
import org.springframework.context.Lifecycle;
26-
import org.springframework.integration.context.IntegrationContextUtils;
2726
import org.springframework.integration.core.MessageSelector;
27+
import org.springframework.integration.support.channel.ChannelResolverUtils;
2828
import org.springframework.jmx.export.annotation.ManagedAttribute;
2929
import org.springframework.jmx.export.annotation.ManagedOperation;
3030
import org.springframework.jmx.export.annotation.ManagedResource;
@@ -182,7 +182,7 @@ private MessageChannel getChannel() {
182182
String channelNameToUse = this.channelName;
183183
if (channelNameToUse != null) {
184184
this.channel =
185-
IntegrationContextUtils.getChannelResolver(this.beanFactory)
185+
ChannelResolverUtils.getChannelResolver(this.beanFactory)
186186
.resolveDestination(channelNameToUse);
187187
this.channelName = null;
188188
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.springframework.core.io.Resource;
5050
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
5151
import org.springframework.core.io.support.ResourcePatternResolver;
52+
import org.springframework.integration.channel.ChannelUtils;
5253
import org.springframework.integration.channel.DefaultHeaderChannelRegistry;
5354
import org.springframework.integration.channel.MessagePublishingErrorHandler;
5455
import org.springframework.integration.channel.NullChannel;
@@ -64,6 +65,7 @@
6465
import org.springframework.integration.support.NullAwarePayloadArgumentResolver;
6566
import org.springframework.integration.support.SmartLifecycleRoleController;
6667
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
68+
import org.springframework.integration.support.channel.ChannelResolverUtils;
6769
import org.springframework.integration.support.converter.ConfigurableCompositeMessageConverter;
6870
import org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter;
6971
import org.springframework.integration.support.json.JacksonPresent;
@@ -149,16 +151,16 @@ public void afterSingletonsInstantiated() {
149151
}
150152

151153
private void registerBeanFactoryChannelResolver() {
152-
if (!this.beanFactory.containsBeanDefinition(IntegrationContextUtils.CHANNEL_RESOLVER_BEAN_NAME)) {
153-
this.registry.registerBeanDefinition(IntegrationContextUtils.CHANNEL_RESOLVER_BEAN_NAME,
154+
if (!this.beanFactory.containsBeanDefinition(ChannelResolverUtils.CHANNEL_RESOLVER_BEAN_NAME)) {
155+
this.registry.registerBeanDefinition(ChannelResolverUtils.CHANNEL_RESOLVER_BEAN_NAME,
154156
new RootBeanDefinition(BeanFactoryChannelResolver.class));
155157
}
156158
}
157159

158160
private void registerMessagePublishingErrorHandler() {
159161
if (!this.beanFactory.containsBeanDefinition(
160-
IntegrationContextUtils.MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME)) {
161-
this.registry.registerBeanDefinition(IntegrationContextUtils.MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME,
162+
ChannelUtils.MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME)) {
163+
this.registry.registerBeanDefinition(ChannelUtils.MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME,
162164
new RootBeanDefinition(MessagePublishingErrorHandler.class));
163165
}
164166
}
@@ -301,7 +303,7 @@ private void registerTaskScheduler() {
301303
.addPropertyValue("threadNamePrefix", "task-scheduler-")
302304
.addPropertyValue("rejectedExecutionHandler", new CallerRunsPolicy())
303305
.addPropertyReference("errorHandler",
304-
IntegrationContextUtils.MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME)
306+
ChannelUtils.MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME)
305307
.getBeanDefinition();
306308

307309
this.registry.registerBeanDefinition(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, scheduler);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.springframework.integration.channel.DirectChannel;
5555
import org.springframework.integration.channel.MessagePublishingErrorHandler;
5656
import org.springframework.integration.config.IntegrationConfigUtils;
57-
import org.springframework.integration.context.IntegrationContextUtils;
5857
import org.springframework.integration.context.Orderable;
5958
import org.springframework.integration.endpoint.AbstractEndpoint;
6059
import org.springframework.integration.endpoint.AbstractPollingEndpoint;
@@ -70,6 +69,7 @@
7069
import org.springframework.integration.handler.advice.HandleMessageAdvice;
7170
import org.springframework.integration.router.AbstractMessageRouter;
7271
import org.springframework.integration.scheduling.PollerMetadata;
72+
import org.springframework.integration.support.channel.ChannelResolverUtils;
7373
import org.springframework.integration.util.ClassUtils;
7474
import org.springframework.integration.util.MessagingAnnotationUtils;
7575
import org.springframework.lang.Nullable;
@@ -125,7 +125,7 @@ public AbstractMethodAnnotationPostProcessor(ConfigurableListableBeanFactory bea
125125
this.conversionService = this.beanFactory.getConversionService() != null
126126
? this.beanFactory.getConversionService()
127127
: DefaultConversionService.getSharedInstance();
128-
this.channelResolver = IntegrationContextUtils.getChannelResolver(beanFactory);
128+
this.channelResolver = ChannelResolverUtils.getChannelResolver(beanFactory);
129129
this.annotationType =
130130
(Class<T>) GenericTypeResolver.resolveTypeArgument(this.getClass(),
131131
MethodAnnotationPostProcessor.class);

spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@
2323
import org.springframework.beans.factory.support.RootBeanDefinition;
2424
import org.springframework.expression.spel.support.SimpleEvaluationContext;
2525
import org.springframework.expression.spel.support.StandardEvaluationContext;
26-
import org.springframework.integration.channel.MessagePublishingErrorHandler;
2726
import org.springframework.integration.config.IntegrationConfigUtils;
2827
import org.springframework.integration.metadata.MetadataStore;
29-
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
3028
import org.springframework.messaging.MessageChannel;
31-
import org.springframework.messaging.core.DestinationResolver;
3229
import org.springframework.scheduling.TaskScheduler;
3330
import org.springframework.util.Assert;
34-
import org.springframework.util.ErrorHandler;
3531

3632
/**
3733
* Utility methods for accessing common integration components from the BeanFactory.
@@ -111,10 +107,6 @@ public abstract class IntegrationContextUtils {
111107

112108
public static final String LIST_MESSAGE_HANDLER_FACTORY_BEAN_NAME = "integrationListMessageHandlerMethodFactory";
113109

114-
public static final String CHANNEL_RESOLVER_BEAN_NAME = "integrationChannelResolver";
115-
116-
public static final String MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME = "integrationMessagePublishingErrorHandler";
117-
118110
/**
119111
* @param beanFactory BeanFactory for lookup, must not be null.
120112
* @return The {@link MetadataStore} bean whose name is "metadataStore".
@@ -220,39 +212,4 @@ public static Properties getIntegrationProperties(BeanFactory beanFactory) {
220212
return properties;
221213
}
222214

223-
/**
224-
* Obtain a {@link DestinationResolver} registered with the
225-
* {@value #CHANNEL_RESOLVER_BEAN_NAME} bean name.
226-
* @param beanFactory BeanFactory for lookup, must not be null.
227-
* @return the instance of {@link DestinationResolver} bean whose name is
228-
* {@value #CHANNEL_RESOLVER_BEAN_NAME}.
229-
* @since 5.2
230-
*/
231-
@SuppressWarnings("unchecked")
232-
public static DestinationResolver<MessageChannel> getChannelResolver(BeanFactory beanFactory) {
233-
Assert.notNull(beanFactory, "'beanFactory' must not be null");
234-
if (!beanFactory.containsBean(CHANNEL_RESOLVER_BEAN_NAME)) {
235-
return new BeanFactoryChannelResolver(beanFactory);
236-
}
237-
return beanFactory.getBean(CHANNEL_RESOLVER_BEAN_NAME, DestinationResolver.class);
238-
}
239-
240-
/**
241-
* Obtain an {@link ErrorHandler} registered with the
242-
* {@value #MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME} bean name.
243-
* By default resolves to the {@link org.springframework.integration.channel.MessagePublishingErrorHandler}
244-
* with the {@value #CHANNEL_RESOLVER_BEAN_NAME} {@link DestinationResolver} bean.
245-
* @param beanFactory BeanFactory for lookup, must not be null.
246-
* @return the instance of {@link ErrorHandler} bean whose name is
247-
* {@value #MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME}.
248-
* @since 5.2
249-
*/
250-
public static ErrorHandler getErrorHandler(BeanFactory beanFactory) {
251-
Assert.notNull(beanFactory, "'beanFactory' must not be null");
252-
if (!beanFactory.containsBean(MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME)) {
253-
return new MessagePublishingErrorHandler(getChannelResolver(beanFactory));
254-
}
255-
return beanFactory.getBean(MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME, ErrorHandler.class);
256-
}
257-
258215
}

spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.springframework.expression.spel.standard.SpelExpressionParser;
3838
import org.springframework.integration.support.DefaultMessageBuilderFactory;
3939
import org.springframework.integration.support.MessageBuilderFactory;
40+
import org.springframework.integration.support.channel.ChannelResolverUtils;
4041
import org.springframework.integration.support.context.NamedComponent;
4142
import org.springframework.integration.support.utils.IntegrationUtils;
4243
import org.springframework.lang.Nullable;
@@ -227,7 +228,7 @@ protected TaskScheduler getTaskScheduler() {
227228

228229
protected DestinationResolver<MessageChannel> getChannelResolver() {
229230
if (this.channelResolver == null) {
230-
this.channelResolver = IntegrationContextUtils.getChannelResolver(this.beanFactory);
231+
this.channelResolver = ChannelResolverUtils.getChannelResolver(this.beanFactory);
231232
}
232233
return this.channelResolver;
233234
}

spring-integration-core/src/main/java/org/springframework/integration/core/ErrorMessagePublisher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.integration.support.DefaultErrorMessageStrategy;
2727
import org.springframework.integration.support.ErrorMessageStrategy;
2828
import org.springframework.integration.support.ErrorMessageUtils;
29+
import org.springframework.integration.support.channel.ChannelResolverUtils;
2930
import org.springframework.lang.Nullable;
3031
import org.springframework.messaging.Message;
3132
import org.springframework.messaging.MessageChannel;
@@ -96,7 +97,7 @@ public final void setChannelResolver(DestinationResolver<MessageChannel> channel
9697
public void setBeanFactory(BeanFactory beanFactory) {
9798
Assert.notNull(beanFactory, "beanFactory must not be null");
9899
if (this.channelResolver == null) {
99-
this.channelResolver = IntegrationContextUtils.getChannelResolver(beanFactory);
100+
this.channelResolver = ChannelResolverUtils.getChannelResolver(beanFactory);
100101
}
101102
}
102103

0 commit comments

Comments
 (0)