无法正确使用Apache Camel requestBody

时间:2020-01-30 16:49:09

标签: java spring-boot apache-camel

我正在使用Apcahe Camel和Spring引导,我的目标是使用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。

1 个答案:

答案 0 :(得分:1)

尝试摆脱对象类型,请尝试使用字符串。您正在对象上使用info.toString(),这就是您将其打印出来的原因。