|
1 | 1 | /* |
2 | | - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
20 | 20 | import org.springframework.beans.factory.BeanFactoryAware; |
21 | 21 | import org.springframework.context.Lifecycle; |
22 | 22 | import org.springframework.core.convert.ConversionService; |
| 23 | +import org.springframework.core.log.LogMessage; |
23 | 24 | import org.springframework.integration.IntegrationPatternType; |
24 | 25 | import org.springframework.integration.MessageRejectedException; |
25 | 26 | import org.springframework.integration.core.MessageSelector; |
|
33 | 34 | /** |
34 | 35 | * Message Handler that delegates to a {@link MessageSelector}. If and only if |
35 | 36 | * the selector {@link MessageSelector#accept(Message) accepts} the Message, it |
36 | | - * will be passed to this filter's output channel. Otherwise the message will |
37 | | - * either be silently dropped (the default) or will trigger the throwing of a |
38 | | - * {@link MessageRejectedException} depending on the value of its |
39 | | - * {@link #throwExceptionOnRejection} property. If a discard channel is |
40 | | - * provided, the rejected Messages will be sent to that channel. |
| 37 | + * will be passed to this filter's output channel. Otherwise, the message will |
| 38 | + * either be silently dropped (the default) with a warning into logs, |
| 39 | + * or will trigger the throwing of a {@link MessageRejectedException} |
| 40 | + * depending on the value of its {@link #throwExceptionOnRejection} property. |
| 41 | + * If a discard channel is provided, the rejected Messages will be sent to that channel. |
41 | 42 | * |
42 | 43 | * @author Mark Fisher |
43 | 44 | * @author Oleg Zhurakousky |
@@ -71,7 +72,7 @@ public MessageFilter(MessageSelector selector) { |
71 | 72 | * {@link MessageRejectedException} when its selector does not accept a |
72 | 73 | * Message. The default value is <code>false</code> meaning that rejected |
73 | 74 | * Messages will be quietly dropped or sent to the discard channel if |
74 | | - * available. Typically this value would not be <code>true</code> when |
| 75 | + * available. Typically, this value would not be <code>true</code> when |
75 | 76 | * a discard channel is provided, but if so, it will still apply |
76 | 77 | * (in such a case, the Message will be sent to the discard channel, |
77 | 78 | * and <em>then</em> the exception will be thrown). |
@@ -179,13 +180,16 @@ protected Object doHandleRequestMessage(Message<?> message) { |
179 | 180 | @Override |
180 | 181 | public Object postProcess(Message<?> message, Object result) { |
181 | 182 | if (result == null) { |
182 | | - MessageChannel channel = getDiscardChannel(); |
183 | | - if (channel != null) { |
184 | | - this.messagingTemplate.send(channel, message); |
| 183 | + MessageChannel channelToDiscard = getDiscardChannel(); |
| 184 | + if (channelToDiscard != null) { |
| 185 | + this.messagingTemplate.send(channelToDiscard, message); |
185 | 186 | } |
186 | 187 | if (this.throwExceptionOnRejection) { |
187 | 188 | throw new MessageRejectedException(message, "message has been rejected in filter: " + this); |
188 | 189 | } |
| 190 | + else if (channelToDiscard == null) { |
| 191 | + logger.warn(LogMessage.format("The message [%s] has been rejected in filter: %s", message, this)); |
| 192 | + } |
189 | 193 | } |
190 | 194 | return result; |
191 | 195 | } |
|
0 commit comments