2016-10-14 6 views
1

複数のHTTPエンドポイントを実行して、パスのリストに基づいて作成する必要があります。複数の動的HTTPエンドポイント

現在、私は1つのエンドポイントを作成することができるよ:

@MessagingGateway(defaultRequestChannel = "requestChannel") 
public interface Gateway { 
    String sendReceive(String in); 
} 

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

@Bean 
public IntegrationFlow flow() { 
    return IntegrationFlows.from("requestChannel").transform(new ObjectToStringTransformer()) 
      .handle(new MyHandle()) 
      .get(); 
} 

@Bean 
public HttpRequestHandlingMessagingGateway httpGate() { 
    HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true); 
    RequestMapping mapping = new RequestMapping(); 
    mapping.setMethods(HttpMethod.POST); 
    mapping.setPathPatterns("/path"); 
    gateway.setRequestMapping(mapping); 
    gateway.setRequestChannel(requestChannel()); 
    gateway.setRequestPayloadType(byte[].class); 
    return gateway; 
} 

を、私はこのように気にいらをしたい:

@Autowired 
List<String> paths; 

@PostConstruct 
public void createEndpoints() { 
    for (String path : paths) { 
     //code for dynamic endpoint creation 
    } 
} 

private class MyHandle extends AbstractReplyProducingMessageHandler { 

    @Override 
    protected Object handleRequestMessage(Message<?> requestMessage) { 
     return this.getMessageBuilderFactory().withPayload("Your message: " + requestMessage.getPayload()); 
    } 
} 

あなたは、私はそれをどのように行うことができます教えてもらえますか?

答えて

0

Java DSL 1.2以降では、IntegrationFlowと依存するBeanを動的に登録するために、このようなユースケースに対しては、正確にIntegrationFlowContextがあります。

https://spring.io/blog/2016/09/27/java-dsl-for-spring-integration-1-2-release-candidate-1-is-available

GAリリース今日。

これらのブログの記事のサンプルに従うだけで、org.springframework.integration.dsl.http.Http工場に注意する必要があります。

しかし、実際には可能な限り早く実行してください。 @PostConstructは、この使用例では良いフェーズです。 これが後になると、HandlerMappingは新しいマッピングを検出することができなくなります。ちょうどそれがそのafterPropertiesSet()でスキャンを行うからです。

関連する問題