2016-10-25 8 views
1

DSLを使用してHTTP OutboundGatewayを使用してREST APIを呼び出そうとしています。私たちはGETとPOSTの両方を使用して呼び出しを行い、応答を期待通りに得ることができます。しかし、DSLを使用してこの呼び出しを行っている間に、httpヘッダーを渡す方法はありませんでした。そこXMLのアプローチに関する記事のかなり多くがありますが、我々は同様にDefaultHttpHeaderMapperと試みたが、それは仕事をdidntのDSLバネ統合dsl http outboundgateway

return IntegrationFlows.from("FileContentChannel") 
       .handle(Http.outboundGateway("http://host:port/paymentinfo/") 
         .charset("UTF-8") 
         .httpMethod(HttpMethod.GET) 
         .headerMapper(headers) 
         .expectedResponseType(String.class)) 
       .channel(MessageChannels.queue("APIResponseChannel")) 
       .get(); 

でドキュメントを見つけるcouldntの。これで私たちを案内してもらえますか? Gary..itへ

おかげで、(現在は)X-接頭辞を取得します

return IntegrationFlows.from("FileContentChannel") 
        .handle(Http.outboundGateway("http://host:port/paymentinfo/") 
          .charset("UTF-8") 
          .httpMethod(HttpMethod.GET) 
          .mappedRequestHeaders("pay*") 
          .headerMapper(headerMapper()) 
          .expectedResponseType(String.class)) 
        .channel(MessageChannels.queue("APIResponseChannel")) 
        .get(); 

@Bean 
    HeaderMapper headerMapper() { 
     DefaultHttpHeaderMapper headerMapper = new DefaultHttpHeaderMapper(); 
     String[] headerNames = {"payment-hdr1","payment-hdr2"}; 
     headerMapper.setOutboundHeaderNames(headerNames); 

     headerMapper.setUserDefinedHeaderPrefix(""); 
     return headerMapper; 
    } 

答えて

0
return IntegrationFlows.from("FileContentChannel") 
      .enrichHeaders(h -> h.header("foo1", "bar") 
            .header("foo2", "baz")) 
      .handle(Http.outboundGateway("http://host:port/paymentinfo/") 
        .charset("UTF-8") 
        .httpMethod(HttpMethod.GET) 
        .mappedRequestHeaders("foo*") 
        .expectedResponseType(String.class)) 
      .channel(MessageChannels.queue("APIResponseChannel")) 
      .get(); 

カスタムヘッダーこの アップデート1で働いていました。

カスタマイズされたDefaultHeaderMapperを使用して、必要なヘッダーパターンをマップし、userDefinedHeaderPrefix""とします。

関連する問題