春季集成http入站网关参数

发布于 2025-02-07 10:07:36 字数 1298 浏览 2 评论 0原文

我想设置一个使用spring-integration设置端点

@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";
        }
    };
}

我有一个springboot 2.2.6应用程序, http:// localhost:8080/myapp/foo?q = test&amp; q1 = test2我以json表单接收参数。

可以在MVC中收到@pathvariable的东西,例如写作:

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

我已经尝试过但不起作用,但我找不到任何文档在谈论这一点(至少使用Java Bean Configuration)

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小红帽 2025-02-14 10:07:36

也许:

@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();
}

更有用...文档充满了XML配置,我读了它,但是我无法将它们全部转移到java dsl

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文