簡體   English   中英

Http Outbound Gateway從pojo有效負載發送Json請求

[英]Http Outbound Gateway Sending Json request from pojo payload

我正在嘗試向REST端點發送一個簡單的POST請求。 我有一個簡單的pojo,我想在有效載荷中發送為JSON。 這是pojo(請注意我使用Spring與Grails集成,因此pojo / service在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 - 無法嘗試轉換消息有效負載類型。 組件'org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler#0'沒有顯式的ConversionService引用,並且上下文中沒有'integrationConversionService'bean。

除此之外它不會給我太多。 我一整天都在嘗試一些小事情,似乎無處可去。 有人看到我錯過了嗎? 謝謝!

  1. Unable to attempt conversion of Message payload types. 別擔心:它對你沒有價值。 在大多數情況下,我們可以在沒有該integrationConversionService的應用程序中使用。 這里需要表達式。 由於您不使用任何表達式,因此該WARN不會傷害您。

  2. 你說你要將POJO作為JSON發送,那么你不應該使用extract-request-payload="false" 如果為false<int-http:outbound-gateway>將整個Message<?> <int-http:outbound-gateway>放置到請求正文中,並將content-type更改為application/x-java-serialized-object

  3. 希望你的jsonConverter在POJO < - > JSON周圍做正確的事情

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM