1

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>
JBStonehenge
  • 192
  • 3
  • 15

1 Answers1

0

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.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • 1
    Thanks a lot, Artem! Why are you Spring Experts not providing a XML to Java Configuration converter? As for Spring Boot there is a Maven project generator Spring Initializr. – JBStonehenge Aug 31 '21 at 23:11
  • Ha! That's interesting idea. I think it is not so easy to do that since it is not just plain Maven XML generation. It is really a Java code generator, not just something what could be translated to the executable code on some adapter, but really a Java source code generator... Parse an XML and write Java. That's probably what you are asking. Not sure if that is so easy to do... Feel free to raise a GH issue on the matter, so other community members may share their thoughts, too. – Artem Bilan Aug 31 '21 at 23:16
  • But back to this issue: The above xml may configure an adapter feeding the channel with messages from a REST service result. Is that right? I do not understand what for the request is configured (method, format, etc.) when from the Spring Integration point of view the response should be. I am looking for an example where a REST service (which I will provide) is returning a JSON representation of some object of mine which is fed into the SI channel to get processed by a Message Handler. Is there any kind of it? – JBStonehenge Aug 31 '21 at 23:41
  • This sounds more like a separate SO thread. Please, consider to raise one with concrete problem. You asked here for Java representation for the provided XML - I answered with my best. The problem you express in this comment somehow is slightly different. Here are SO rules how and what can be asked in this forum: https://stackoverflow.com/help/how-to-ask – Artem Bilan Aug 31 '21 at 23:53