在没有 Spring Boot 的情况下使用 Apache Camel Route 进行表单数据上传的问题

问题描述 投票:0回答:1

Stack Overflow 社区您好,

我目前正在开发一个没有 Spring Boot 的 Apache Camel 项目,并且在创建处理表单数据的路由方面面临着挑战。我遇到了 JsonParseException 问题,我正在努力解决。

问题:

我正在尝试创建一个 Camel 路由来接收表单数据并将其上传到下游服务。但是,我遇到以下错误:

2023-12-11T15:51:33,380 错误 [XNIO-1 任务 6]:(ExchangeId 上的 MessageId:AFFA0D62E217B39-0000000000000002)传递失败:AFFA0D62E217B39-0000000000000002)。交付尝试后精疲力竭:1 捕获:com.fasterxml.jackson.core.JsonParseException:数值中出现意外字符(“-”(代码 45)):负号后面应有数字 (0-9),以获得有效数值。

班级:

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

有效负载类(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;
}

问题:

在这种情况下可能会导致 JsonParseException 错误,以及如何确保我的 Apache Camel 路由正确处理表单数据而不尝试将其解析为 JSON?

附加信息:

我正在尝试使用来自 Swagger 的路线。 我已验证 Content-Type 标头设置为 multipart/form-data。 我已经包含了用于生成不记名令牌的 TokenProcessor。 我很感激任何解决此问题的见解或建议。

谢谢!

forms apache routes apache-camel form-data
1个回答
0
投票

您可以关闭绑定模式

.绑定模式(RestBindingMode.auto)

.绑定模式(RestBindingMode.off)

© www.soinside.com 2019 - 2024. All rights reserved.