java - 无法正确使用 Apache Camel requestBody

标签 java spring-boot apache-camel

我正在使用 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。

最佳答案

尝试摆脱对象类型,尝试使用字符串代替。您正在对象上使用 info.toString(),这就是您打印该信息的原因。

关于java - 无法正确使用 Apache Camel requestBody,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59990733/

相关文章:

java - 在单独安装 MYSQL 的同时使用 XAMPP- phpmyadmin

java - spring boot不加载jsp文件

java - 找不到依赖项 'com.amazonaws'

jpa - 如何从 Camel jpa 组件获取结果集?

java - 如何确定 JMock 模拟对象正在模拟哪个类?

java - HTML 字段 json 编码为深层嵌套对象

java - Spring OAuth2 client_credentials 与预身份验证用户相结合

java - 无法使用 XPATH 设置 header

java - receive() 之后 PollingConsumer 模板中的信号异常

java - Android Studio 在记事本中打开 xml 文件