Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Is this correct - EJBs are allowed to invoke Class.getResource

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this correct ?

EJBs are allowed to invoke Class.getResource in order to retrieve bundled resources (images, texts, properties, etc).
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that Class.getResource() returns an URL instance which then does its work through classes of the java.io package. Since the EJB spec does not allow bean providers to play with java.io classes for the sake of portability (EJB spec 24.1.2), it might make sense not to invoke Class.getResource() from your beans.

However, this topic has been discussed on the EJB-INTEREST mailing list and it comes out that it is indeed allowed to call Class.getResourceAsStream() from your beans. Check out the discussion at http://archives.java.sun.com/cgi-bin/wa?A2=ind0002&L=ejb-interest&F=&S=&P=59870
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, despite what the java.io.FilePermission API doc says, the EJB spec does disallow the use of the java.io package.

If you've got something like a properties file that you need to read, one possibility that springs to mind is to include it in your EAR file and use ResourceBundle, eg:


ResourceBundle rb = ResourceBundle.getBundle("some.pkg.myprop");


You can then get an enumeration of the keys and so be able to load the keys and values into a HashMap or similar.
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you've got something like a properties file that you need to read, one possibility that springs to mind is to include it in your EAR file and use ResourceBundle

Well, I guess that if you have a properties file or something similar the easiest way to go is to use environment entries (EJB spec 20.2) in my opinion. But as soon as you have something more "binarish" to retrieve, the getResourceAsStream() makes sense provided what has been said on the EJB-INTEREST mailing list. You can also store that binary stuff in a database as a BLOB or something which would comply with the programming restrictions.

Besides, the EJB spec is very fuzzy about the usage of java.io classes. It doesn't say much except that... (24.1.2)


...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.



This sounds pretty light to me
[ June 21, 2004: Message edited by: Valentin Crettaz ]
 
Do you pee on your compost? Does this tiny ad?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic