簡體   English   中英

使用和暴露 REST 服務並傳遞 JSON 主體

[英]Consuming & exposing a REST service and passing JSON body

我正在使用 Apache Camel 和 XML DSL 來使用和公開 REST 服務。 我有一個請求正文{"name":"your name","phonenumber":"111-111"}

我成功地能夠直接發送這個 json 請求正文並從消費端點 url 獲得成功的響應。 而當我通過暴露的 URL go 時,我得到以下異常。

org.apache.camel.component.restlet.RestletOperationException: Restlet operation failed invoking 
<!--Consumed URL--> with statusCode: 400 /n responseBody:
{"timestamp":"2020-04-07T06:15:41.302+0000","status":400,"error":"Bad Request",
"message":"Required request body is missing: public boolean
com.agcs.cids.BookingRestController.createBooking(org.bson.Document...)","path":"-----"}

在我打電話給 URL 之前,我什至能夠成功打印正文。 請在下面完善我的代碼:

<log loggingLevel="TRACE" message="Request from source: Body: ${body}" />      
<log loggingLevel="TRACE" message="Request from source: Header: ${headers}" />
<to uri="restlet:<--Consumed URL-->?restletMethod=POST" />

我猜你的代碼試圖要么 -

  1. 發送沒有{"name":"your name","phonenumber":"111-111"} JSON 正文的POST請求。 在這種情況下,您可能想重新訪問您的代碼並驗證您是否正確設置了正文,例如<setBody><to><from>標記中正確使用。
  2. 向不接受JSON主體的 URL 發送POST請求。 您是否嘗試將"Accept", "application/json"添加為 header?
  3. 驗證您是否沒有混淆您的<from><to>地址(您提到了“Consumed URL”,在<to>端點的情況下,它在語義上應該是“Consuming URL”)

暫無
暫無

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

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