[OpenMap Users] BinaryFile and JNLPClassLoader issue

From: Carsten Ø. Madsen <com_at_navicon.dk>
Date: Tue, 08 Jun 2010 14:20:00 +0200

Hello

I have an issue using the BinaryFile class to load shape files in signed
jar files under JNLP. Most of the time it works but sometimes I get a
JNLP security warning about mixing signed and unsigned code (see [1]).

The BinaryFile class does:

                 url = Thread.currentThread()
                         .getContextClassLoader()
                         .getResource(name);

and it then tries to decompose the url to read the contents. However [2]
says that the correct way to access a resource under JNLP is to use
getResourceAsStream:

"Access the /ClassLoader/ being used with:

    ClassLoader cl = Thread.getCurrent().getContextClassLoader();
       

/ClassLoader.getResource()/ returns a URL, but any code that assumes the
URL is a JarURL to a FileURL, and then tries to decompose that FileURL
to find the underlying file path will fail. The correct way to access
resources is to use /getResourceAsStream()/ which will return the
correct content whatever type of /ClassLoader/ is used to access the
resource. If the resource is already cached, the contents of the
resource will be returned from the cache directly, so there won't be
extra network connections to the resource itself."

So should BinaryFile have a check to see of the class loader is a JNLP
loader and then use getResourceAsStream?

I'm guessing that the BinaryFile fails (provokes security warning) when
getResource returns something that is cached.

[1] http://java.sun.com/javase/6/docs/technotes/guides/jweb/mixed_code.html

[2]
http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#ClassLoader_and_Resources

BR
Carsten





--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Tue Jun 08 2010 - 08:53:12 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:09 EDT