简体   繁体   English

JBoss中带有EJB3的FTP客户端

[英]FTP Client with EJB3 in JBoss

I have a Stateless Session Bean (in JBOSS container) that does download a file from remote FTP server using org.apache.commons.net.ftp.FTPClient. 我有一个无状态会话Bean(位于JBOSS容器中),它确实使用org.apache.commons.net.ftp.FTPClient从远程FTP服务器下载文件。 It then temporarily stores the file in local System tmp directory (java.io.tmpdir) and processes the content mainly by adding it into a Database using Hibernate. 然后,它将文件临时存储在本地System tmp目录(java.io.tmpdir)中,并主要通过使用Hibernate将其添加到数据库中来处理内容。

Now EJB Specifications do tell me not to use java.io.File, java.io.FileInputStream and so on. 现在,EJB规范确实告诉我不要使用java.io.File,java.io.FileInputStream等。 Basically not to do any "direct" filesystem access at all. 基本上根本不执行任何“直接”文件系统访问。

Now how am I supposed to do my task ? 现在我应该怎么做? Does anyone have a hint, link, example ? 有没有人提供提示,链接和示例?

Thank you in advance 先感谢您

mostart 最艺术的

How about having your own local/remote ftp server for storing the incoming files? 如何拥有自己的本地/远程ftp服务器来存储传入文件? Then you just use the FTPClient and not access file system directly. 然后,您仅使用FTPClient而不直接访问文件系统。

Ok, found out I could refactor the modul to just operate on the download Stream directly rather than temporarily saving it in the file system. 好的,发现我可以将模块重构为直接在下载Stream上运行,而不是暂时将其保存在文件系统中。

thanks for your hints.. 谢谢你的提示。

You should not access the local file system to store any data which you would use later in your application. 您不应访问本地文件系统来存储以后将在应用程序中使用的任何数据。 If your application resides on a cluster then the locally stored files won't be accessible from each cluster member, that's why the documentation doesn't recommend to use java.io at all. 如果您的应用程序驻留在集群上,则每个集群成员都将无法访问本地存储的文件,这就是为什么文档完全不建议使用java.io的原因。 That's the easiest way to avoid such inconsistency. 这是避免这种不一致的最简单方法。

However, if you need to work with temporary files only, which you can delete before the end of your bean's life-cycle, then you can use java.io without any worry. 但是,如果只需要使用临时文件(可以在bean的生命周期结束前将其删除),则可以使用java.io而不用担心。 The point is that, don't store locally anything which you want access from your app later. 关键是,不要在本地存储以后要从应用程序访问的任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM