1

我正在努力解决以下流程:

.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,因为我无法让它工作)。似乎在第二个请求中没有传播订阅密钥。出于某种原因,在第二个中包含了更多标题。

第一

在此处输入图像描述

第二个

在此处输入图像描述

4

1 回答 1

0

好的。我知道问题出在哪里:

private HttpEntity<?> createHttpEntityFromPayload(Message<?> message, HttpMethod httpMethod) {
Object payload = message.getPayload();
if (payload instanceof HttpEntity<?>) {
    // payload is already an HttpEntity, just return it as-is
    return (HttpEntity<?>) payload;
}
HttpHeaders httpHeaders = mapHeaders(message);

由于您将 a 从第一个调用传播ResponseEntity到第二个调用,因此确实没有任何标头映射,因为我们只是不执行该逻辑AbstractHttpRequestExecutingMessageHandler并按原样使用提供HttpEntity的。

我们无法假设您想用它做什么,但由于您提供了整个实体,我们只是不对其进行变异并按原样执行请求。

为了解决这个问题,我建议在第二次调用之前包括一些简单.transform((p) -> "")的以避免一些 HTTP 实体假设。

是的,如果 的值相同,则不需要第二个标头丰富ocp-apim-subscription-key器。

我们可能需要改进有关此问题的文档并解释此组件中如何处理请求消息。随意提出一个GH问题!

于 2020-08-31T20:47:51.187 回答