Apache 骆驼休息 dsl RestBindingMode.json 不工作
Apache camel rest dsl RestBindingMode.json is not working
我正在尝试使用 camel-rest-dsl 构建 rest api。我尝试过多个提供商、spark-rest、jetty。但是当我使用 RestBindingMode.json 时它抛出编组异常,如果我删除 rest 绑定模式它工作正常。
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 setter 的简单 pojo class。
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]
检查您的项目中是否包含依赖项 camel-jackson
。
我正在尝试使用 camel-rest-dsl 构建 rest api。我尝试过多个提供商、spark-rest、jetty。但是当我使用 RestBindingMode.json 时它抛出编组异常,如果我删除 rest 绑定模式它工作正常。
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 setter 的简单 pojo class。
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]
检查您的项目中是否包含依赖项 camel-jackson
。