Rickard �berg wrote:

> > Resource access with Class.getResource() and
> > Class.getResourceAsStream() are allowed by the specification. They go
> > through the ClassLoader and the EJB server can easily handle this.
>
> Unfortunately this is incorrect. getResource() is about getting URL's to
> the resource, and getResourceAsStream simply calls
> getResource().openStream() (or something like that). Underneath this the
> JDK uses FileStreams, so it doesn't work because of the security
> restrictions.

You have the right of reading all files located in the same directory (or in
subdirectory) of the Bean class. You can look at Javadoc for
java.io.FilePermission, the last sentence addresses this.

Java class loaders also implement this logic. Calling the getResource() on a
file that is located else where returns "null" even if it is in the classpath
of your application. Calling getResourceAsStream() on that file throws a null
pointer exception (it might just do getResource().openStream() like Rickard
points out above.
<security>
I hope implementors of custom class loader respects this logic.
</security>

When packaging the Bean and accessed files in the same .jar, use
getResourceAsStream() or new File().toURL().openStream() to access the file. If
the bean is not packaged into a .jar, also use new FileInputStream(file_name)
to access the file. No security exception or null pointer exception will occur.

Using getResourceAsStream() is better than using new FileInputStream() because
your classes (or .jar) could not be directly located under the jre-execution
dir ("user.dir") but somewhere in the classpath instead. So for
getResourceAsStream, the class loader searches the resource for you.

Regards.
--
Francis Pouatcha

MATHEMA Software GmbH
http://www.mathema.de

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to