web start, security element, resource loading problem

H

Honglin Ye

Hi,
I need to feed a data file to a dataset in a web start application. The program runs fine on local.

In the jnlp,
(1) if set security element to j2ee-application-client-permissions,
I got "ava.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)"
(2) if set security element to all-permissions
I got "java.io.FileNotFoundException: C:\Documents and Settings\hye\Desktop\file:\C:\Program Files\Java Web
Start\.javaws\cache\http\Dbernoulli.aoc.nrao.edu\P80\DMe2e\DMcalib3\RMCalib3.jar!\calib3\src_parm_pos_datafile.txt (The filename, directory name, or volume label syntax is
incorrect)
It seems the class loader picked up an extra prefix "C:\Documents and Settings\hye\Desktop" for the file.

Any one know why? Thanks

Honglin Ye
 
H

Honglin Ye

Roedy said:
Try running Wassup to look at the system properties. That may give you
a clue.

See http://mindprod.com/jgloss/wassup.html
------------------------------------------------------------------------------------------

Thanks, Roedy, Here is the report from from wassup. I could not find theproblem there.
Also, the jar file is downloaded, but it did not add to the app manager, why?

Thanks again.
Honglin Ye


awt.toolkit = sun.awt.windows.WToolkit

file.encoding = Cp1252

file.encoding.pkg = sun.io

file.separator = \

java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment

java.awt.printerjob = sun.awt.windows.WPrinterJob

java.class.path = D:\PROGRA~1\Java\J2RE14~1.1\classes

java.class.version = 48.0

java.ext.dirs = D:\PROGRA~1\Java\J2RE14~1.1\lib\ext

java.home = D:\PROGRA~1\Java\J2RE14~1.1

java.io.tmpdir = C:\DOCUME~1\hye\LOCALS~1\Temp\

java.library.path = D:\Program Files\Netscape\Netscape;.;C:\WINNT\System32;C:\WINNT;d:\Program Files\Netscape\Netscape\;D:\oracle\ora81\bin;C:\Program
Files\Oracle\jre\1.1.7\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program Files\Common Files\Adaptec Shared\System;"D:\Program
Files\Hummingbird\Connectivity\7.00\Accessories\";D:\Program Files\Rational\common;D:\BorlandEnterpriseServer\bin;D:\oracle\ora81\bin;C:\Program
Files\Oracle\jre\1.1.7\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program Files\Common Files\Adaptec Shared\System;"D:\Program
Files\Hummingbird\Connectivity\7.00\Accessories\";D:\Program
Files\Rational\common;D:\BorlandEnterpriseServer\bin;d:\j2ee\bin;d:\j2sdk1.4.0\bin;D:\j2ee\jakarta-ant-1.3\bin;D:\BorlandEnterpriseServer\bin

java.specification.name = Java Platform API Specification

java.specification.vendor = Sun Microsystems Inc.

java.specification.version = 1.4

java.vendor = Sun Microsystems Inc.

java.vendor.url = http://java.sun.com/

java.vendor.url.bug = http://java.sun.com/cgi-bin/bugreport.cgi

java.version = 1.4.1

java.vm.info = mixed mode

java.vm.name = Java HotSpot(TM) Client VM

java.vm.specification.name = Java Virtual Machine Specification

java.vm.specification.vendor = Sun Microsystems Inc.

java.vm.specification.version = 1.0

java.vm.vendor = Sun Microsystems Inc.

java.vm.version = 1.4.1-b21

line.separator = [binary chars: 0x0d 0x0a i.e. CrLf, \r\n]

os.arch = x86

os.name = Windows 2000

os.version = 5.0

path.separator = ;

sun.boot.class.path =
D:\PROGRA~1\Java\J2RE14~1.1\lib\rt.jar;D:\PROGRA~1\Java\J2RE14~1.1\lib\i18n.jar;D:\PROGRA~1\Java\J2RE14~1.1\lib\sunrsasign.jar;D:\PROGRA~1\Java\J2RE14~1.1\lib\jsse.jar;D:\PROGRA~1\Java\J2RE14~1.1\lib\jce.jar;D:\PROGRA~1\Java\J2RE14~1.1\lib\charsets.jar;D:\PROGRA~1\Java\J2RE14~1.1\classes;D:\PROGRA~1\Java\J2RE14~1.1\lib\jaws.jar

