[英]Spring Integration http:outbound-gateway “no suitable HttpMessageConverter”
We are receiving the following error: 我们收到以下错误:
org.springframework.web.client.RestClientException: Could not write request:
no suitable HttpMessageConverter found for
request type [com.company.FileRecord] and
content type [application/x-java-serialized-object]
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:770)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:549)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:527)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:472)
...
This is being thrown by an http:outbound-gateway
with a MappingJackson2HttpMessageConverter
attached, like so: 这是由附加了
MappingJackson2HttpMessageConverter
的http:outbound-gateway
抛出的,如下所示:
<bean id="jsonMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes"
value="application/x-java-serialized-object"/>
</bean>
<int:transformer input-channel="transformationChannel"
output-channel="registrationQueue"
ref="fileTransformer"/>
<int:channel id="registrationQueue"/>
<int-http:outbound-gateway id="gateway"
request-channel="registrationQueue"
message-converters="jsonMessageConverter"
url-expression="@urlGenerator.resolve()"
http-method="POST"
expected-response-type="javax.ws.rs.core.Response"
reply-channel="nullChannel"
error-handler="httpResponseErrorHandler"/>
Out object being serialized is annotated for Jackson serialization: 被序列化的Out对象标注为Jackson序列化:
public class FileRecord {
@JsonProperty
private final String id;
@JsonProperty
private final String path;
...
}
I believe this was working with Spring Integration 2.2 and started to fail with a migration to 3.0. 我相信这与Spring Integration 2.2一起使用,并且由于迁移到3.0而开始失败。
It jumps out at me as odd that we are trying to serialize as application/x-java-serialized-object
. 我们试图序列化为
application/x-java-serialized-object
,这让我感到奇怪。 I'd expect application/json
here. 我希望在这里
application/json
。 Perhaps a header-enricher
is called for? 也许需要一个
header-enricher
的人? If so, I'd like to understand why exactly this needs to expressed. 如果是这样,我想了解为什么需要准确表达这一点。 Shouldn't my
jsonMessageConverter
know this? 我的
jsonMessageConverter
不应该知道吗?
I'm not sure what the true cause or fix is, but I found a different approach which does the trick. 我不确定真正的原因或解决方法是什么,但是我找到了解决问题的方法。
First, I removed the MappingJackson2HttpMessageConverter
bean entirely. 首先,我完全删除了
MappingJackson2HttpMessageConverter
bean。
I then added an extra transformer to explicitly convert my POJO to JSON: 然后,我添加了一个额外的转换器,将我的POJO显式转换为JSON:
<int:transformer input-channel="objectTransformationChannel"
output-channel="jsonTransformationChannel"
ref="fileTransformer"/>
<int:channel id="jsonTransformationChannel"/>
<int:object-to-json-transformer input-channel="jsonTransformationChannel"
output-channel="registrationQueue"/>
<int:channel id="registrationQueue"/>
For the outbound-gateway
, I just needed to remove the message-converters
as my payload is now JSON. 对于
outbound-gateway
,我只需要删除message-converters
因为我的有效负载现在是JSON。
<int-http:outbound-gateway id="gateway"
request-channel="registrationQueue"
url-expression="@urlGenerator.resolve()"
http-method="POST"
expected-response-type="javax.ws.rs.core.Response"
reply-channel="nullChannel"
error-handler="httpResponseErrorHandler"/>
?? ??
You are replacing the default supported (json) media types with this... 您正在用此替换默认的受支持(json)媒体类型...
<property name="supportedMediaTypes"
value="application/x-java-serialized-object"/>
...the constructor sets them up properly... 构造函数正确设置了它们
public MappingJackson2HttpMessageConverter() {
super(new MediaType("application", "json", DEFAULT_CHARSET),
new MediaType("application", "*+json", DEFAULT_CHARSET));
}
Just remove... 只是删除...
<property name="supportedMediaTypes"
value="application/x-java-serialized-object"/>
...and you should be good. ...你应该很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.