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

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

Introduction

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

Prototype

@Override
    public final void afterPropertiesSet() 

Source Link

Usage

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

@Test
public void filterDiscardWithinAdvice() {
    MessageFilter filter = new MessageFilter(new MessageSelector() {
        @Override/*from w  w  w .  j  a  v  a 2s.com*/
        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 w w  w.  j  a  v 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<?>>();
    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));
}