SM_DBArchitect
SM_DBArchitect

Reputation: 31

Dynamic http inbound gateway using spring-integration-dsl

I am trying to create and register runtime Integration flow for HTTP inbound gateway using Java DSL as code provided below

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

In this case my request url ("/foo") is not mapping with the server as when I send the message from the HTTP client then no message is received on server side. but when I uncomment the above bean (inbound) i.e creating a Bean for Integration flow and comment the flow creation and register code(remove runtime integration flow code) in run method as below it work fine:

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

My HTTP outbound gateway Code is as follow

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

Please help me with the above issue or provide a solution to create Http inbound gateway at runtime if this approach is not appropriate.

Upvotes: 3

Views: 2768

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121552

This is not possible yet: https://jira.spring.io/browse/INT-4436.

Unfortunately there is no simple workaround for your to go ahead, unless you could expose just only one REST endpoint and do routing inside the IntegrationFlow according the accepted HTTP request.

Upvotes: 0

Related Questions