繁体   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