java.io in EJBs - WTF?!?!

So, the current project I am working on will be running inside of a J2EE container, behind some Message Driven Beans (MDBs). The requirement is that our application must grab some files from various locations… FTP servers, Content Management systems, file system shares, etc…

So, when the team member that is working on these components said that we cannot us the java.io package inside an EJB, my initial reaction was “BS! who says that?!?!”. At which point I was pointed at this:

From page 511, EJB 3.0 Proposed Final Draft - ejbcore:

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

The file system APIs are not well-suited for business components to access data. Business components
should use a resource manager API, such as JDBC, to store data.

  • An enterprise bean must not attempt to listen on a socket, accept connections on a socket, or use a socket for multicast.

The EJB architecture allows an enterprise bean instance to be a network socket client, but it does not
allow it to be a network server. Allowing the instance to become a network server would conflict with
the basic function of the enterprise bean— to serve the EJB clients.

WTF is up with that!?!?!

I can understand the underlying concepts… managing resources can be hard, and J2EE is all about pushing the management of resources to the container.  Thats fine to an extent, but I have some issues with the above statements:

  1. It is too specific on the technology, but vague on the reason.  I’m sorry, but just because a technology is not “well suited” does not mean I “must not use it”.  There are situations where I may need to use it, but now it is a Taboo.  Doing a quick google indicates that there are a number of potential reasons, most revolving around blocking versus non-blocking operations, where blocking operations, such as reading from/writing to a disk).  I feel that as long as you understand and are prepared for the consequences, this should not be a problem.
  2. It is vague overall.  So, can I use this inside of a component, as long as it is not a “Business Component”?  And what does that really mean?  Can I use System.out?  What about Logging?  They use Java.io… are they OK?
  3. It has not been updated in EJB 3.0.  If this is such a problem, why has it not been updated to take into account java.nio?

I’m confused.  I would love to hear what other people think about this, as it does not make any sense to me.  Can anybody answer these questions?

I know for me, I couldn’t care less that the spec says don’t use java.io.  If you know how to use it, and are aware of what the issues are with using it, than use it.  Unfortunately, there is a political cloud over this.  There are people that believe that the spec cannot possibly be wrong.

If we do use java.io in our system, it will be inside of a component, not an EJB directly.  And if we have to we can always use java.nio :)

In the end, I feel that the spec is just poorly worded, and is in dire need of an update.