Spring Book – Chapter 20 – Spring Integration


Gateways are message endpoints which provide two-way integration. It can be used as bidirectional or request-reply adapter unlike channel adapter which is unidirectional. Similar to adapters gateways are of two types namely:

  • Inbound Gateway – It brings message into the application and then waits for the response.
  • Outbound Gateway – It invokes external applications/systems and feeds the response back into the application.

In EAI, gateway can be pictorially represented as shown in Figure 22-15 below.

Figure 22-15. Message Gateway

Figure 22-15. Message Gateway

Application to application interaction using gateway endpoint can be pictorially represented as shown in Figure 22-16 below.

Figure 22-16. Application to application interaction using gateway endpoint

Figure 22-16. Application to application interaction using gateway endpoint

In our sample application, for dealing with booking we have another service interface as shown in Listing 22-7 below.

Listing 22-7. BookingService Interface

The gateway is defined in Spring configuration file namely applicationContext.xml as shown in Listing 22-8 below.

Listing 22-8. Gateway declaration in Spring configuration file

Declaring gateway serves as a proxy for sending new messages and even after doing so your application code doesn’t depend on the core Spring Integation API’s which is really advantageous to avoid third party integration issues. By default temporary reply channel is created automatically for Listing 22-8 but if you want you can also specify default-response-channel as well.

The gateway method signature can have “void” as well as “Future” return types. In the case of “void” return type, it effectively turns into a passive inbound adapter and in case of “Future” return type, it becomes effectively as a asynchronous and non-blocking gateway.

Declaring gateway using Java annotation turns the service interface as shown in Listing 22-9 below.

Listing 22-9. BookingService interface using Java annotations to declare gateways

Listing 22-10 shows declaration of Inbound Web Service gateway and Figure 22-17 shows the same pictorially.

Listing 22-10. Declaring inbound web service gateway in Spring configuration file

Figure 22-17. Inbound Web Service gateway

Figure 22-17. Inbound Web Service gateway

Page Visitors: 11238

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)

Leave a Reply

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

  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.