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

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

Introduction

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

Prototype

public void setDiscardChannel(MessageChannel discardChannel) 

Source Link

Document

Specify a channel where rejected Messages should be sent.

Usage

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

public void filterDiscardNoAdvice() {
    MessageFilter filter = new MessageFilter(new MessageSelector() {
        @Override/*from  w ww  .  ja v  a  2 s . c o m*/
        public boolean accept(Message<?> message) {
            return false;
        }
    });
    QueueChannel discardChannel = new QueueChannel();
    filter.setDiscardChannel(discardChannel);
    filter.handleMessage(new GenericMessage<String>("foo"));
    assertNotNull(discardChannel.receive(0));
}

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

@Test
public void filterDiscardWithinAdvice() {
    MessageFilter filter = new MessageFilter(new MessageSelector() {
        @Override/*from   ww  w  .  j av a2 s. 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<?>>();
    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.afterPropertiesSet();
    filter.handleMessage(new GenericMessage<String>("foo"));
    assertNotNull(discardedWithinAdvice.get());
    assertNull(discardChannel.receive(0));
}

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

@Test
public void filterDiscardOutsideAdvice() {
    MessageFilter filter = new MessageFilter(new MessageSelector() {
        @Override//from ww w .  j  ava  2  s .  c  o 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));
}