Apache camel 无法从 InputStreamCache 编组到 JSON
Apache camel cannot marshal to JSON from InputStreamCache
在 Apache Camel 中,我公开了一个 REST 服务,获取其输入以调用 SOAP 服务,然后我想将 SOAP 响应编组到 JSON。我的 RouteBuilder 大致如下所示:
rest("/api")
.get("/client/{id}")
.to("direct:getClient");
from("direct:getClient")
.log(LoggingLevel.INFO, "Getting client with id ${id}")
.process(new GetClientProcessor())
.marshal().jaxb()
.to("spring-ws:http://localhost:9000/searchClient?soapAction=search")
.process(new ClientProcessor())
.marshal().json(JsonLibrary.Jackson);
我在将结果编组到 JSON 时收到以下错误:
com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.apache.camel.converter.stream.InputStreamCache and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:275)
at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1110)
at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1135)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
...
我知道为什么会这样,因为我默认打开了流缓存。但是,我不知道如何在不关闭 流缓存的情况下解决此问题。
我已经搜索过 Camel 文档、邮件列表和论坛,但到目前为止我还没有找到有用的信息。
我终于解决了。问题与描述的路由无关,而是全局其余配置:
RestConfiguration restConfiguration = new RestConfiguration();
restConfiguration.setComponent("servlet");
restConfiguration.setBindingMode(RestConfiguration.RestBindingMode.json);
restConfiguration.setHost("localhost");
restConfiguration.setPort(serverPort);
camelContext.setRestConfiguration(restConfiguration);
第三行,设置绑定模式,是不必要的,因为我明确说明了我想映射到 JSON 的时间以及我使用的框架。删除此行后,一切都很好用。
此刻我不完全知道这如何或为什么解决了我的问题,但我很高兴它解决了 ;)
在 Apache Camel 中,我公开了一个 REST 服务,获取其输入以调用 SOAP 服务,然后我想将 SOAP 响应编组到 JSON。我的 RouteBuilder 大致如下所示:
rest("/api")
.get("/client/{id}")
.to("direct:getClient");
from("direct:getClient")
.log(LoggingLevel.INFO, "Getting client with id ${id}")
.process(new GetClientProcessor())
.marshal().jaxb()
.to("spring-ws:http://localhost:9000/searchClient?soapAction=search")
.process(new ClientProcessor())
.marshal().json(JsonLibrary.Jackson);
我在将结果编组到 JSON 时收到以下错误:
com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.apache.camel.converter.stream.InputStreamCache and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:275)
at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1110)
at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1135)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
...
我知道为什么会这样,因为我默认打开了流缓存。但是,我不知道如何在不关闭 流缓存的情况下解决此问题。
我已经搜索过 Camel 文档、邮件列表和论坛,但到目前为止我还没有找到有用的信息。
我终于解决了。问题与描述的路由无关,而是全局其余配置:
RestConfiguration restConfiguration = new RestConfiguration();
restConfiguration.setComponent("servlet");
restConfiguration.setBindingMode(RestConfiguration.RestBindingMode.json);
restConfiguration.setHost("localhost");
restConfiguration.setPort(serverPort);
camelContext.setRestConfiguration(restConfiguration);
第三行,设置绑定模式,是不必要的,因为我明确说明了我想映射到 JSON 的时间以及我使用的框架。删除此行后,一切都很好用。
此刻我不完全知道这如何或为什么解决了我的问题,但我很高兴它解决了 ;)