【问题标题】:Camel-FTP timing out and creating 0 byte filesCamel-FTP 超时并创建 0 字节文件
【发布时间】:2013-08-26 17:20:49
【问题描述】:

我正在开发一个 servlet,我们在 DB 中存储了一个 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 状态 500 - 请求处理失败;嵌套异常是 java.lang.RuntimeException: org.apache.camel.CamelExecutionException: 在交换执行期间发生异常:Exchange[消息:[Body is file based: PATH\FILE.tmp]]

在我的 servlet 日志中我看到:

org.apache.commons.net.ftp.FTPConnectionClosedException: 连接关闭且没有提示。

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

【问题讨论】:

    标签: java servlets ftp apache-camel


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-03-10
      • 1970-01-01
      • 2012-12-11
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      相关资源
      最近更新 更多