tags:

views:

259

answers:

3

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  A: 

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.

cdonner
+2  A: 

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

sal
A: 

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.

KarlP