sun.boot.library.path = D:\PROGRA~1\Java\J2RE14~1.1\bin

sun.io.unicode.encoding = UnicodeLittle

user.dir = d:\Program Files\Netscape\Netscape

user.home = C:\Documents and Settings\hye

user.language = en

user.name = hye

user.timezone = America/Denver
 
R

Roedy Green

It seems the class loader picked up an extra prefix "C:\Documents and Settings\hye\Desktop" for the file.
So it is looking in user.home.
user.home = C:\Documents and Settings\hye

I think the key may be dumping out
new File(".").getCanonicalPath().

To find out what the current directory is under various circumstances.

Just WHAT is it looking in that directory for?

My guess is some sort of properties file.
 
R

Roedy Green

java.io.FileNotFoundException: file:\C:\Program Files\Java Web Start\.javaws\cache\http\Dbernoulli.aoc.nrao.edu\P80\DMe2e\DMcalib3\RMCalib3.jar!\calib3\alias_datafile.txt

It is hard debugging without seeing the source code. I have to make a
lot of guesses. That is not a valid FILE name. That is an URL of a
member of a jar. I think you were trying to use file methods to read
a jar member. Zips are something like subdirectories, but are not
treated that way by Java. You need totally different methods to read
them.


See http://mindprod.com/fileio.html for how to read given an URL.
 
R

Roedy Green

