Spring integration Spring Integration HTTP出站网关头不是连续请求的转发器

Spring integration Spring Integration HTTP出站网关头不是连续请求的转发器,spring-integration,spring-integration-dsl,spring-integration-http,Spring Integration,Spring Integration Dsl,Spring Integration Http,我正在努力解决以下问题: .enrichHeaders(h->h.headerFunction(“ocp apim订阅密钥”,m-> “xxx”)) .handle(Http.outboundGateway(“https://northeurope.api.cognitive.microsoft.com/vision/v3" + “.0/read/analyzeResults/abc”) .mappedRequestHeaders(“ocp apim订阅密钥”) .httpMethod(http

我正在努力解决以下问题:

.enrichHeaders(h->h.headerFunction(“ocp apim订阅密钥”,m->
“xxx”))
.handle(Http.outboundGateway(“https://northeurope.api.cognitive.microsoft.com/vision/v3" +
“.0/read/analyzeResults/abc”)
.mappedRequestHeaders(“ocp apim订阅密钥”)
.httpMethod(httpMethod.GET))
.enrichHeaders(h->h.headerFunction(“ocp apim订阅密钥”,m->
“xxx”))
.handle(Http.outboundGateway(“https://northeurope.api.cognitive.microsoft.com/vision/v3" +
“.0/read/analyzeResults/def”)
.mappedRequestHeaders(“ocp apim订阅密钥”)
.httpMethod(httpMethod.GET))
第一个请求被正确提交,我得到了结果,第二个请求我得到了401 UNAUTHORIZED,这意味着不包括ocp apim订阅密钥。我尝试过不使用第二个充实步骤,因为我认为标题不会被清除,但它也没有改变任何东西

知道我做错了什么吗?我是否需要以不同的方式配置标头映射器

下面是调试的输出,它清楚地显示了包含的标题:

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}]
17:45:31.468[main]DEBUG org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler-bean'ocrDocument.http:outbound gateway#2'用于组件'ocrdocdocument.org.springframework.integration.config.ConsumerndpointFactoryBean#3';在“processing.OCRIntegrationFlow”中定义;来源:“bean method ocrDocument”收到消息:GenericMessage[payload=,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,日期=159888731000,时间戳=159888731467}]
更新 我用wireshark录制了一个会话(切换到http而不是https,因为我无法让它工作)。在第二个请求中,似乎没有传播订阅密钥。出于某种原因,在第二个标题中包含了更多的标题

第一个

第二个


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

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);
私有HttpEntity createHttpEntityFromPayload(消息消息,HttpMethod HttpMethod){
对象负载=message.getPayload();
if(HttpEntity的有效负载实例){
//有效负载已经是一个HttpEntity,只需按原样返回即可
返回(HttpEntity)有效载荷;
}
HttpHeaders HttpHeaders=mapHeaders(消息);
由于您将
响应属性
从第一个调用传播到第二个调用,因此实际上没有任何头映射,因为我们只是在
AbstractHttpRequestExecutingMessageHandler
中不执行该逻辑,而是按原样使用提供的
HttpEntity

我们不能假设您想用它做什么,但既然您已经提供了整个实体,我们就不会对它进行变异,并按原样对其执行请求

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

是的,如果
ocp apim订阅密钥的值相同,则不需要第二个标头enricher


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

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

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);
私有HttpEntity createHttpEntityFromPayload(消息消息,HttpMethod HttpMethod){
对象负载=message.getPayload();
if(HttpEntity的有效负载实例){
//有效负载已经是一个HttpEntity,只需按原样返回即可
返回(HttpEntity)有效载荷;
}
HttpHeaders HttpHeaders=mapHeaders(消息);
由于您将
响应属性
从第一个调用传播到第二个调用,因此实际上没有任何头映射,因为我们只是在
AbstractHttpRequestExecutingMessageHandler
中不执行该逻辑,而是按原样使用提供的
HttpEntity

我们不能假设您想用它做什么,但既然您已经提供了整个实体,我们就不会对它进行变异,并按原样对其执行请求

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

是的,如果
ocp apim订阅密钥的值相同,则不需要第二个标头enricher


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

此问题可能与其他问题有关。您能否使用一些wire sniffer(例如Wireshark)进行确认您的标题没有第二次传输?谢谢Artem。请查看wireshark结果。问题可能出在其他方面。您能用一些wireshark嗅探器(例如wireshark)确认吗你的标题没有第二次传输?谢谢Artem。请查看wireshark结果。酷,谢谢解释!我昨天尝试了一个附加的。在中间处理,但没有帮助。让我用.transform.酷,谢谢解释!我昨天尝试了一个附加的。在中间处理但是没用。让我试试。转换。