Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
I have created an RMI server and an applet that accesses the server.
When I run the applet from Netbeans, everything works great and I get the response back from the server. I have also created a non-applet client and that seems to work as well.
Even though the code was developed using Netbeans, I didn't use any of the GUI tools.
If I run it from my browser (either FireFox or IE), the applet loads, but when I push the button that calls the RMI method I get the following exception:
I have found lots of topics and tips on this, but can't really seem to get anything to work.
This is the first RMI server / applet combination I have written, so bear with me if it's an obvious problem.
I have verified that the server is running using the netstat command.
I am running Java version 1.6.0_13.
Also, I'm just trying to get this to work, that's why the getLargestPrime method is really rather useless....
I'm thinking SocketPermission exception indicates that the socket the client is attempting to connect to and the socket the server is listening on are different. I started the rmiregistry explicitly like 'start rmiregistry 1099' just to make sure it is using the expected port. After I started the RMI Server, I ran netstat and found this line 'TCP 192.168.0.100:1099 myPC:49695 ESTABLISHED'. The IP address here corresponds to my PCs IP address.
Using the appletviewer, I'm getting the same Exception as I'm getting from the browsers. Here is the Stacktrace:
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
Am I correct in my understanding that the RMI Server will use the same port as the RMI Registry?
As far as using a security manager, I didn't have much luck, however it could have been that I didn't fully understand how to use it. Also, I thought that the security manager was for applications and not for applets?
I was just reading some documentation that talked about hosting both the applet, server and html on a webserver. Do I need to be doing this? (Very new to all of this!) I realize if I want the world to see it, it needs to be hosted, but I just need it to work locally.
Are you running this on Windows or Unix? On windows if your IP address is say 192.168.0.100 then the server log should say "192.168.0.100:1099" but I it said "127.0.0.1:1099". Only unix can produce 127.0.0.1 without changing the networking hosts file.
Also how are you binding your remote object? I'm not sure if applet binds with RMI different from application or not because your applet code does not have some sort of lookup code for the RMI remote object that applications do.
For your server main method, try adding the createRegistry line and specifying the rmi protocol:
So..... I finally got this working with the original code I had.
The problem the entire time was the java.policy file in the jre/lib/security folder. I had done a search for a 'java.policy' file on my PC when I was trying to diagnose the issue, but apparently the default search in Vista doesn't look at non-indexed files, even if you say to look at all files.
I replaced the default with a 'grant all permissions' file and voila everything is working! Now, I just need to figure out how to do this in a more appropriate fashion as I really don't want to be giving all permissions to all java files...
Thanks K. Tsang for all the pointers and assistance - I learned quite a bit during the whole process!
Nice to hear that you got it working. Well you are running applet and applets are bound by that sandbox security issue. I guess you can play around with the policy file and set it to the most secured way (ie allowing least privilege).
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth