This commit is contained in:
Mark Fisher
2008-11-21 22:03:27 +00:00
parent 837a295cbe
commit 2b166d6471
10 changed files with 133 additions and 261 deletions

View File

@@ -44,8 +44,6 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit
private static final String POLLER_ELEMENT = "poller";
private static final String SELECTOR_ATTRIBUTE = "selector";
@Override
protected boolean shouldGenerateId() {
@@ -77,8 +75,6 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ConsumerEndpointFactoryBean.class);
String handlerBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(handlerBeanDefinition, parserContext.getRegistry());
builder.addConstructorArgReference(handlerBeanName);
// TODO: remove the 'selector'
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(handlerBuilder, element, SELECTOR_ATTRIBUTE);
String inputChannelAttributeName = this.getInputChannelAttributeName();
String inputChannelName = element.getAttribute(inputChannelAttributeName);
Assert.hasText(inputChannelName, "the '" + inputChannelAttributeName + "' attribute is required");

View File

@@ -227,7 +227,6 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="selector" type="xsd:string"/>
<xsd:attribute name="auto-startup" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>

View File

@@ -19,32 +19,55 @@ package org.springframework.integration.filter;
import org.springframework.integration.core.Message;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.handler.ReplyMessageHolder;
import org.springframework.integration.message.MessageRejectedException;
import org.springframework.integration.selector.MessageSelector;
import org.springframework.util.Assert;
/**
* Message Handler that delegates to a {@link MessageSelector}. If and only if
* the selector {@link MessageSelector#accept(Message) accepts} the Message, it
* will be passed to this filter's output channel.
* will be passed to this filter's output channel. Otherwise the message will
* either be silently dropped (the default) or will trigger the throwing of a
* {@link MessageRejectedException} depending on the value of its
* {@link #throwExceptionOnRejection} property.
*
* @author Mark Fisher
*/
public class MessageFilter extends AbstractReplyProducingMessageHandler {
private MessageSelector selector;
private final MessageSelector selector;
private volatile boolean throwExceptionOnRejection;
/**
* Create a MessageFilter that will delegate to the given
* {@link MessageSelector}.
*/
public MessageFilter(MessageSelector selector) {
Assert.notNull(selector, "selector must not be null");
this.selector = selector;
}
/**
* Specify whether this filter should throw a
* {@link MessageRejectedException} when its selector does not accept a
* Message. The default value is <code>false</code> meaning that rejected
* Messages will be quietly dropped.
*/
public void setThrowExceptionOnRejection(boolean throwExceptionOnRejection) {
this.throwExceptionOnRejection = throwExceptionOnRejection;
}
@Override
protected void handleRequestMessage(Message<?> message, ReplyMessageHolder replyHolder) {
if (this.selector.accept(message)) {
replyHolder.set(message);
}
else if (this.throwExceptionOnRejection) {
throw new MessageRejectedException(message);
}
}
}

View File

@@ -27,8 +27,6 @@ import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.core.MessageHeaders;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessageRejectedException;
import org.springframework.integration.selector.MessageSelector;
import org.springframework.util.Assert;
/**
@@ -45,8 +43,6 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa
private volatile ChannelResolver channelResolver;
private volatile MessageSelector selector;
private volatile boolean requiresReply = false;
private final MessageChannelTemplate channelTemplate;
@@ -78,10 +74,6 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa
this.channelResolver = channelResolver;
}
public void setSelector(MessageSelector selector) {
this.selector = selector;
}
public void setRequiresReply(boolean requiresReply) {
this.requiresReply = requiresReply;
}
@@ -94,9 +86,6 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa
@Override
protected final void handleMessageInternal(Message<?> message) {
if (!this.supports(message)) {
throw new MessageRejectedException(message, "unsupported message");
}
ReplyMessageHolder replyMessageHolder = new ReplyMessageHolder();
this.handleRequestMessage(message, replyMessageHolder);
if (replyMessageHolder.isEmpty()) {
@@ -123,16 +112,6 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa
protected abstract void handleRequestMessage(Message<?> requestMessage, ReplyMessageHolder replyMessageHolder);
protected boolean supports(Message<?> message) {
if (this.selector != null && !this.selector.accept(message)) {
if (logger.isDebugEnabled()) {
logger.debug("selector for handler '" + this + "' rejected message: " + message);
}
return false;
}
return true;
}
protected boolean sendReplyMessage(Message<?> replyMessage, MessageChannel replyChannel) {
return this.channelTemplate.send(replyMessage, replyChannel);
}