开发者

Globally accessible property in EJB

开发者 https://www.devze.com 2023-04-06 16:58 出处:网络
I have a JavaEE application that needs to access a file in order to obtain certain informations about the installation.

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.


My suggestion is as follows:

  1. User JAX-WS with EJB 3 for enable to user upload the file through a WebService (You can provide the client).
  2. Store the content of the file in the JNDI using the menthod bind() of Context class. As I know the JNDI will be propagated across the cluster, but maybe you need to check the doc of your Java EE Application Server.

Hope it can be useful.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消