java - 使用和公开 REST 服务并传递 JSON 正文
问题描述
我正在使用带有 XML DSL 的 Apache Camel 来使用和公开 REST 服务。我有一个请求正文{"name":"your name","phonenumber":"111-111"}
我成功地能够直接发送此 json 请求正文并从使用的端点 url 获得成功的响应。而当我浏览暴露的 URL 时,我得到了以下异常。
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" />
解决方案
我猜你的代码试图要么 -
- 发送
POST
没有{"name":"your name","phonenumber":"111-111"}
JSON 正文的请求。在这种情况下,您可能想重新访问您的代码并验证您是否正确设置了正文,例如在and标记<setBody>
中正确使用了。<to>
<from>
POST
向不接受JSON
正文的URL发送请求。您是否尝试过添加"Accept", "application/json"
为标题?- 验证您是否没有混淆您的地址
<from>
和地址(您提到了“Consumed URL”,在端点<to>
的情况下,语义上应该是“Consuming URL” )<to>
推荐阅读
- excel - 宏,连续擦除数据(锁定单元格在混合位置)
- cmake - 我可以将 CMakeLists.txt(s) 放在单独的文件夹中吗?
- dart - 在 Flutter 应用程序中将辅助隔离中的地理定位作为后台任务
- python - 无法通过 JSON 文件中的第一个字典
- javascript - 为什么mysql数据库信息不会传递给express.js函数?
- php - 改造不返回 ETag 和 Last-Modified
- android - 以编程方式设置 TabLayout 项目标题
- python - 在 python 中读取 NetCDF 文件
- maven - Cucumber+Maven+TestNG-->即使在构建成功后,控制台输出也会显示为 TestRun as 0
- python-3.x - 将“预压缩”列表值转换为整数