Spring Integration HTTP Outbound Gateway标头未在连续请求时转发

问题描述

我在以下流程中苦苦挣扎:

.enrichHeaders(h -> h.headerFunction("ocp-apim-subscription-key",m ->
        "xxx"))
.handle(Http.outboundGateway("https://northeurope.api.cognitive.microsoft.com/vision/v3" +
        ".0/read/analyzeResults/abc")
        .mappedRequestHeaders("ocp-apim-subscription-key")
        .httpMethod(HttpMethod.GET))
.enrichHeaders(h -> h.headerFunction("ocp-apim-subscription-key",m ->
        "xxx"))
.handle(Http.outboundGateway("https://northeurope.api.cognitive.microsoft.com/vision/v3" +
        ".0/read/analyzeResults/def")
        .mappedRequestHeaders("ocp-apim-subscription-key")
        .httpMethod(HttpMethod.GET))

第一个请求已正确提交,我得到了结果,第二个请求得到了 401 UNAUTHORIZED ,这意味着 ocp-apim-subscription-key 不是包括在内。我尝试过没有第二个富集步骤,因为我认为不会清除标头,但它也没有任何改变。

知道我可能做错了什么吗?我是否需要以其他方式配置标头映射器?

以下是调试的输出,该输出清楚地表明包含了标头:

17:45:31.468 [main] DEBUG org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler - bean 'ocrDocument.http:outbound-gateway#2' for component 'ocrDocument.org.springframework.integration.config.ConsumerEndpointFactoryBean#3'; defined in: 'processing.OCRIntegrationFlow'; from source: 'bean method ocrDocument' received message: GenericMessage [payload=<200,[Transfer-Encoding:"chunked",Content-Type:"application/json; charset=utf-8",x-envoy-upstream-service-time:"25",CSP-Billing-Usage:"CognitiveServices.ComputerVision.Transaction=1",Strict-Transport-Security:"max-age=31536000; includeSubDomains; preload",x-content-type-options:"nosniff",Date:"Mon,31 Aug 2020 15:45:31 GMT"]>,headers={Transfer-Encoding=chunked,ocp-apim-subscription-key=xxx,id=11fa4a77-d97a-772b-69b6-059de29ef808,contentType=application/json;charset=utf-8,http_statusCode=200 OK,Date=1598888731000,timestamp=1598888731467}]

更新 我已经记录了wireshark的会话(由于无法正常工作,切换到了http而不是https)。似乎在第二个请求中,订阅密钥没有传播。由于某种原因,第二个中包含了更多标题。

第一个

enter image description here

第二个

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)