Book Image

Spring Integration Essentials

By : CHANDAN K PANDEY
Book Image

Spring Integration Essentials

By: CHANDAN K PANDEY

Overview of this book

Table of Contents (18 chapters)
Spring Integration Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Channel interceptors


Interceptor patterns can be used to apply business rules and validations on messages that are either sent from the channel or received on it. The following four interceptors are available:

public interface ChannelInterceptor {
  Message<?> preSend(Message<?> message, MessageChannel channel);
  void postSend(Message<?> message, MessageChannel channel, boolean sent);
  boolean preReceive(MessageChannel channel);
  Message<?> postReceive(Message<?> message, MessageChannel channel);
}

Adding an interceptor is straightforward: define a class that implements the ChannelInterceptor interface and then inject a reference of it in the channel definition. Here is a quick code snippet to show this:

<int:channel id="resultChannel">
  <int:interceptors>
    <ref bean="resultValidationInterceptor"/>
  </int:interceptors>
</int:channel>

Here are the methods exposed by the ChannelInterceptor interface:

  • preSend: This is invoked before...