Example usage for org.springframework.integration.filter MessageFilter setDiscardWithinAdvice

List of usage examples for org.springframework.integration.filter MessageFilter setDiscardWithinAdvice

Introduction

In this page you can find the example usage for org.springframework.integration.filter MessageFilter setDiscardWithinAdvice.

Prototype

public void setDiscardWithinAdvice(boolean discardWithinAdvice) 

Source Link

Document

Set to 'true' if you wish the discard processing to occur within any request handler advice applied to this filter.

Usage

From source file:org.springframework.integration.handler.advice.AdvisedMessageHandlerTests.java

@Test
public void filterDiscardOutsideAdvice() {
    MessageFilter filter = new MessageFilter(new MessageSelector() {
        @Override/*from  w w  w.  ja  v  a 2s.  co m*/
        public boolean accept(Message<?> message) {
            return false;
        }
    });
    final QueueChannel discardChannel = new QueueChannel();
    filter.setDiscardChannel(discardChannel);
    List<Advice> adviceChain = new ArrayList<Advice>();
    final AtomicReference<Message<?>> discardedWithinAdvice = new AtomicReference<Message<?>>();
    final AtomicBoolean adviceCalled = new AtomicBoolean();
    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));
            adviceCalled.set(true);
            return result;
        }
    });
    filter.setAdviceChain(adviceChain);
    filter.setDiscardWithinAdvice(false);
    filter.afterPropertiesSet();
    filter.handleMessage(new GenericMessage<String>("foo"));
    assertTrue(adviceCalled.get());
    assertNull(discardedWithinAdvice.get());
    assertNotNull(discardChannel.receive(0));
}