Spring Book – Chapter 20 – Spring Integration

Error Handling

Spring Integration promotes loose coupling between components using message-oriented framework. This loose-coupling nature also poses some drawbacks and one among that is the error handling mechanism.

Fortunately, Spring Integration supports error handling for its components by allowing each component to publish the errors to a message channel as shown in Listing 22-85 below.

Listing 22-85. Channel configured to listen to error messages

The Exception will become the payload of a Spring Integration Message. If the message being handled at the time the Exception occurred contains an ‘errorChannel’ header, the ErrorMessage will be sent to that channel. Otherwise, the error handler will send to a “global” channel whose bean name is “errorChannel”.

Security in Spring Integration

Spring Integration builds upon the Spring Security project to enable role-based security checks applied to channel while sending and receiving messages. Listing 22-86 shows Spring Integration security namespace declaration, which can be used easily to apply security to channels.

Listing 22-86. Declaring Spring Integration security namespace in Spring configuration file

Listing 22-87 below shows security a channel by defining appropriate access policy that makes sure that these channels can only be accessed by authorized users.

Listing 22-87. Declaring secured channel in Spring configuration file

If you would like to use custom authentication and access decision manager (See Chapter 15), you can use attributes namely “authentication-manager” and “access-decision-manager” in the “secured-channel” tag as shown in Listing 22-88 below.

Listing 22-88. Declaring custom authentication and access decision manager


Spring Integration provides the base components to implement the Enterprise Integration Patterns (EIP) in your application. It allows your application components to interact with each other and with other external systems hiding the complexity involved in this integration away from the application developer.

By doing so, Spring Integration brings loosely-couples, event-driven architecture and allows having a clear separation between the integration logic and the actual business processing logic. The shielding of integration loci from the developers is achieved by Spring integration by providing appropriate adapters and gateways.

We started the chapter with the Spring Integration goals, principle and benefits. We then went onto discuss the various components in Spring Integration in detail. We then covered Spring Integration architecture and went onto explain expand some of the main components to cover some advanced topics.

We then looked into adapters and gateways by which Spring Integration allows to communicate in detail along with code samples. We then finished the Chapter with topics like Spring Integration security and error handling features.

After reading this Chapter, you should now have a clear picture of Spring Integration along with hands-on experience on the actual code required to achieve Spring Integration in your application.

Page Visitors: 13409

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

2 thoughts on “Spring Book – Chapter 20 – Spring Integration

  1. Hi,
    Thanks for this blog and information sharing!
    I have one question from Spring Integration. Just thought of checking with you.
    I have SimplewebserviceOutBoundGateway. I need to send a document / attachment to the webservice. How will i achieve that?
    This is my current gateway configuration:

    Please let me know, if you can throw some light in this area.
    Thanks in Advance!

  2. Hi,
    Thank you for your information sharing.
    I have one doubt,could you please suggest me the correct frameworks to address that issue.

    My requirement is I would like to get and process files using spring and camel.


Leave a Reply

Your email address will not be published. Required fields are marked *