我正在尝试使用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]
最佳答案
看来您的JSON有效负载中的数据格式错误-不确定您要执行的操作是什么-似乎解析器正在处理一个期望将其强制转换为数字的字段,但其中包含一个破折号(-)。
在错误消息中就可以了:
“ 2018-05-09 21:24:48.743 DEBUG 31824 --- [ntExecutorGroup] oacamel.processor.DefaultErrorHandler:(MessageId:ID-GSHYD-C02T823UG8WN-local-1525881280467-0-2在ExchangeId:ID- GSHYD-C02T823UG8WN-local-1525881280467-0-1)。交付尝试:0捕获:com.fasterxml.jackson.core.JsonParseException:数字值中的意外字符('-'(代码45)):预期数字(0- 9)跟随减号,以获得有效的数值
”