chrisgresty
asked on
Using javax.comm in Java 1.2 applets
I am trying to get access to a PC's serial ports from a signed Java applet, using the Java 1.2.2 plug-in for IE5 and the Java Comms API v2.0. I have copied the win32com.dll, comm.jar and properties file to the appropriate places for the right runtime environment on the client PC, and granted all permissions to applets signed by me. In the applet, I use getCommPortIdentifiers to get an enumerator, then use this to obtain all available serial ports. However, when the applet is loaded, the following error is reported when I execute the hasMoreElements() method of the enumerator:
"Caught java.lang.NullPointerExcep tion: name can't be null while loading driver com.sun.comm.Win32Driver"
The same code works fine when run as an application. The security setup is definitely having an effect, since I also try to read from a local file - this fails as expected when the applet is unsigned (and the comm port stuff raises a different seurity-related error, too) but succeeds when the applet is signed. Perhaps I have missed something else though.
If anyone has any ideas on how to proceed, I would be glad to hear them.
Many thanks,
Chris
"Caught java.lang.NullPointerExcep
The same code works fine when run as an application. The security setup is definitely having an effect, since I also try to read from a local file - this fails as expected when the applet is unsigned (and the comm port stuff raises a different seurity-related error, too) but succeeds when the applet is signed. Perhaps I have missed something else though.
If anyone has any ideas on how to proceed, I would be glad to hear them.
Many thanks,
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Heyhey_'s comments gave me a handle on the problem, and led me to find the right answer - thanks!
thank you :)
ASKER
loadDriver(s1);
propfilename = new String(s1);
(s1 is the javax.comm.properties file)
As part of the driver initialisation started by loadDriver, the addPortName() method is called. If there is a security manager being used, it checks the delete permission on propfilename. Which hasn't been initialised yet. Whoops.
So initialisation fails whenever you use javax.comm with a security manager.
Switching the two lines around solves this problem. I can't see any negative implications of this yet...