0

I have a SpringBoot 2.2.6 application and I would like to set an endpoint with spring-integration therefore I have the follow configuration:

@Bean
public MessageChannel reply() {
    return new DirectChannel();
}

@Bean
public IntegrationFlow inbound(TestTransformer testTransformer) {
    return IntegrationFlows.from(Http.inboundGateway("/foo")
            .requestMapping(m -> m.methods(HttpMethod.GET))
            .replyChannel("reply")
            .requestPayloadType(String.class))
            .channel("httpRequest")
            .get();
}

@Bean
@ServiceActivator(inputChannel = "httpRequest", outputChannel = "reply")
public Function<Message<?>, String> handler() {
    return new Function<Message<?>, String>() {
        public String apply(Message<?> message) throws MessagingException {
            log.info("myHandler: " + message.getPayload());
            log.info("myHandler: " + message.getHeaders());
            return "ok";
        }
    };
}

Now if I call the enpoint passing params as http://localhost:8080/MyApp/foo?q=test&q1=test2 I receive the parameters in a JSON form.

Is possible to receive something like @PathVariable in the MVC for example writing:

return IntegrationFlows.from(Http.inboundGateway("/foo/{name}")

I have tried it but doesn't work and I canno't find any docs talking about that (at least with java bean configuration)

Thanks

CoderJammer
  • 599
  • 3
  • 8
  • 27

1 Answers1

0

Maybe:

@Bean
public IntegrationFlow test(TestTransformer testTransformer, Jackson2JsonObjectMapper obj) {
    return IntegrationFlows.from(Http.inboundGateway("/foo/{name}")
            .requestMapping(m -> m.methods(HttpMethod.GET))
            .payloadExpression("#pathVariables.name")
            .replyChannel("reply")
            .requestPayloadType(String.class))
            .transform(testTransformer)
            .transform(new ObjectToJsonTransformer(obj))
            .channel("httpRequest")
            .get();
}

is more usefull... The docs is full of xml config and I read it but I'm not able to trasnform them all into java DSL

CoderJammer
  • 599
  • 3
  • 8
  • 27
  • You have switched context somehow, but let's hope it answers your concerns anyway. – Artem Bilan Jun 14 '22 at 14:55
  • yes yes absolutely, and thank you for your answer. I have already seen the snippet you have write above but I rarely find the equivalent in javadsl (or at least in java) noway and I'm not able to translate...:( – CoderJammer Jun 14 '22 at 15:42
  • There are some samples in that doc: https://docs.spring.io/spring-integration/docs/current/reference/html/http.html#http-java-config. You probably just need to go to code in your IDE and try suggested methods for configuration and their JavaDocs. It is really pointless to describe all the methods in the doc and show all the possible use-case samples in the world... – Artem Bilan Jun 14 '22 at 16:17