private void readFromFile(URL aliasFileName) {
FileReader fileReader;
char data[] = new char[1024];

Please reread my earlier post. You cannot use FileReader to look
inside a Jar.
 
H

Honglin Ye

Roedy said:
private void readFromFile(URL aliasFileName) {
FileReader fileReader;
char data[] = new char[1024];


Please reread my earlier post. You cannot use FileReader to look
inside a Jar.

Did read it. Read from FileReader is to verify the point - it does
not work for the file that is in a jar file.

Again, the objective is to use borland TableDataSet classs. The
construct of that class takes a file name as argument. The question
is - what if that file is in a jar file? It seems that it behaves
just like the case of using FileReader.
 
R

Roedy Green

Did read it. Read from FileReader is to verify the point - it does
not work for the file that is in a jar file.

If you want to read an URL you have to do something like this.
Are you telling me this does NOT work on file:! Jar-type URLs?
If not, then you are going to have to use the ZIP classes.

// Read Locale-encoded chars ( usually 8 bit ) from a buffered URL.
// WARNING! unsigned Applets may only read from the server they were
loaded from.
// Sockets are a low level tool. For HTTP you will see all the headers
and length bytes.
// For HTTP normally you want the HttpURLConnection rather than
Socket.
// To copy/download files see
http://mindprod.com/products.html#FILETRANSFER.

// import java.io.*;
// import java.net.*;

// O P E N
// Generate an HTTP GET Command
URL url = new URL( "http://www.billabong.com:80/songs/lyrics.txt" );
URLConnection urlc = url.openConnection();
urlc.setAllowUserInteraction( false );
urlc.setDoInput( true );
urlc.setDoOutput( false );
urlc.setUseCaches( false );
urlc.connect();
long length = urlc.getContentLength(); // -1 if not available
// if you want to analyse the URL
String protocol = url.getProtocol(); // http
String host = url.getHost(); // www.billabong.com
String file = url.getFile(); // lyrics.txt
int port = url.getPort();// 80
InputStream is = urlc.getInputStream();
InputStreamReader eisr = new InputStreamReader( is,"Cp437" );
// Cp437 is IBM OEM.
// See "encoding" in the Java glossary for alternatives
// such as UnicodeBig for 16-bit, big-endian Unicode characters.
BufferedReader br = new BufferedReader( eisr, 4096 /* buffsize */ );

// R E A D
char[] ca = new char[1024];
int charsRead = br.read( ca );
String line;
// File being read had better have a terminal \n!
line = br.readLine();
// line == null means EOF
int aChar;
aChar = br.read();
// aChar == -1 means EOF

// C L O S E
br.close();
 
H

Honglin Ye

Roedy said:
Did read it. Read from FileReader is to verify the point - it does
not work for the file that is in a jar file.


If you want to read an URL you have to do something like this.
Are you telling me this does NOT work on file:! Jar-type URLs?
If not, then you are going to have to use the ZIP classes.

// Read Locale-encoded chars ( usually 8 bit ) from a buffered URL.
// WARNING! unsigned Applets may only read from the server they were
loaded from.
// Sockets are a low level tool. For HTTP you will see all the headers
and length bytes.
// For HTTP normally you want the HttpURLConnection rather than
Socket.
// To copy/download files see
http://mindprod.com/products.html#FILETRANSFER.

// import java.io.*;
// import java.net.*;

// O P E N
// Generate an HTTP GET Command
URL url = new URL( "http://www.billabong.com:80/songs/lyrics.txt" );
URLConnection urlc = url.openConnection();
urlc.setAllowUserInteraction( false );
urlc.setDoInput( true );
urlc.setDoOutput( false );
urlc.setUseCaches( false );
urlc.connect();
long length = urlc.getContentLength(); // -1 if not available
// if you want to analyse the URL
String protocol = url.getProtocol(); // http
String host = url.getHost(); // www.billabong.com
String file = url.getFile(); // lyrics.txt
int port = url.getPort();// 80
InputStream is = urlc.getInputStream();
InputStreamReader eisr = new InputStreamReader( is,"Cp437" );
// Cp437 is IBM OEM.
// See "encoding" in the Java glossary for alternatives
// such as UnicodeBig for 16-bit, big-endian Unicode characters.
BufferedReader br = new BufferedReader( eisr, 4096 /* buffsize */ );

// R E A D
char[] ca = new char[1024];
int charsRead = br.read( ca );
String line;
// File being read had better have a terminal \n!
line = br.readLine();
// line == null means EOF
int aChar;
aChar = br.read();
// aChar == -1 means EOF

// C L O S E
br.close();

I have no problem read from stream which connected in a file in a jar.
You can look at my code I posted on 8/21, 12:09pm. I have a method there
called readFromStream. That method works even it is not the same as you
posted here. Infact, we do not necessarily need URLConnnection, the
following line is sufficient to get the stream. It works.
-----------
InputStream is = this.getClass().getClassLoader().getResourceAsStream("calib3/alias_datafile.txt");
-----------

The situation is this:
TableDataSet takes file, but not file in a jar.
read from filereader does not work for file in a jar.
read from stream works well for file in a jar.
TableDataSet does not take stream directly.
How to make TableDataSet to work if the file is in a jar?
 
H

Honglin Ye

The situation is this:
TableDataSet takes file, but not file in a jar.
read from filereader does not work for file in a jar.
read from stream works well for file in a jar.
TableDataSet does not take stream directly.
How to make TableDataSet to work if the file is in a jar?

It turns out extremly easy. Just 3 lines of code!

private TextDataFile aliasDataFile = new TextDataFile();
public TableDataSet aliasTableDataSet = new TableDataSet();

InputStream dataStream = this.getClass().getClassLoader().getResourceAsStream("calib3/alias_datafile.txt");
aliasDataFile.load(aliasTableDataSet, dataStream, null);

Thanks.

Honglin Ye
 
R

Roedy Green

TableDataSet takes file, but not file in a jar.
read from filereader does not work for file in a jar.
read from stream works well for file in a jar.
TableDataSet does not take stream directly.
How to make TableDataSet to work if the file is in a jar?

Perhaps that you problem is how do you get an InputStream but you
want in Reader. How do you convert?

Again the fileIO amanunesis is your friend.
http://mindprod.com/jgloss/fileio.html

The technique I showed earlier works for any URL. The getResource
technique works only for stuff on the resource path. Obviously
getResource or getResourceAsStream is simpler if you can make that
assumption.



InputStreamReader eisr = new InputStreamReader( inputStream,"Cp437" );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top