Spring 找不到适用于请求类型[request.model.RTPRequest]和内容类型[application/x-java-serialized-object]的HttpMessageConverter
我试图使用Spring集成的HttpRequestExecutingMessageHandler对REST服务调用POST方法 我已经试过了服务器上提供的解决方案 下面是我的配置:我在bean配置类上有@EnableIntegration和@IntegrationComponentScan注释。我已经验证了我在类路径上有Jackson数据绑定jar。我可以通过邮递员得到有效的回复Spring 找不到适用于请求类型[request.model.RTPRequest]和内容类型[application/x-java-serialized-object]的HttpMessageConverter,spring,spring-integration,spring-rest,Spring,Spring Integration,Spring Rest,我试图使用Spring集成的HttpRequestExecutingMessageHandler对REST服务调用POST方法 我已经试过了服务器上提供的解决方案 下面是我的配置:我在bean配置类上有@EnableIntegration和@IntegrationComponentScan注释。我已经验证了我在类路径上有Jackson数据绑定jar。我可以通过邮递员得到有效的回复 @Bean public MessageChannel rtpRequestChannel() { Mess
@Bean
public MessageChannel rtpRequestChannel() {
MessageChannel rtpRequestPostOperationRequestChannel = new DirectChannel();
return rtpRequestPostOperationRequestChannel;
}
@Bean
public MessageChannel rtpResponseChannel() {
MessageChannel rtpRequestPostOperationResponseChannel = new DirectChannel();
return rtpRequestPostOperationResponseChannel;
}
@ServiceActivator(inputChannel = "rtpRequestChannel")
@Bean
public MessageHandler httResponseMessageHandler(MessageChannel rtpResponseChannel) {
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler(
"http://myhost:8080/services/v1-0/request");
handler.setHttpMethod(HttpMethod.POST);
handler.setOutputChannel(rtpResponseChannel);
handler.setExpectedResponseType(RTPResponse.class);
return handler;
}
下面是ServiceActivator端点的POJO
@Service
public class RTPRequestServiceClient implements IRTPRequestServiceClient {
@Override
@ServiceActivator(inputChannel="rtpRequestChannel")
public void makeCall(Message<RtpResponse> pr) {
RtpResponse response = pr.getPayload();
System.out.println(response);
}
我的回答是:
public class RTPResponse implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3504586520124861349L;
private String id;
private String responseId;
@JsonCreator
public RTPResponse(@JsonProperty("id") String id, @JsonProperty("responseId") String responseId) {
super();
this.id = id;
this.responseId = responseId;
}
// getters ommited for brevity
}
我的请求如下:
RTPRequest body = new RTPRequest(....);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(IntegrationBeanConfiguration.class);
MessageChannel rtpRequestChannel = (MessageChannel) context.getBean("rtpRequestChannel");
rtpRequestChannel
.send(
MessageBuilder.withPayload(body)
.setHeader("accept","application/json")
.setHeader("Sender","API_GATEWAY")
.setHeader("ClientId","DIGITAL")
.build()
);
我对Spring集成http相当陌生。我假设RTPRequest对象将通过HttpRequestExecutingMessageHandler默认消息转换器链和类路径中的Jackson数据绑定转换为JSON
请告知。当您发送请求时,您必须将
contentType
标题与accept
一起明确设置:
.setHeader(MessageHeaders.CONTENT_TYPE,"application/json")
要强制执行restemplate
,请使用提到的MappingJackson2HttpMessageConverter
或者您可以配置HttpRequestExecutingMessageHandler
仅使用此MappingJackson2HttpMessageConverter
.setHeader(MessageHeaders.CONTENT_TYPE,"application/json")