I'm currently working on an Apache Camel project without Spring Boot, and I'm facing challenges with creating a route that handles form data. I've encountered a JsonParseException issue that I'm struggling to resolve.
Problem:
I'm trying to create a Camel route that receives form data and uploads it to a downstream service. However, I'm encountering the following error:
2023-12-11T15:51:33,380 ERROR [XNIO-1 task-6] : Failed delivery for (MessageId: AFFA0D62E217B39-0000000000000002 on ExchangeId: AFFA0D62E217B39-0000000000000002). Exhausted after delivery attempt: 1 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.
Class:
public class PageUpload extends RouteBuilder {
@Override
public void configure() throws Exception {
String URL = "some link";
restConfiguration()
.component("servlet")
.bindingMode(RestBindingMode.auto)
.dataFormatProperty("prettyPrint", "true");
rest("/pageUpload")
.post()
.description("IG API to upload file in ImageRight")
.id("pageUpload")
.consumes("multipart/form-data")
.type(IRPageUploadRequestPayload.class)
.produces(APPLICATION_JSON)
.route()
.to(PAGE_UPLOAD)
.endRest();
from(PAGE_UPLOAD)
.routeId(this.getClass().getSimpleName())
.unmarshall().mimeMultipart()
.process(new TokenProcessor()) // token processor for bearer token gen
.toD(URL + BRIDGE_ENDPOINT)
.log("Azure Response Body: ${body}")
.end();
}
}
Payload Class (IRPageUploadRequestPayload):
@Getter
@Setter
public class IRPageUploadRequestPayload {
@JsonProperty("DocumentType")
private String DocumentType;
@JsonProperty("FileNumber")
private String FileNumber;
@JsonProperty("PolicyEffectiveDate")
private String PolicyEffectiveDate;
@JsonProperty("Content")
private File Content;
@JsonProperty("Description")
private String Description;
@JsonProperty("UserId")
private String UserId;
@JsonProperty("Username")
private String Username;
}
Question:
What could be causing the JsonParseException error in this scenario, and how can I ensure that my Apache Camel route correctly handles form data without attempting to parse it as JSON?
Additional Information:
I'm trying to consume the route from Swagger. I've verified that the Content-Type header is set to multipart/form-data. I've included the TokenProcessor for bearer token generation. I appreciate any insights or suggestions to resolve this issue.
Thank you!
You can turn off binding mode
.bindingMode(RestBindingMode.auto)
to
.bindingMode(RestBindingMode.off)