我找不到在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");
有人可以帮我吗
答案 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))