![](/img/trans.png)
[英]How to write the JUnit for the Spring Integration DSL Http.outboundGateway operation
[英]How to add cutom header in Http.outboundGateway in Spring Integration Rest Service Call?
我正在嘗試使用自定義標頭進行 Rest Web 服務 POST 方法調用。 嘗試在enrichHeaders 中添加自定義標頭仍然得到HTTP 403 Forbidden 響應。 你能幫忙提供正確的代碼片段嗎?
.enrichHeaders(h -> h.header("X-API-Key","ABCEDABCED").header(CONTENT_TYPE, APPLICATION_JSON_VALUE).header(APP_NAME, XXX).header(ACCEPT,
APPLICATION_JSON_VALUE))
.handle(Http.outboundGateway(config.getXxxWebServiceUrl()).httpMethod(HttpMethod.POST)
.expectedResponseType(String.class).requestFactory(xxxRequestFactory()),
c -> c.advice(sendToArchive.sendToArhive()))
.log().get();
錯誤日志:-
[bean 'xxxDispatcher1.http:outbound-gateway#0' for component 'xxxDispatcher1.org.springframework.integration.config.ConsumerEndpointFactoryBean#2'; defined in: 'class path resource [service/xxxDispatcher.class]'; from source: 'bean method xxxDispatcher1']; nested exception is org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden: [{"message":"Forbidden"}]
at
請參閱文檔中的標題映射部分: https : //docs.spring.io/spring-integration/docs/current/reference/html/http.html#http-header-mapping
默認情況下,所有標准 HTTP 標頭都從消息映射到 HTTP 請求或響應標頭,無需進一步配置。
所以,既然你不提供mappedRequestHeaders()
的選項Http.outboundGateway()
因此您的APP_NAME
自定義頭沒有被映射,而不是轉移通過HTTP的REST服務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.