java - 无法正确使用 Apache Camel requestBody
问题描述
我正在使用 Apcahe Camel 和 Spring Boot,我的目标是使用 Camel 向 REST API 发出请求并获得响应。
我有这个请求映射:
@RequestMapping("/annotation")
String getAnnotation(@RequestBody JSONObject payload) {
Object info = producerTemplate.requestBody("direct:annotation", payload, Object.class);
return info.toString();
}
还有这条路线;
from("direct:annotation").
convertBodyTo(String.class).
log("Receiving a annotation request").
to("http4://"+ address +"/annotation");
当我向 /annotation 发出请求时,我收到以下响应:
org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream@7d5a6dba
我想收到消息的正文,在这种情况下是 JSON。
解决方案
尝试摆脱 Object 类型,尝试使用 String 代替。您在 Object 上使用 info.toString() ,这就是您打印它的原因。
推荐阅读
- c - 在包含字符串的 typedef 结构中使用指针
- javascript - 在网格数组上动态跨越 div
- python - Python:如果键的值在同一个字典中存在多次,则合并它
- r - R中径向树状图的数据结构和包
- java - ReflectionTestUtils 是否仅适用于类的字段,而不适用于该类方法内定义的变量?
- javascript - 获取 API 不通过 post 发送数据
- javascript - 如何在 JSP 中实现机场自动完成功能?
- java - 是否可以在加载后将文本写入网页?
- etl - Apache NiFi 中处理器属性和流文件属性之间的区别
- javascript - 如何在选择框上获取值添加动态