use of org.springframework.integration.filter.MessageFilter in project spring-integration by spring-projects.
the class AdvisedMessageHandlerTests method filterDiscardNoAdvice.
public void filterDiscardNoAdvice() {
MessageFilter filter = new MessageFilter(message -> false);
QueueChannel discardChannel = new QueueChannel();
filter.setDiscardChannel(discardChannel);
filter.handleMessage(new GenericMessage<String>("foo"));
assertNotNull(discardChannel.receive(0));
}
use of org.springframework.integration.filter.MessageFilter in project spring-integration by spring-projects.
the class AdvisedMessageHandlerTests method filterDiscardWithinAdvice.
@Test
public void filterDiscardWithinAdvice() {
MessageFilter filter = new MessageFilter(message -> false);
final QueueChannel discardChannel = new QueueChannel();
filter.setDiscardChannel(discardChannel);
List<Advice> adviceChain = new ArrayList<Advice>();
final AtomicReference<Message<?>> discardedWithinAdvice = new AtomicReference<Message<?>>();
adviceChain.add(new AbstractRequestHandlerAdvice() {
@Override
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
Object result = callback.execute();
discardedWithinAdvice.set(discardChannel.receive(0));
return result;
}
});
filter.setAdviceChain(adviceChain);
filter.setBeanFactory(mock(BeanFactory.class));
filter.afterPropertiesSet();
filter.handleMessage(new GenericMessage<String>("foo"));
assertNotNull(discardedWithinAdvice.get());
assertNull(discardChannel.receive(0));
}
use of org.springframework.integration.filter.MessageFilter in project spring-integration by spring-projects.
the class GroovyFilterTests method testInt2433VerifyRiddingOfMessageProcessorsWrapping.
@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
assertTrue(this.groovyFilterMessageHandler instanceof MessageFilter);
MessageSelector selector = TestUtils.getPropertyValue(this.groovyFilterMessageHandler, "selector", MethodInvokingSelector.class);
@SuppressWarnings("rawtypes") MessageProcessor messageProcessor = TestUtils.getPropertyValue(selector, "messageProcessor", MessageProcessor.class);
// before it was MethodInvokingMessageProcessor
assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);
}
use of org.springframework.integration.filter.MessageFilter in project spring-integration by spring-projects.
the class FilterAnnotationPostProcessor method createHandler.
@Override
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
MessageSelector selector;
if (AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
Object target = this.resolveTargetBeanFromMethodWithBeanAnnotation(method);
if (target instanceof MessageSelector) {
selector = (MessageSelector) target;
} else if (this.extractTypeIfPossible(target, MessageFilter.class) != null) {
checkMessageHandlerAttributes(resolveTargetBeanName(method), annotations);
return (MessageHandler) target;
} else {
selector = new MethodInvokingSelector(target);
}
} else {
Assert.isTrue(boolean.class.equals(method.getReturnType()) || Boolean.class.equals(method.getReturnType()), "The Filter annotation may only be applied to methods with a boolean return type.");
selector = new MethodInvokingSelector(bean, method);
}
MessageFilter filter = new MessageFilter(selector);
String discardWithinAdvice = MessagingAnnotationUtils.resolveAttribute(annotations, "discardWithinAdvice", String.class);
if (StringUtils.hasText(discardWithinAdvice)) {
discardWithinAdvice = this.beanFactory.resolveEmbeddedValue(discardWithinAdvice);
if (StringUtils.hasText(discardWithinAdvice)) {
filter.setDiscardWithinAdvice(Boolean.parseBoolean(discardWithinAdvice));
}
}
String throwExceptionOnRejection = MessagingAnnotationUtils.resolveAttribute(annotations, "throwExceptionOnRejection", String.class);
if (StringUtils.hasText(throwExceptionOnRejection)) {
String throwExceptionOnRejectionValue = this.beanFactory.resolveEmbeddedValue(throwExceptionOnRejection);
if (StringUtils.hasText(throwExceptionOnRejectionValue)) {
filter.setThrowExceptionOnRejection(Boolean.parseBoolean(throwExceptionOnRejectionValue));
}
}
String discardChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "discardChannel", String.class);
if (StringUtils.hasText(discardChannelName)) {
filter.setDiscardChannelName(discardChannelName);
}
this.setOutputChannelIfPresent(annotations, filter);
return filter;
}
use of org.springframework.integration.filter.MessageFilter in project spring-integration by spring-projects.
the class FilterFactoryBean method createFilter.
protected MessageFilter createFilter(MessageSelector selector) {
MessageFilter filter = new MessageFilter(selector);
postProcessReplyProducer(filter);
return filter;
}
Aggregations