3

我正在尝试使用 Java DSL 为 HTTP 入站网关创建和注册运行时集成流,如下所示

@Autowired
private IntegrationFlowContext flowContext;

public static void main(String[] args) {
    SpringApplication.run(RestClientDemoApplication.class, args);
}

@ServiceActivator(inputChannel="httpRequest")
public String upCase(String in) {
    System.out.println("message received" + in);
    return in.toUpperCase();
}

@Bean
public MessageChannel directChannel(){
    return MessageChannels.direct().get();
}

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


@Override
public void run(String... args) throws Exception {
     IntegrationFlow flow;
     IntegrationFlowRegistration theFlow;
    flow = IntegrationFlows.from(Http.inboundGateway("/foo")
                .requestMapping(m -> m.methods(HttpMethod.POST))
                .requestPayloadType(String.class).replyChannel(directChannel()))
            .channel("httpRequest")
            .get();

      theFlow = this.flowContext.registration(flow).register();
}

在这种情况下,我的请求 url ("/foo") 没有与服务器映射,因为当我从 HTTP 客户端发送消息时,服务器端没有收到任何消息。但是当我取消注释上面的bean(入站),即为集成流创建一个bean并在运行方法中 注释流创建和注册代码(删除运行时集成流代码)时,它工作正常

@Autowired
private IntegrationFlowContext flowContext;

public static void main(String[] args) {
    SpringApplication.run(RestClientDemoApplication.class, args);
}

@ServiceActivator(inputChannel="httpRequest")
public String upCase(String in) {
    System.out.println("message received" + in);
    return in.toUpperCase();
}

@Bean
public MessageChannel directChannel(){
    return MessageChannels.direct().get();
}

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



@Override
public void run(String... args) throws Exception {


     /*IntegrationFlow flow;
     IntegrationFlowRegistration theFlow;

     flow = IntegrationFlows.from(Http.inboundGateway("/foo")
                .requestMapping(m -> m.methods(HttpMethod.POST))
                .requestPayloadType(String.class).replyChannel(directChannel()))
            .channel("httpRequest")
            .get();

      theFlow = this.flowContext.registration(flow).register();*/ 
}

我的 HTTP 出站网关代码如下

    flow = IntegrationFlows.from(directChannel()).handle(Http.outboundGateway("https://localhost:8448/foo")
            .httpMethod(HttpMethod.POST).expectedResponseType(String.class)).channel("httpReply").get();

    theFlow = this.flowContext.registration(flow).register();

如果这种方法不合适,请帮助我解决上述问题或提供在运行时创建 Http 入站网关的解决方案。

4

1 回答 1

0

这是不可能的:https ://jira.spring.io/browse/INT-4436 。

不幸的是,没有简单的解决方法可以让您继续进行,除非您只能公开一个 REST 端点并IntegrationFlow根据接受的 HTTP 请求在内部进行路由。

于 2018-04-17T15:54:42.867 回答