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

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

Introduction

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

Prototype

public void setAdviceChain(List<Advice> adviceChain) 

Source Link

Document

Configure a list of Advice s to proxy a #handleRequestMessage(Message) method.

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  va  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<?>>();
    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//  w  w  w . j a  v a 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));
}