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

Handling errors


So far so good, how about handling error scenarios? How to test negative use cases and what to do with the failed test case? The following code snippet will help us in these matters:

  @Test(expected = MessageTransformationException.class)
  public void errorReportedWhenPayloadIsWrong() {
    Message<String> message = 
      MessageBuilder.withPayload("this should fail").build();
    filteredFeedChannel.send(message);
  }

The input channel expects a message with the payload type SyndEntry, but if a message with a String payload is sent—this must throw an exception. This is what has been tested. This can be further enhanced to monitor certain types of exception on channels with the ability to validate user-defined propagated messages.