Search code examples
springspring-integrationspring-integration-dsl

Why Spring Integration Java DSL request for the JSON is not working


I have the bean definition

    @Bean
public IntegrationFlow inbound() {
    return IntegrationFlows.from(MessageChannels.queue("getSend1"))
            .handle(Http.outboundGateway("http://localhost:8055/greeting").httpMethod(HttpMethod.GET)
                    .expectedResponseType(String.class))
            .channel(MessageChannels.queue("getReceive1"))
            .get();
}

and default poller and I want to get the JSON from the URL. This is not working. The service http://localhost:8055/greeting is not called at all and the log message

preReceive on channel 'getSend1'
postReceive on channel 'getSend1', message is null
Received no Message during the poll, returning 'false'

is printed.


Solution

  • It is working like this:

        @Bean
    public IntegrationFlow inbound() {
        return IntegrationFlows
                .from(this.integerMessageSource(), c -> c.poller(Pollers.fixedRate(2000)))
                .handle(Http.outboundGateway("http://localhost:8055/greeting")
                        .httpMethod(HttpMethod.GET).expectedResponseType(String.class))
                .channel(MessageChannels.queue("getReceive"))
                .handle(Http.outboundGateway("http://localhost:8055/greeting").httpMethod(HttpMethod.POST)
                        .expectedResponseType(String.class))
                .channel(MessageChannels.queue("postReceive"))
                .handle(Http.outboundGateway("http://localhost:8055/greeting-final").httpMethod(HttpMethod.POST)
                        .expectedResponseType(String.class))
                .channel(MessageChannels.queue("postReceiveFinal"))
                .get();
    }
    

    This does get for the first URL, then posts the answer the second URL and then posts the answer to third URL and gets the final answer.