我有一个http:入站网关,接收一条json消息,进行一些充实,并使用http:outbound gateway将其发送到端点,使用json有效负载调用rest服务。
入站-gw接收到内容类型的报头,它在消息头上设置,但是当有效负载使用出站-gw发送到rest服务时,会发生以下错误: 415不支持的媒体类型
我检查了日志,并显示了以下警告:
警告DefaultHttpHeaderMapper:951 -标头‘content’和值'application/json‘将不会被设置,因为它不是字符串,也没有转换器可用。考虑使用ConversionService注册转换器(例如,)
这很奇怪,因为内容类型的头是用值application/json设置的,我使用mapped-request-headers="HTTP_REQUEST_HEADERS".。我用的是SI 4.3.1.RELEASE,知道吗?
这里是http:inbound
<int-http:inbound-gateway id="restHttpInboundGateway"
request-channel="restHttpInboundChannel" path="/services"
supported-methods="GET,POST,PUT,DELETE,PATCH,HEAD"
reply-channel="restHttpOutboundChannel"
mapped-request-headers="http_requestMethod,Content-Length,Accept,Connection, Content-Type">
<int-http:request-mapping consumes="application/json,application/xml"
produces="application/json,application/xml" />
</int-http:inbound-gateway>这是出站-gw
<int-http:outbound-gateway id="restHttpOutboundGateway"
request-channel="restHttpOutboundGatewayChannel" reply-channel="restHttpOutboundChannel"
url-expression="https://localhost:8443/service/rest/contacts/1" mapped-request-headers="HTTP_REQUEST_HEADERS"
http-method-expression="PUT" expected-response-type="java.lang.String"
charset="UTF-8"/>以下是出站-gw之前记录的消息:
2016-10-08 10:07:04,634 INFO serviceMessage:194- GenericMessage [payload=byte76,headers={content-length=76,payload=byte76 content-type=application/json,connection=备存,id=79012 bea-263B-0f48-6e96-5fc832c08da6,accept=text/平原,/,timestamp=1475932024630}]
发布于 2016-10-08 14:52:10
这看起来像一个bug;报头映射程序应该总是在Spring消息中将Content-Type映射到/从contentType映射。出站适配器正在等待contentType。
但是,在入站端这样做的代码正在寻找Content-Type (区分大小写),并从Spring获得content-type。也许是什么改变了。
看起来我们需要让这个映射测试不区分大小写。
在此期间,您可以添加一个标题丰富她复制标题..。
<header-enricher ...>
<header name="contentType" expression="headers['content-type']" />
</header-enricher>和一个头-过滤器,以删除content-type头(以消除警告日志)。
发布于 2016-10-10 18:11:37
DefaultHttpHeaderMapper中还有另一个错误,当它不随ConversionService提供时,因此不能将content-type头的MimeType转换为字符串。
您可以为DefaultHttpHeaderMapper.outboundMapper()创建mapped-request-headers而不是<int-http:outbound-gateway>。或者,再一次:将content-type映射到自身:
<header name="content-type" expression="headers['content-type'].toString()" override="true"/>https://stackoverflow.com/questions/39932959
复制相似问题