Search code examples
javaspringspring-integrationspring-integration-http

How can I create http inbound channel adapter with JAVA config in Spring integration?


I have the following http inbound channel adapter. How can I do this configuration with Java Config or Spring DSL?

<int-http:inbound-channel-adapter
    channel="api_app_integration_request_channel" 
    supported-methods="PUT" 
    path="/process/ticket"
    request-payload-type="*.model.Ticket"
    header-mapper="headerMapper"
    error-channel="internal-client-rest-ticket-error-channel"
>
<int-http:request-mapping consumes="application/json" />
</int-http:inbound-channel-adapter>

Solution

  • See Spring Integration Reference Manual:

    Java DSL at all: https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl

    HTTP Module specifics: https://docs.spring.io/spring-integration/docs/current/reference/html/http.html#http-java-config

    Your particular sample could be translated to this IntegrationFlow:

        @Bean
        public IntegrationFlow myHttpFlow() {
            return IntegrationFlows
                    .from(Http.inboundChannelAdapter("/process/ticket")
                            .requestMapping(r -> r
                                    .methods(HttpMethod.PUT)
                                    .consumes("application/json"))
                            .requestPayloadType(model.Ticket.class)
                            .headerMapper(headerMapper))
                    .channel("api_app_integration_request_channel")
                    ...
                    .get();
        }
    

    Instead of ... you can add integration endpoints to build your logic for processing those requests.

    In the same HTTP chapter, you can find how to configure an HttpRequestHandlingMessagingGateway as a plain @Bean if that.