当异常消息转到camel中的deadLetterChannel时,如何将MultipartityBuilder转换为inputStream?

93ze6v8z  于 12个月前  发布在  Apache
关注(0)|答案(2)|浏览(191)

我正在使用MultipartityBuilder向服务器发送一个文件,当服务器没有响应或发生任何其他异常时,文件应该转到deadLetterChennal端点并保存为文件。一切正常,但deadLetterChennal显示转换问题。

from("direct:sendFileExchange")
 .errorHandler(deadLetterChannel("file:/home/r2/Desktop/ofBizFile/errorFinalServer")
            .asyncDelayedRedelivery()
            .maximumRedeliveries(3)
            .redeliveryDelay(1000)
            .retryAttemptedLogLevel(LoggingLevel.WARN))

            .startupOrder(3)
            .process(new ProcessorSetFileRequest())
            .setHeader(Exchange.HTTP_METHOD, constant("POST"))
            .setHeader(Exchange.HTTP_QUERY,constant("USERNAME=__&PASSWORD=_"))
            .to("https4://someAddress/uploadAndImportFileFromCSVFile?throwExceptionOnFailure=false")
            .to("stream:out");

字符串
deadLetter文件不在目录中。我可以在路由中设置类型转换器吗?
我得到的错误:

org.apache.camel.component.file.GenericFileOperationFailedException: Cannot store file: /home/r2/Desktop/ofBizFile/errorFinalServer/orders-02-01-2018.csv
Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type:
org.apache.http.entity.mime.MultipartFormEntity to the required type: java.io.InputStream with value org.apache.http.entity.mime.MultipartFormEntity@ddf0916]

vngu2lb8

vngu2lb81#

你可以这样做

from("direct:sendFileExchange")
            .errorHandler(deadLetterChannel("direct:savefile").useOriginalMessage()
                .asyncDelayedRedelivery()
                .maximumRedeliveries(3)
                .redeliveryDelay(1000)
                .retryAttemptedLogLevel(LoggingLevel.WARN))

            .startupOrder(3)
            .process(new ProcessorSetFileRequest())
            .setHeader(Exchange.HTTP_METHOD, constant("POST"))
            .setHeader(Exchange.HTTP_QUERY,constant("USERNAME=__&PASSWORD=_"))
            .to("https4://someAddress/uploadAndImportFileFromCSVFile?throwExceptionOnFailure=false")
            .to("stream:out");

 from("direct:savefile").process(exchange -> {
          MultipartFormEntity body = (MultipartFormEntity) exchange.getIn().getBody();
          exchange.getOut().setBody(body.getContent());
        }).to("file:/home/r2/Desktop/ofBizFile/errorFinalServer");

字符串

5anewei6

5anewei62#

从org.apache.hc.client5.http.entity.mime导入MultipartFormEntity

相关问题