Apache骆驼休息dsl RestBindingMode.json无法正常运行

时间:2018-10-23 13:53:09

标签: apache-camel spring-camel

我正在尝试使用camel-rest-dsl构建rest api。我尝试过与多个提供者,火花休息区,码头一起使用。但是当我使用RestBindingMode.json时,它会引发marshelling异常,如果我删除剩余绑定模式,它会很好地工作。

SpringRouteBuilder

@Component
public class RestAPIRoutes extends SpringRouteBuilder {

    @Override
    public void configure() throws Exception {
        restConfiguration().component("spark-rest")
            .bindingMode(RestBindingMode.json)
            .port(8787)
            .dataFormatProperty("prettyPrint","true");

        rest("/balance").produces("application/json").consumes("application/json")
            /* mock api */
            .get("/query").route().bean(BalanceService.class,"fetchBalance").endRest()
            /* fetch balance by msisdn*/
            .get("/query/{msisdn}").description("Fetch line balance by msisdn")
                .type(BalanceInfo.class).to("bean:balanceService?method=fetchBalance(${header.msisdn})")
            .post("/update").type(BalanceInfo.class).outType(BalanceInfo.class).to("bean:balanceService?method=updateBalance");

    }

}

这里balanceService是带有重载方法的简单Spring @Service,而BalanceInfo是具有两个字段和getter设置程序的简单pojo类。

Pom依赖

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spark-rest</artifactId>
        <version>2.22.1</version>
    </dependency>
<dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>2.22.1</version>
        </dependency>

异常

org.apache.camel.processor.binding.BindingException: Cannot bind to json as message body is not json compatible. Exchange[ID-LTB0202777-MAC-1540301942376-3-1]
    at org.apache.camel.processor.RestBindingAdvice.unmarshal(RestBindingAdvice.java:317) ~[camel-core-2.22.1.jar:2.22.1]
    at org.apache.camel.processor.RestBindingAdvice.before(RestBindingAdvice.java:137) ~[camel-core-2.22.1.jar:2.22.1]

1 个答案:

答案 0 :(得分:1)

检查项目中是否包含依赖项camel-jackson