gpt4 book ai didi

java - Camel-FTP 超时并创建 0 字节文件

转载 作者:行者123 更新时间:2023-12-02 06:47:39 25 4
gpt4 key购买 nike

我正在开发一个 servlet,其中我们有一个存储在数据库中的 FTP URI。用户将选择一个 FTP URI(通过“友好”名称),然后从站点将文件上传到它。我想使用 Camel 进行实际上传,因为我们存储的 URI 之前已在 Camel 端点中使用。

以下是使用文件发送消息的代码:

public void uploadValidFiles(List<ValidatedFile> files, UploadLocationInfo info)
{
final String uri = info.getUri();
RouteBuilder rb = new RouteBuilder() {
public void configure() {
from("direct:start").to(uri);
}
};

CamelContext ctx = new DefaultCamelContext();

try {
ctx.addRoutes(rb);
ctx.start();
ProducerTemplate prod = new DefaultProducerTemplate(ctx);
prod.start();
for(ValidatedFile file : files)
{
File temp = File.createTempFile(file.getFilename(), ".tmp");
//Transfer MultiPartFile to File
file.getFile().transferTo(temp);
prod.sendBodyAndHeader("direct:start", temp, "CamelFileName", file.getFilename());
}
prod.stop();
ctx.stop();
}
catch (CamelExecutionException ce)
{
System.out.println("Problem!");
throw new RuntimeException(ce);
}
}

我正在测试的 URI 是:ftp://user@ftp.domain.com/folder?password=s3cr3t

在网站上,我选择了 URI 和文件,点击“上传...”,然后它就挂起了。最终我得到了一个带有文本的 HTTP500:

HTTP Status 500 - Request processing failed; nested exception is java.lang.RuntimeException: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: [Body is file based: PATH\FILE.tmp]]

在我的 servlet 日志中我看到:

org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.

FTP 上正在创建一个文件,其名称与上传的文件相同,但大小为 0

最佳答案

我通过将passiveMode=true 和binary=true 添加到FTP URI 解决了这个问题

关于java - Camel-FTP 超时并创建 0 字节文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18449523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com