Class MessageFilter
java.lang.Object
- All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>
,Aware
,BeanClassLoaderAware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,Lifecycle
,Ordered
,ExpressionCapable
,Orderable
,MessageProducer
,DiscardingMessageHandler
,HeaderPropagationAware
,PostProcessingMessageHandler
,IntegrationPattern
,NamedComponent
,IntegrationManagement
,ManageableLifecycle
,TrackableComponent
,MessageHandler
,reactor.core.CoreSubscriber<Message<?>>
public class MessageFilter
extends AbstractReplyProducingPostProcessingMessageHandler
implements DiscardingMessageHandler, ManageableLifecycle
Message Handler that delegates to a
MessageSelector
. If and only if
the selector accepts
the Message, it
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
MessageRejectedException
depending on the value of its
throwExceptionOnRejection
property. If a discard channel is
provided, the rejected Messages will be sent to that channel.- Author:
- Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan, David Liu
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
AbstractReplyProducingMessageHandler.RequestHandler
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
messagingTemplate
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorDescriptionMessageFilter
(MessageSelector selector) Create a MessageFilter that will delegate to the givenMessageSelector
. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
doHandleRequestMessage
(Message<?> message) protected void
doInit()
Subclasses may implement this method to provide component type information.Return the discard channel.Return a pattern type this component implements.boolean
postProcess
(Message<?> message, Object result) Take some further action on the result and/or message.void
setDiscardChannel
(MessageChannel discardChannel) Specify a channel where rejected Messages should be sent.void
setDiscardChannelName
(String discardChannelName) void
setDiscardWithinAdvice
(boolean discardWithinAdvice) Set to 'true' if you wish the discard processing to occur within any request handler advice applied to this filter.void
setThrowExceptionOnRejection
(boolean throwExceptionOnRejection) Specify whether this filter should throw aMessageRejectedException
when its selector does not accept a Message.protected boolean
Subclasses may override this.void
start()
void
stop()
Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingPostProcessingMessageHandler
doInvokeAdvisedRequestHandler, handleRequestMessage, setPostProcessWithinAdvice
Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
getBeanClassLoader, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReply
Methods inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, shouldSplitOutput, updateNotPropagatedHeaders
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe
Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface reactor.core.CoreSubscriber
currentContext
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAs
Methods inherited from interface org.springframework.messaging.MessageHandler
handleMessage
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
MessageFilter
Create a MessageFilter that will delegate to the givenMessageSelector
.- Parameters:
selector
- The message selector.
-
-
Method Details
-
setThrowExceptionOnRejection
public void setThrowExceptionOnRejection(boolean throwExceptionOnRejection) Specify whether this filter should throw aMessageRejectedException
when its selector does not accept a Message. The default value isfalse
meaning that rejected Messages will be quietly dropped or sent to the discard channel if available. Typically this value would not betrue
when a discard channel is provided, but if so, it will still apply (in such a case, the Message will be sent to the discard channel, and then the exception will be thrown).- Parameters:
throwExceptionOnRejection
- true if an exception should be thrown.- See Also:
-
setDiscardChannel
Specify a channel where rejected Messages should be sent. If the discard channel is null (the default), rejected Messages will be dropped. However, the 'throwExceptionOnRejection' flag determines whether rejected Messages trigger an exception. That value is evaluated regardless of the presence of a discard channel.- Parameters:
discardChannel
- The discard channel.- See Also:
-
setDiscardChannelName
-
setDiscardWithinAdvice
public void setDiscardWithinAdvice(boolean discardWithinAdvice) Set to 'true' if you wish the discard processing to occur within any request handler advice applied to this filter. Also applies to throwing an exception on rejection. Default: true.- Parameters:
discardWithinAdvice
- true to discard within the advice.
-
getDiscardChannel
Description copied from interface:DiscardingMessageHandler
Return the discard channel.- Specified by:
getDiscardChannel
in interfaceDiscardingMessageHandler
- Returns:
- the channel.
-
getComponentType
Description copied from class:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in classMessageHandlerSupport
-
getIntegrationPatternType
Description copied from interface:IntegrationPattern
Return a pattern type this component implements.- Specified by:
getIntegrationPatternType
in interfaceIntegrationPattern
- Overrides:
getIntegrationPatternType
in classAbstractReplyProducingMessageHandler
- Returns:
- the
IntegrationPatternType
this component implements.
-
doInit
protected void doInit()- Overrides:
doInit
in classAbstractReplyProducingMessageHandler
-
start
public void start()- Specified by:
start
in interfaceLifecycle
- Specified by:
start
in interfaceManageableLifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceLifecycle
- Specified by:
stop
in interfaceManageableLifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceLifecycle
- Specified by:
isRunning
in interfaceManageableLifecycle
-
doHandleRequestMessage
- Specified by:
doHandleRequestMessage
in classAbstractReplyProducingPostProcessingMessageHandler
-
postProcess
Description copied from interface:PostProcessingMessageHandler
Take some further action on the result and/or message.- Specified by:
postProcess
in interfacePostProcessingMessageHandler
- Parameters:
message
- The message.result
- The result fromAbstractMessageHandler.handleMessageInternal(Message)
.- Returns:
- The post-processed result.
-
shouldCopyRequestHeaders
protected boolean shouldCopyRequestHeaders()Description copied from class:AbstractMessageProducingHandler
Subclasses may override this. True by default.- Overrides:
shouldCopyRequestHeaders
in classAbstractMessageProducingHandler
- Returns:
- true if the request headers should be copied.
-