Spring集成:使用应用程序/八位字节流内容类型的http转换器问题

Spring集成:使用应用程序/八位字节流内容类型的http转换器问题,spring,spring-integration,spring-cloud-stream,Spring,Spring Integration,Spring Cloud Stream,我有这个流程: @Bean public IntegrationFlow flow(){ return IntegrationFlows.from(QueueMessageSink.INPUT) .transform(Transformers.fromJson(QueueMessage.class)) .<QueueMessage, DTOMessage> transform(queueMessage -> new DTOMessage(

我有这个流程:

@Bean
public IntegrationFlow flow(){
    return IntegrationFlows.from(QueueMessageSink.INPUT)
        .transform(Transformers.fromJson(QueueMessage.class))
        .<QueueMessage, DTOMessage> transform(queueMessage -> new DTOMessage(/* transform logic */))
        .handle(Http.outboundGateway(uri).httpMethod(HttpMethod.POST))
        .channel("nullChannel")
        .get();
}
消息正确地从JSON转换为QueueMessage,从QueueMessage转换为DTOMessage,但在尝试发布DTOMessage时出现以下异常:

Caused by: org.springframework.messaging.MessageHandlingException: HTTP request execution failed for URI; nested exception is org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [com.example.DTOMessage] and content type [application/octet-stream]
我认为Http.outboundGateway正在从Spring集成消息的头读取内容类型application/octet流,这可能是我的错误

解决这个问题的正确方法是什么?我想一个可能的解决方案是将内容类型更改为application/json,但我不确定这是否是最简单的方法,我不知道如何做到这一点

提前谢谢

我想一个可能的解决方案是将内容类型更改为application/json

这确实是一种正确的方法,但不应该在绑定上这样做,而应该在流中这样做。我认为这样的事情应该对你有好处:

.enrichHeaders(h -> h
                .defaultOverwrite(true)
                .header(MessageHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.handle(Http.outboundGateway(uri).httpMethod(HttpMethod.POST))

这似乎管用,谢谢。我还有一个问题。从JSON到QueueMessage的转换正确吗?我的意思是,在enrichHeaders步骤之前,我有一条不一致的消息,其中负载是Java对象,内容类型是application/octet,我必须手动覆盖它,这听起来很奇怪。因为您将JSON转换为POJO,反之亦然。这并不是因为您将JSON转换为QueueMessage,然后将其转换为DTOMessage,因此,假设它是JSON,我们不能将字节直接传递给Http.outboundGateway。无论如何,看起来您必须根据HTTP要求覆盖它。。。
.enrichHeaders(h -> h
                .defaultOverwrite(true)
                .header(MessageHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.handle(Http.outboundGateway(uri).httpMethod(HttpMethod.POST))