首页 > 解决方案 > Apache Camel Multipart Netty Rest DSL 不适用于骆驼杰克逊依赖项

问题描述

我正在尝试使用 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]

标签: javaspring-bootapache-camel

解决方案


您的 JSON 有效负载中似乎有格式错误的数据 - 不知道您正在尝试做什么 - 解析器似乎正在处理它希望转换为数字但它包含破折号 (-) 的字段。

错误消息中没有问题:

“2018-05-09 21:24:48.743 调试 31824 --- [ntExecutorGroup] oacamel.processor.DefaultErrorHandler:ExchangeId:ID-GSHYD 上的(MessageId:ID-GSHYD-C02T823UG8WN-local-1525881280467-0-2)传递失败-C02T823UG8WN-local-1525881280467-0-1). 交付尝试:0 捕获:com.fasterxml.jackson.core.JsonParseException:数值中的意外字符('-'(代码 45)):预期数字(0-9 ) 跟随减号,用于有效数值 "


推荐阅读