users@glassfish.java.net

Re: Globally accessible property in EJB

From: Noah White <emailnbw_at_gmail.com>
Date: Sat, 24 Sep 2011 18:07:51 -0400

You have two choices from an EJB:

1) Violate the spec and use the standard Java File APIs to access it from your EJB. Can be 'safe' if you understand what this means in terms of clustering, transactions etc. Since you are only doing read only access you should be OK.

2) Use a JCA adapter that supports file system access. You could write your own, try an open source one (I think there's one on source forge), or purchase one - I think oracle sells one for use with Glassfish oracle edition. Probably overkill for your situation.

You could also add a web app component to your project (Servlet) which does the file access since file io is permitted in that spec.

-Noah

On Sep 22, 2011, at 12:32 PM, Thiago Negri <evohunz_at_gmail.com> wrote:

> I have a JavaEE application that needs to access a file in order to
> obtain certain informations about the installation.
>
> This access is read-only, I do not need to change that file within the
> application, i.e. I do not need the "file" directly, just it's content
> (a byte array).
>
> There's a restriction on EJBs using the filesystem. I do understand
> the problems associated with it but I can't figure out a alternative
> solution to this.
>
> The file path should be configurable by the user, but there's no need
> to track changes to the file contents. Once loaded, it stays the same
> unless the user choose another file. So, I can't package it within the
> application archive.
>
> This file-based approach is a decision made long time ago by some
> legacy systems we have. There's no practical way to change it now,
> i.e. I need that my JavaEE application uses the file (at least once)
> to load it's content.
>
> Another restriction is that this file can not be persisted on the database.
>
> How should I do this without violating the EJB restriction of filesystem access?
>
> I thought about user uploading the file to the server and then
> persisting this information on the server. But how do I do this? This
> information should be globally accessible, including multiple
> instances of the server (e.g. in a cluster architecture).
>
> The user should configure this file once (not necessarily within the
> main application, it could be other app just to configure this). Even
> if the server restart, the file's content should still be accessible
> without any further configuration by the user.
>
> I'm using JavaEE 5 with EJB 3.0 specification on a GlassFish v2.1.1 server.
>
> Thanks, Thiago.
>
> * This question was posted on Stackoverflow too:
> http://stackoverflow.com/questions/7502980/globally-accessible-property-in-ejb