簡體   English   中英

如何在 Spring Integration Rest 服務調用的 Http.outboundGateway 中添加 cutom 標頭?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM