Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring integration 无法使用int http:outbound gateway映射内容类型标头_Spring Integration_Content Type - Fatal编程技术网

Spring integration 无法使用int http:outbound gateway映射内容类型标头

Spring integration 无法使用int http:outbound gateway映射内容类型标头,spring-integration,content-type,Spring Integration,Content Type,我有一个http:inbound网关,接收一条json消息,进行一些扩展,并使用http:outbound网关将其发送到一个端点,以使用json负载调用rest服务 入站gw接收内容类型报头,它在消息报头上设置,但当有效负载使用出站gw发送到rest服务时,会发生以下错误:415不支持的媒体类型 我检查了日志,出现了以下警告: 警告DefaultHttpHeaderMapper:951-将不会设置值为“application/json”的标题“content type”,因为它不是字符串,并且没

我有一个http:inbound网关,接收一条json消息,进行一些扩展,并使用http:outbound网关将其发送到一个端点,以使用json负载调用rest服务

入站gw接收内容类型报头,它在消息报头上设置,但当有效负载使用出站gw发送到rest服务时,会发生以下错误:415不支持的媒体类型

我检查了日志,出现了以下警告:

警告DefaultHttpHeaderMapper:951-将不会设置值为“application/json”的标题“content type”,因为它不是字符串,并且没有可用的转换器。考虑使用转换服务注册一个转换器(例如)

这很奇怪,因为content-type头是用值application/json设置的,我使用映射的请求头=“HTTP\u-request\u-headers”。我正在使用SI 4.3.1.RELEASE,你知道吗

这是http:inboundgw

<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:04634信息服务消息:194-通用消息[有效载荷=字节[76],标题={content length=76,replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@44237f19,errorChannel=org.springframework.messaging.core.GenericMessageTemplate$TemporaryReplyChannel@44237f19,content type=application/json,connection=keep-alive,id=79012bea-263b-0f48-6e96-5fc832c08da6,accept=[text/plain,/],timestamp=1475932024630}]

这看起来像一个bug;在Spring集成消息中,头映射器应该总是将
内容类型映射到
内容类型
,或从
内容类型
映射到
内容类型。出站适配器需要
内容类型

然而,在入站端执行此操作的代码正在查找
内容类型
(区分大小写),并且正在从Spring MVC获取
内容类型
。可能发生了一些变化

看起来我们需要使这个映射测试不区分大小写

同时,您可以添加一个标题充实器来复制标题

<header-enricher ...>
    <header name="contentType" expression="headers['content-type']" />
</header-enricher>


和一个头过滤器,用于删除
内容类型
头(以消除警告日志)。

这看起来像一个bug;头映射器应该总是在Spring集成消息中将
内容类型
映射到
内容类型
。出站适配器需要
内容类型

然而,在入站端执行此操作的代码正在查找
内容类型
(区分大小写),并且正在从Spring MVC获取
内容类型
。可能发生了一些变化

看起来我们需要使这个映射测试不区分大小写

同时,您可以添加一个标题充实器来复制标题

<header-enricher ...>
    <header name="contentType" expression="headers['content-type']" />
</header-enricher>


和一个头过滤器,用于删除
内容类型
头(以消除警告日志)。

转换服务未提供
时,
DefaultHttpHeaderMapper
中还有另一个错误,因此
内容类型
头的
MimeType
无法转换为字符串

您可以为
创建
DefaultHttpHeaderMapper.outboundMapper()
bean,而不是
映射的请求头
。或者,再次:将
内容类型重新映射到自身:

<header name="content-type" expression="headers['content-type'].toString()" override="true"/>

转换服务未提供时,
DefaultHttpHeaderMapper
中还有另一个bug,因此
内容类型的
头的
MimeType
无法转换为字符串

您可以为
创建
DefaultHttpHeaderMapper.outboundMapper()
bean,而不是
映射的请求头
。或者,再次:将
内容类型重新映射到自身:

<header name="content-type" expression="headers['content-type'].toString()" override="true"/>

它固定在下周发布的位置。可用于测试。它固定在下周发布的位置。可用于测试。