如何将请求标头添加到outboundGateway spring integration dsl

时间:2018-05-04 13:38:31

标签: spring-integration spring-integration-dsl

我找不到在spring integration dsl中向outboundGateway添加标题的函数。

.handle(outboundGateway("localhost:8080/search")
       .httpMethod(HttpMethod.GET)
       .expectedResponseType(Order.class))

我想要添加到请求的标题是

HttpHeaders headers = new HttpHeaders();
headers.setAccept(newArrayList(APPLICATION_JSON));
headers.setContentType(APPLICATION_JSON);
headers.add("Client-Id", "test");

有人可以帮我吗

1 个答案:

答案 0 :(得分:3)

这是正确的:Spring Integration不允许直接操作HttpHeaders对象。相反,您应该遵循规范的消息传递方法 - 免费协议.enrichHeaders()

.enrichHeaders(e -> e
                        .header(DefaultHttpHeaderMapper.ACCEPT, APPLICATION_JSON)
                        .header(DefaultHttpHeaderMapper.CONTENT_TYPE, APPLICATION_JSON)
                        .header("Client-Id", "test"))
.handle(outboundGateway("localhost:8080/search")
   .httpMethod(HttpMethod.GET)
   .expectedResponseType(Order.class))