java - Http 出站网关从 pojo 负载发送 Json 请求

标签 java spring spring-integration

我正在尝试向 REST 端点发送一个简单的 POST 请求。我有一个简单的 pojo,我想将其作为 JSON 发送到有效负载中。这是 pojo(请注意,我将 Spring Integration 与 grails 结合使用,因此 pojo/服务在 Groovy 中):

class Person implements Serializable {
    String name
}

这是我的网关:

public interface PersonGateway {
    Person savePerson(Person person)
}

这里是布线的重要部分:

<int:channel id="requestChannel" />
<int:channel id="responseChannel" />
<int:header-enricher input-channel="requestChannel">
    <int:header name="Content-Type" value="application/json" />
</int:header-enricher>

<int:gateway id="PersonGateway"
             service-interface="com.example.PersonGateway"
             default-request-channel="requestChannel"
             default-reply-channel="responseChannel">
    <int:method name="savePerson" />
</int:gateway>
<int-http:outbound-gateway url="http://127.0.0.1:8000/person"
                           http-method="POST"
                           message-converters="jsonConverter"
                           expected-response-type="com.example.Person"
                           request-channel="requestChannel"
                           extract-request-payload="false"/>

此 POST 请求永远不会到达该服务,但不会抛出任何异常。当我记录所有级别时,我得到的唯一看起来像线索的是:

2014-03-30 16:35:07,313 [main] DEBUG outbound.HttpRequestExecutingMessageHandler - Unable to attempt conversion of Message payload types. Component 'org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler#0' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.

除此之外,它并没有给我太多。我整天都在尝试一些小事情,但似乎无济于事。有人看到我错过了什么吗?谢谢!

最佳答案

  1. Unable to attempt conversion of Message payload types. 别担心:它对你没有值(value)。在大多数情况下,我们可以在没有它的情况下生活在我们的应用程序中integrationConversionService .这里需要表达式。由于您不使用任何表达式,因此该 WARN 不会伤害您。

  2. 你说你要将 POJO 作为 JSON 发送,那么你不应该使用 extract-request-payload="false" .与 false <int-http:outbound-gateway>放置到整个请求主体 Message<?>和变化content-typeapplication/x-java-serialized-object

  3. 希望你的jsonConverter围绕 POJO <-> JSON

  4. 做正确的事情

关于java - Http 出站网关从 pojo 负载发送 Json 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22750403/

相关文章:

java - 为什么我在 Java 中得到 NoClassDefFoundError?

java - 按键监听器不工作

java - Elasticsearch存储库分页未返回正确的页面大小并且未对数据进行排序

java - 当使用 Spring Integration 从队列中读取的消息在 Transacted 情况下为 ACK 时

Spring Cloud Streams - 源和接收器的多个动态目的地

Java 程序查找一副牌中四张牌的组合数等于 24

java - Jsp 404异常

java - EntityManager.merge() 未提交(Wildfly、JPA、JTA)

spring - 我可以使用 Spring Integration 作为守护进程来轮询目录吗?

java - 如果我们在父列表中添加元素,为什么 JDK 会向 UnmodifyableList 添加一个元素