Sunand Padmanabhan
Sunand Padmanabhan

Reputation: 656

Apache Camel Multipart Netty Rest DSL not working with camel-jackson dependency

I am trying to read multipart/form-data using netty4-http. The problem occurs when I have added dependencies of camel-jackson and camel-xstream in my project which results in JsonParseException which ideally should not happen since we are reading multipart/form-data. Can anyone help me on this?

The code is simple,

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();

The error goes like this,

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]

Upvotes: 1

Views: 1087

Answers (1)

Greg Patnude
Greg Patnude

Reputation: 49

It appears that you have malformed data in your JSON payload -- without knowing for certain what you are trying to do -- it seems the parser is processing a field it expects to be cast as a number but it contains a dash (-).

It's all right there in the error message:

"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 "

Upvotes: 1

Related Questions