http - 一些 Camel IN 交换标头未映射到 HTTP 标头,尽管 mapHttpMessageHeaders 和 copyHeaders 都默认为 true
问题描述
我正在使用 Camel 3.1.0 版及其 http 组件来调用 REST 端点,该端点需要以下标头:日期、主机、摘要、授权等以确保安全。但是,当我在向 http 组件发送请求之前在路由中设置所有这些标头时,总是缺少“日期”HTTP 标头。使用 WireMock 和真实测试环境进行测试。如果我将它与其他几个测试一起运行而不是单独运行,那么测试也可以通过。
这是代码:
.setHeader("flowId", simple("\${body.flowId}"))
.process { exchange ->
with(pubsubConfig) { exchange.setPubsubTimeHeaders(minIntervalValueMills, maxIntervalValueMills, timeoutMillis) }
val settlementAdviceRequestDto = exchange.message.body as SettlementAdviceRequestDto
exchange.setProperty("settlementAdviceRequestDto", settlementAdviceRequestDto)
// Setting security headers
request.entity = StringEntity(jacksonObjectMapper().writeValueAsString(settlementAdviceRequestDto))
signer.signRequest(request, exchange.message)
}
.marshal(settlementAdviceRequestJacksonDataFormat)
.logInfoWithBreadCrumbId("Received SettlementAdviceRequestDto from PubSub, flowId: \${header.flowId}, sending to N&TS with \${headers}")
.to(with(ntsConfigProperties) {
"$protocol://$host:$port/$path?" +
"httpClient.maxConnTotal=$maxConnectionsTotal" +
"&httpClient.maxConnPerRoute=$maxConnectionsPerRoute" +
"&httpClient.connectionRequestTimeout=$connectionRequestTimeout" +
"&httpClient.connectTimeout=$connectionTimeout" +
"&httpClient.socketTimeout=$socketTimeout" +
"&httpClient.redirectsEnabled=$followRedirects"
})
.logInfoWithBreadCrumbId("SettlementAdviceRequestDto sent to N&TS, flowId: \${header.flowId} \${headers}")
以下是检查日期标题的测试日志:
2020-05-13 11:11:22.267 INFO 5514 --- [tlement.advice]] ocffsroute.SettlementAdviceRoute:[ID-C02VC27UHTD6-liping-1589361082160-0-1] 从 PubSub 收到 SettlementAdviceRequestDto,flowId:550e8400-e29b-4 -a716-446655440000, sending to N&TS with {CamelGooglePubsub.MsgAckId=TgQhIT4wPkVTRFAGFixdRkhRNxkIaFEOT14jPzUgKEUQC1MTUVx2B0YQajNcdQdRDRh1f2Ehbg4UBQEXWX5VWwk8aH58dAZUDRt2eGJ1aF8bCANCW1a0tP24kajpRx1tNZCxo6RASsXWuO52Zhg9XBJLLD5-KTBFQV5AEkwiBURJUytDCypYEQ, CamelGooglePubsub.MessageId=1150245302589178, CamelGooglePubsub.PublishTime=2020-05-13T09:11:20.194Z, breadcrumbId=ID-C02VC27UHTD6-liping-1589361082160-0 -1,flowId=550e8400-e29b-41d4-a716-446655440000,CamelGooglePubsub.AckDeadline=2,CamelPubsubHeader.Lifetime=2047,CamelPubsubHeader.LifeTimeout=5000,日期=2020 年 5 月 13 日星期三 09:11:22 GMT,主机=localhost ,content-type=application/json, content-length=417, digest=SHA-256=Ocdp4q+ZLUshftQIsycfkidD2SEEnvU29TpX/AFkMt4=, Authorization= keyId="id",algorithm="hmac-sha256",headers="date (request-目标) 主机内容长度内容类型摘要",signature="j/GUbOD0UijQJEjuwCrehQ+seoJ9yeHObYGXbuZgJJY="}
2020-05-13 11:11:22.328 INFO 5514 --- [tp293974199-118] / : RequestHandlerClass 从上下文返回 com.github.tomakehurst.wiremock.http.StubRequestHandler。返回的“空”下的归一化映射
2020-05-13 11:11:22.373 错误 5514 --- [tp293974199-118] WireMock:
Request was not matched
=======================
date [contains] : GMT | <<<<< Header is not present
host [contains] : localhost | host: localhost:14685
content-length [contains] : 417 | content-length: 417
content-type [contains] : application/json | content-type: application/json
digest [contains] : | digest:
...
以下是未检查日期标题的测试日志:
2020-05-13 11:20:09.092 INFO 5628 --- [tlement.advice]] ocffsroute.SettlementAdviceRoute:[ID-C02VC27UHTD6-liping-1589361608990-0-1] 从 PubSub 收到 SettlementAdviceRequestDto,flowId:550e8400-e29b-4 -a716-446655440000, sending to N&TS with {CamelGooglePubsub.MsgAckId=BCEhPjA-RVNEUAYWLF1GSFE3GQhoUQ5PXiM_NSAoRRIGCBQFfH1yR1B1XjN1B1ENGXN6Y3U-XxYGVEUCdF9RGx9ZXH5VBlAIGXB-ZnZvWxoFA0BTeXfQ16DUpajANUsxIYq6v7BfeuyjqYNhZhs9XxJLLD5-KStFQV5AEkwiHkRJUytDCypYEU4, CamelGooglePubsub.MessageId=1150237351941507, CamelGooglePubsub.PublishTime=2020-05-13T09:20:07.119Z, breadcrumbId=ID-C02VC27UHTD6 -liping-1589361608990-0-1,flowId=550e8400-e29b-41d4-a716-446655440000,CamelGooglePubsub.AckDeadline=1,CamelPubsubHeader.Lifetime=1949,CamelPubsubHeader.LifeTimeout=5000,日期=星期三,2020 年 5 月 13 日 09:02 09 GMT,主机=本地主机,content-type=application/json, content-length=417, digest=SHA-256=Ocdp4q+ZLUshftQIsycfkidD2SEEnvU29TpX/AFkMt4=, Authorization= keyId="id",algorithm="hmac-sha256",headers="date (request-目标) 主机内容长度内容类型摘要",signature="POpggmhIDI8tNBsb7239ksYEGfwY+IB/Rn93PCrkGsY="}
2020-05-13 11:20:09.145 INFO 5628 --- [tp294593670-119] / : RequestHandlerClass 从上下文返回 com.github.tomakehurst.wiremock.http.StubRequestHandler。返回的“空”下的归一化映射
2020-05-13 11:20:09.434 INFO 5628 --- [tlement.advice]] ocffsroute.SettlementAdviceRoute:[ID-C02VC27UHTD6-liping-1589361608990-0-1] SettlementAdviceRequestDto 发送到 N&TS,flowId:550e8400-e29b-41d -a716-446655440000 {CamelHttpResponseCode=200, CamelHttpResponseText=OK, Matched-Stub-Id=4efce26c-dbfa-457e-864d-98f29ef38f97, Vary=Accept-Encoding, User-Agent, Transfer-Encoding=chunked, Server=Jetty(9.2 .z-SNAPSHOT), CamelGooglePubsub.MsgAckId=BCEhPjA-RVNEUAYWLF1GSFE3GQhoUQ5PXiM_NSAoRRIGCBQFfH1yR1B1XjN1B1ENGXN6Y3U-XxYGVEUCdF9RGx9ZXH5VBlAIGXB-ZnZvWxoFA0BTeXfQ16DUpajANUsxIYq6v7BfeuyjqYNhZhs9XxJLLD5-KStFQV5AEkwiHkRJUytDCypYEU4, CamelGooglePubsub.MessageId=1150237351941507, CamelGooglePubsub.PublishTime=2020-05-13T09:20:07.119Z, breadcrumbId=ID-C02VC27UHTD6-liping-1589361608990 -0-1, flowId=550e8400-e29b-41d4-a716-446655440000,CamelGooglePubsub.AckDeadline=1, CamelPubsubHeader.Lifetime=1949, CamelPubsubHeader.LifeTimeout=5000, digest=SHA-256=Ocdp4q+ZLUshftQIsycfkidD2SEEnvU29TpX/AFkMt4=, Authorization= keyId="id",algorithm="hmac-sha256",headers="日期(请求目标)主机内容长度内容类型摘要”,signature="POpggmhIDI8tNBsb7239ksYEGfwY+IB/Rn93PCrkGsY="}
解决方案
推荐阅读
- spring - 将服务注入另一个服务的最佳实践
- java - JdbcSQLNonTransientConnectionException:数据库可能已在使用中:“等待数据库关闭时间超过 1 分钟”
- python - 从 cloudwatch 中检索 Json 并通过电子邮件发送获取的 Json
- javascript - 获取ID后将属性添加到数组中的一行
- javascript - 在使用图像标签加载的悬停时更改 SVG 颜色的一部分
- c# - 在 C# 中,如果 SharePoint 网站上不存在文件夹,如何创建该文件夹
- hadoop - 无法使用 Flume 检索 Twitter 流数据
- javascript - jQuery循环遍历选定的html元素行 - 数据表
- visual-studio - .netstandard2.1、AndroidQ 和 TFS 构建
- python - app.autodiscover_tasks() 类型错误:autodiscover_tasks() 缺少 1 个必需的位置参数:'packages'