当异常消息转到camel中的deadLetterChannel时,如何将MultipartEntityBuilder转换为inputStream?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当异常消息转到camel中的deadLetterChannel时,如何将MultipartEntityBuilder转换为inputStream?相关的知识,希望对你有一定的参考价值。
我正在使用MultipartEntityBuilder向服务器发送文件当服务器没有响应或发生任何其他异常时,文件应该转到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]
答案
你可以做这样的事情
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");
以上是关于当异常消息转到camel中的deadLetterChannel时,如何将MultipartEntityBuilder转换为inputStream?的主要内容,如果未能解决你的问题,请参考以下文章