Removed channel and channel name properties from MessageEndpoint and its implementations. Now the MessageEndpoint only has the 'source' and 'target' properties.
This commit is contained in:
@@ -50,7 +50,6 @@ import org.springframework.integration.endpoint.EndpointRegistry;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.endpoint.MessagingGateway;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.integration.message.SubscribableSource;
|
||||
import org.springframework.integration.scheduling.PollingSchedule;
|
||||
@@ -268,29 +267,9 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
if (endpoint instanceof ChannelRegistryAware) {
|
||||
((ChannelRegistryAware) endpoint).setChannelRegistry(this);
|
||||
}
|
||||
MessageTarget target = endpoint.getTarget();
|
||||
if (target == null) {
|
||||
String outputChannelName = endpoint.getOutputChannelName();
|
||||
if (outputChannelName != null) {
|
||||
target = this.lookupChannel(outputChannelName);
|
||||
if (target == null) {
|
||||
throw new ConfigurationException("cannot activate endpoint '" + endpoint +
|
||||
"', unable to resolve output-channel '" + outputChannelName + "'");
|
||||
}
|
||||
endpoint.setTarget(target);
|
||||
}
|
||||
}
|
||||
MessageSource<?> source = endpoint.getSource();
|
||||
if (source == null) {
|
||||
String inputChannelName = endpoint.getInputChannelName();
|
||||
if (inputChannelName != null) {
|
||||
source = this.lookupChannel(inputChannelName);
|
||||
if (source == null) {
|
||||
throw new ConfigurationException("cannot activate endpoint '" + endpoint +
|
||||
"', unable to resolve input-channel '" + inputChannelName + "'");
|
||||
}
|
||||
endpoint.setSource(source);
|
||||
}
|
||||
throw new ConfigurationException("endpoint '" + endpoint + "' has no source");
|
||||
}
|
||||
if (source != null && source instanceof SubscribableSource) {
|
||||
((SubscribableSource) source).subscribe(endpoint);
|
||||
|
||||
@@ -93,7 +93,7 @@ public abstract class AbstractEndpointParser extends AbstractSingleBeanDefinitio
|
||||
builder.addPropertyReference("source", pollerBeanName);
|
||||
}
|
||||
else {
|
||||
builder.addPropertyValue("inputChannelName", inputChannel);
|
||||
builder.addPropertyReference("source", inputChannel);
|
||||
}
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(
|
||||
builder, element, OUTPUT_CHANNEL_ATTRIBUTE, "target");
|
||||
|
||||
@@ -100,7 +100,7 @@ public abstract class AbstractMessageEndpointParser extends AbstractSingleBeanDe
|
||||
builder.addPropertyReference("source", pollerBeanName);
|
||||
}
|
||||
else {
|
||||
builder.addPropertyValue("inputChannelName", inputChannel);
|
||||
builder.addPropertyReference("source", inputChannel);
|
||||
}
|
||||
Element interceptorsElement = DomUtils.getChildElementByTagName(element, INTERCEPTORS_ELEMENT);
|
||||
if (interceptorsElement != null) {
|
||||
@@ -108,8 +108,8 @@ public abstract class AbstractMessageEndpointParser extends AbstractSingleBeanDe
|
||||
ManagedList interceptors = parser.parseInterceptors(interceptorsElement, parserContext);
|
||||
builder.addPropertyValue("interceptors", interceptors);
|
||||
}
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(
|
||||
builder, element, OUTPUT_CHANNEL_ATTRIBUTE, "outputChannelName");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(
|
||||
builder, element, OUTPUT_CHANNEL_ATTRIBUTE, "target");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, SELECTOR_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, ERROR_HANDLER_ATTRIBUTE);
|
||||
this.postProcessEndpointBean(builder, element, parserContext);
|
||||
|
||||
@@ -46,7 +46,6 @@ import org.springframework.integration.handler.config.MessageHandlerCreator;
|
||||
import org.springframework.integration.router.RouterMessageHandlerCreator;
|
||||
import org.springframework.integration.splitter.SplitterMessageHandlerCreator;
|
||||
import org.springframework.integration.transformer.config.TransformerMessageHandlerCreator;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Post-processor for the {@link Handler @Handler} annotation.
|
||||
@@ -127,16 +126,7 @@ public class HandlerAnnotationPostProcessor extends AbstractAnnotationMethodPost
|
||||
|
||||
public MessageEndpoint createEndpoint(Object bean, String beanName, Class<?> originalBeanClass,
|
||||
org.springframework.integration.annotation.MessageEndpoint endpointAnnotation) {
|
||||
DefaultEndpoint<MessageHandler> endpoint = new DefaultEndpoint<MessageHandler>((MessageHandler) bean);
|
||||
String outputChannelName = endpointAnnotation.output();
|
||||
if (StringUtils.hasText(outputChannelName)) {
|
||||
endpoint.setOutputChannelName(outputChannelName);
|
||||
}
|
||||
String inputChannelName = endpointAnnotation.input();
|
||||
if (StringUtils.hasText(inputChannelName)) {
|
||||
endpoint.setInputChannelName(inputChannelName);
|
||||
}
|
||||
return endpoint;
|
||||
return new DefaultEndpoint<MessageHandler>((MessageHandler) bean);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -123,6 +123,17 @@ public class MessagingAnnotationPostProcessor implements BeanPostProcessor, Init
|
||||
throw new ConfigurationException("The @Poller annotation should only be provided for a PollableSource");
|
||||
}
|
||||
}
|
||||
else {
|
||||
endpoint.setSource(inputChannel);
|
||||
}
|
||||
String outputChannelName = endpointAnnotation.output();
|
||||
if (StringUtils.hasText(outputChannelName)) {
|
||||
MessageChannel outputChannel = this.messageBus.lookupChannel(outputChannelName);
|
||||
if (outputChannel == null) {
|
||||
throw new ConfigurationException("unable to resolve output channel '" + outputChannelName + "'");
|
||||
}
|
||||
endpoint.setTarget(outputChannel);
|
||||
}
|
||||
this.messageBus.registerEndpoint(endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,13 +26,16 @@ import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.annotation.Subscriber;
|
||||
import org.springframework.integration.bus.MessageBus;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.endpoint.DefaultEndpoint;
|
||||
import org.springframework.integration.handler.DefaultMessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A {@link BeanPostProcessor} that creates a method-invoking handler adapter
|
||||
@@ -86,6 +89,9 @@ public class SubscriberAnnotationPostProcessor implements BeanPostProcessor {
|
||||
Annotation annotation = method.getAnnotation(subscriberAnnotationType);
|
||||
if (annotation != null) {
|
||||
String channelName = (String) AnnotationUtils.getValue(annotation, channelNameAttribute);
|
||||
if (!StringUtils.hasText(channelName)) {
|
||||
throw new ConfigurationException("no channel name provided for subscriber");
|
||||
}
|
||||
DefaultMessageHandler handler = new DefaultMessageHandler();
|
||||
handler.setObject(bean);
|
||||
handler.setMethod(method);
|
||||
@@ -94,7 +100,11 @@ public class SubscriberAnnotationPostProcessor implements BeanPostProcessor {
|
||||
"." + method.getName() + ".endpoint";
|
||||
DefaultEndpoint<DefaultMessageHandler> endpoint = new DefaultEndpoint<DefaultMessageHandler>(handler);
|
||||
endpoint.setBeanName(endpointName);
|
||||
endpoint.setInputChannelName(channelName);
|
||||
MessageChannel inputChannel = messageBus.lookupChannel(channelName);
|
||||
if (inputChannel == null) {
|
||||
throw new ConfigurationException("unable to resolve channel '" + channelName + "' for subscriber");
|
||||
}
|
||||
endpoint.setSource(inputChannel);
|
||||
messageBus.registerEndpoint(endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.springframework.integration.channel.ChannelRegistry;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.message.CompositeMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
@@ -159,23 +158,4 @@ public abstract class AbstractInOutEndpoint extends AbstractEndpoint {
|
||||
return replyTarget;
|
||||
}
|
||||
|
||||
// TODO: remove these methods after refactoring
|
||||
|
||||
private volatile String inputChannelName;
|
||||
|
||||
public String getInputChannelName() {
|
||||
return this.inputChannelName;
|
||||
}
|
||||
|
||||
public void setInputChannelName(String inputChannelName) {
|
||||
this.inputChannelName = inputChannelName;
|
||||
}
|
||||
|
||||
public String getOutputChannelName() {
|
||||
if (this.getTarget() instanceof MessageChannel) {
|
||||
return ((MessageChannel) this.getTarget()).getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,41 +16,18 @@
|
||||
|
||||
package org.springframework.integration.endpoint;
|
||||
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.message.CompositeMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractRequestReplyEndpoint extends AbstractEndpoint {
|
||||
|
||||
private volatile String inputChannelName;
|
||||
|
||||
private volatile String outputChannelName;
|
||||
|
||||
private volatile boolean requiresReply = false;
|
||||
|
||||
|
||||
public String getInputChannelName() {
|
||||
return this.inputChannelName;
|
||||
}
|
||||
|
||||
public void setInputChannelName(String inputChannelName) {
|
||||
this.inputChannelName = inputChannelName;
|
||||
}
|
||||
|
||||
public String getOutputChannelName() {
|
||||
return this.outputChannelName;
|
||||
}
|
||||
|
||||
public void setOutputChannelName(String outputChannelName) {
|
||||
this.outputChannelName = outputChannelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether this endpoint should throw an Exception when
|
||||
* it returns an invalid reply Message after handling the request.
|
||||
@@ -85,20 +62,4 @@ public abstract class AbstractRequestReplyEndpoint extends AbstractEndpoint {
|
||||
|
||||
protected abstract void sendReplyMessage(Message<?> replyMessage, Message<?> requestMessage);
|
||||
|
||||
@Override
|
||||
public void setSource(MessageSource<?> source) {
|
||||
if (source instanceof MessageChannel) {
|
||||
this.setInputChannelName(((MessageChannel) source).getName());
|
||||
}
|
||||
super.setSource(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTarget(MessageTarget target) {
|
||||
if (target instanceof MessageChannel) {
|
||||
this.setOutputChannelName(((MessageChannel) target).getName());
|
||||
}
|
||||
super.setTarget(target);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.List;
|
||||
|
||||
import org.springframework.integration.channel.ChannelRegistry;
|
||||
import org.springframework.integration.channel.ChannelRegistryAware;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.CompositeMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
@@ -203,11 +202,4 @@ public class DefaultEndpoint<T extends MessageHandler> extends AbstractRequestRe
|
||||
return replyTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the channel where reply Messages should be sent.
|
||||
*/
|
||||
public void setOutputChannel(MessageChannel outputChannel) {
|
||||
this.setTarget(outputChannel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,18 +49,4 @@ public class InboundChannelAdapter extends AbstractEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
public String getInputChannelName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getOutputChannelName() {
|
||||
if (this.getTarget() instanceof MessageChannel) {
|
||||
return ((MessageChannel) this.getTarget()).getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setInputChannelName(String inputChannelName) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,10 +37,4 @@ public interface MessageEndpoint extends MessageTarget, BeanNameAware {
|
||||
|
||||
MessageTarget getTarget();
|
||||
|
||||
void setInputChannelName(String inputChannelName);
|
||||
|
||||
String getInputChannelName();
|
||||
|
||||
String getOutputChannelName();
|
||||
|
||||
}
|
||||
|
||||
@@ -32,18 +32,4 @@ public class OutboundChannelAdapter extends AbstractEndpoint {
|
||||
return this.getMessageExchangeTemplate().send(message, this.getTarget());
|
||||
}
|
||||
|
||||
public String getInputChannelName() {
|
||||
if (this.getSource() instanceof MessageChannel) {
|
||||
return ((MessageChannel) this.getSource()).getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getOutputChannelName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setInputChannelName(String inputChannelName) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,21 +87,4 @@ public class RouterEndpoint extends AbstractEndpoint {
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
||||
// TODO: remove these methods after refactoring
|
||||
|
||||
private volatile String inputChannelName;
|
||||
|
||||
public String getInputChannelName() {
|
||||
return this.inputChannelName;
|
||||
}
|
||||
|
||||
public void setInputChannelName(String inputChannelName) {
|
||||
this.inputChannelName = inputChannelName;
|
||||
}
|
||||
|
||||
public String getOutputChannelName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user