Динамический HTTP-шлюз входящей почты с использованием Spring-integration-dsl

Я пытаюсь создать и зарегистрировать поток интеграции времени выполнения для входящего HTTP-шлюза с использованием Java DSL, как показано ниже.

@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 во время выполнения, если этот подход не подходит.


person SM_DBArchitect    schedule 17.04.2018    source источник


Ответы (1)