How to use Spring Integration Http Inbound with Spring Boot

In the tutorial, JavaSampleApproach will guide you how to use Spring Http Inbound with Spring Boot.
Related Post:
How to start Spring Integration with Spring Boot

I. Technologies

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.1.RELEASE

II. Overview

Http Inbound Channel Adapter or Gateway is used to receive http messages.
inbound-channel-adapter:

In case, the kind of request need a returning with a customized message, use Http Inbound Gateway.

In the tutorial, we create http RESTful services, use: http:inbound-gateway for GET request with dedicated returning result, use: http:inbound-channel-adapter for POST, PUT & DELETE requests without customized result for returning.

http:inbound-channel-adapter for: POST, PUT & DELETE requests
Spring Boot Spring Integration Http Inbound Channel - inbound adapter

http:inbound-gateway for GET requests
Spring Boot Spring Integration Http Inbound Channel - inbound gateways

1. Project Structure

Spring Boot Spring Integration Http Inbound Channel - project structure

2. Step to do

– Create Spring Boot project
– Create simple Customer model
– Create Customer Services
– Implement Endpoints for GET, POST, PUT, DELETE
– Config Inbound Adapter & Inbound Gateway
– Run & Enjoys Results

III. Practices
1. Create Spring Boot project

– Open Spring Tool Suite, on main menu, choose File->New->Spring Starter Project, input project info. Press Next then Finish, a Spring Boot project will be created successfully.

Add dependencies:
spring-boot-starter-integration
spring-integration-http
spring-boot-starter-web
Details:

2. Create simple Customer model

3. Create Customer Services

Create a simple customer services for: insert, update, delete, get.

4. Implement Service Activator – Endpoint for GET, POST, PUT, DELETE

5. Config Inbound Adapter & Inbound Gateway

For GET requests, use http:inbound-gateway to handle

Use method get of InboundEnpoint for service-activator:

Full Config: create http-inbound-gateway.xml:

For POST, PUT & DELETE requests, use inbound-channel-adapte

POST & PUT:

DELETE:

Full Config: create http-inbound-adapter.xml file:

status-code-expression: By default, the channel adapter will returns a 200 status code. In the case we specify a different status code in this attribute: 204 No Content status code.
request-payload-type: used to specify a class to convert request body.

int:router is used for routing and filtering logic within the Spring Integration flow.
In the tutorial case, it is used for mapping with PUT or POST requests to process.

– Config @ImportResource({“classpath:http-inbound-adapter.xml”, “classpath:http-inbound-gateway.xml”}) in main class:

6. Run & Enjoys Results

Build & Run the project with Spring Boot App mode.
Makes requests:
GET request:
Spring Boot Spring Integration Http Inbound Channel - get result

POST request:
Spring Boot Spring Integration Http Inbound Channel - post result

PUT request:
Spring Boot Spring Integration Http Inbound Channel - put result

DELETE request:
Spring Boot Spring Integration Http Inbound Channel - delete result

GET request:
Spring Boot Spring Integration Http Inbound Channel - last get result

IV. Sourcecode

SpringIntegrationInboundComponent

By JavaSampleApproach | February 6, 2017.

Last updated on June 4, 2017.


Related Posts


Got Something To Say:

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

*