FileIO from an stateless session bean

為{幸葍}努か 提交于 2020-01-04 05:35:34

问题


I need to read and write xml files to disk from a stateless session bean running in JBoss. What is the preferred way of doing this?

Right now we are accessing the file system using the java.io classes.

I found a simple file system RAR example and have got that working but it may be more buggy than just using java.io directly.


回答1:


If you check that Programming Restrictions section of the EJB Spec you'll find the following:

An enterprise bean must not use the java.io package to attempt to access files and directories in the file system.

If you can find a better, possibly secure and more importantly, transactional way of doing it, please reconsider. We have a system that stores PDF documents as blobs in a database and then serves them to the users by email or servlet.

The JBoss JCA based FSManagedConnectionFactory isn't too bad. It is JNDI based and likely to work in more instances than just hacking around java.io




回答2:


If you properly close the file and clean up, you can use anything you want. I would use an XML parser to read or write XML files, though, it is safer.




回答3:


The complicated way is to write a ejb client that reads the file, or set up an xml datasource somehow. In reality, nothing bad will happen if you use java.io in the session bean. However, if you are using clustering and/or will migrate the servers, then you have to take care of where your beans are running and which one will be invoked.

The simplest "batch" solutions is to take one machine out of the cluster and run the "batch" applications there.



来源:https://stackoverflow.com/questions/917795/fileio-from-an-stateless-session-bean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!