首页 > 解决方案 > 无法正确使用 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。

标签: javaspring-bootapache-camel

解决方案


尝试摆脱 Object 类型,尝试使用 String 代替。您在 Object 上使用 info.toString() ,这就是您打印它的原因。


推荐阅读