【发布时间】:2018-10-19 19:36:20
【问题描述】:
我正在尝试使用 netty4-http 读取 multipart/form-data。当我在我的项目中添加了camel-jackson和camel-xstream的依赖项时会出现问题,这会导致JsonParseException,因为我们正在读取multipart/form-data,所以理想情况下不应该发生这种情况。谁能帮我解决这个问题?
代码很简单,
rest().post("/hello")
.consumes("multipart/form-data")
.produces("application/json")
.to("direct:inbound");
from("direct:inbound")
.routeId("inbound_email")
.process(new PayloadParser())
.process(exchange -> System.out.println("In Body : " + exchange.getIn().getBody()))
.to("log:ie").end();
错误是这样的,
2018-05-09 21:24:48.708 DEBUG 31824 --- [ntExecutorGroup] o.a.c.component.netty4.NettyConsumer : Channel: [id: 0x198248e0, L:/127.0.0.1:8081 - R:/127.0.0.1:65379] received body: HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 9147, cap: 9147, components=3))
POST /hello HTTP/1.1
Host: localhost:8081
tenantid: 2a721265-bd98-45ec-abc3-f8e81c59e257
Content-Type: multipart/form-data; boundary=--------------------------269100026150164898107684
Content-Length: 9147
2018-05-09 21:24:48.743 DEBUG 31824 --- [ntExecutorGroup] o.a.camel.processor.DefaultErrorHandler : Failed delivery for (MessageId: ID-GSHYD-C02T823UG8WN-local-1525881280467-0-2 on ExchangeId: ID-GSHYD-C02T823UG8WN-local-1525881280467-0-1). On delivery attempt: 0 caught: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('-' (code 45)) in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value
at [Source: (ByteArrayInputStream); line: 1, column: 3]
【问题讨论】:
-
此异常可能来自输出编组,而不是来自输入。由于您添加了
.produces("application/json"),Camel 会自动尝试将其转换为 json(如果有可用的转换器)。如果您自己处理过编组,请删除produces()。或者你可以试试.bindingMode(RestBindingMode.off),但现在我不确定它是否优先于内容类型。 -
我调试了它,发现它实际上编组输入,还尝试删除
.produces("application/json")。正文以边界值----7234开头,并且无法将其转换为 Json 输出。使用RestBindingMode.off,我需要在任何地方指定marshall()和unmarshall()。在这种情况下,http content-type 属性不受支持,看起来像一个错误。 -
您使用的是哪个 Camel 版本?您是否有与 Camel Core 相同版本的组件?
-
camel.version = 2.21.1,所有组件共享同一个版本
标签: java spring-boot apache-camel