File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes Java RMI Client AccessControlException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Java RMI Client AccessControlException" Watch "Java RMI Client AccessControlException" New topic
Author

Java RMI Client AccessControlException

Alastair Bryce
Greenhorn

Joined: Mar 24, 2006
Posts: 5
Hi I've had some problems trying to get RMI working and was wondering if anyone can help me? I've tried

implementing the client/server code two different ways - one way using a Registry object to bind my remote object

and one using the Naming.rebind()/Naming.lookup() methods (my current code, which I'll supply in a sec).

I noticed when I was using the Registry object to bind the DriverObject I was getting errors about stuff not being

serializable when trying to run the client. Is it talking about the objects that the DriverObject uses?

I'm running all of this on a windows machine using the following commands (the code is located in the folder

C:\pid):


When running the ClientObject I get the following error:


I've taken some of the code out of the driver object (the getters/setters are pretty much the same) for this post.

RemoteEvent.java


DriverObject.java


ClientObject.java


Thanks .
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

The exception that you posted is due to some kind of problem with your security/permissions setup...

Which is strange, because you're including a policy file in your command line when you run the client - any chance that the policy.all file isn't where you think it is? Or that it has some sort of formatting problem?

Is it a "AllPermissions" policy file, or are you configuring specific permissions?


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Alastair Bryce
Greenhorn

Joined: Mar 24, 2006
Posts: 5
Thanks for the reply Nate, I haven't had a good chance to have a look at the code since friday, but here are a few exta remarks which might help figuring out what the problem is.

I'm not really all that familiar with RMi, so still not exactly sure how to implement it exactly - the tutorial I found online uses the security manager and then at the end almost as a side note says "oh by the way - you can set the policies like this..." (not a quote and grossly reduced - but that's pretty much what I felt about it's coverage). I assumed that policy.all was a default mechanisim for granting all policies to the port (which I figured would be extremely unsecure, but would at-least do for now). How do you setup a policy file to get things working?

The other thing is I'm using localhost -so both server and client classes are being run on the same computer - I THINK that you can get access problems when doing so, but I'm trying to get things working first in an isolated computer right now when I don't have access to a network. I should imagine it should be possible to run both server and client code on the same system if you set things up correctly - but like I said I'm fairly new to this stuff, so I'm stumbling around in the dark a little right now.

I'll try working on it some more and see what I can come up with - more help definetly would be appreciated though...

Cheers
Alastair Bryce
Greenhorn

Joined: Mar 24, 2006
Posts: 5
Ok, fixed the security exception problem . Was just a .java.policy problem - now the problem I'm getting is a "java.rmi.NotBoundException: RemotePID" which I find a bit confusing - the RMIRegistry is definetly running and hasn't crashed plus the server object (DriverObject in my case) is running properly (checking my CPU usage it goes from around about 2-5% to 50% - the program is pretty cpu intensive, so the DriverObject definetly is running).

My only conclusions I can come up with are either that the DriverObject isn't advertising itself correctly or the ClientObject isn't finding the advertised object for some reason.

Any ideas people?

I've also tried the alternate way of advertising and connecting to remote objects:

DriverObject


ClientObject

It's pretty unsecure, but currently my .java.policy file in the root folder of my user profile looks like:
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

OK - great that you fixed the policy file stuff.

Strange error you are getting now - are you getting the "Advertising completed" message in your server? Are you sure you haven't added some error handling code in the catch() in the server's main() that could "ignore" an error by doing nothing? Since you haven't mentioned codebase yet, and it's the next common problem people usually run into now - I'm wondering if you're really getting an error due to codebase not being set, not succeeding in binding to the registry, and something is causing the error to be "eaten"...

codebase is kind of like classpath, but used for remote programs. If you really have the classpath set to nothing when running rmiregistry, then the initial bind to the registry will throw an exception, because the registry cannot find/load your stub class.

You would do something like this to set the codebase -


Also, in your client - before you do the lookup(), try to do a registry.list() - this returns an array of Strings, and you can print them out to see if the object you're looking for is there, or if there's been a slight misspelling in the name you're looking for.
Alastair Bryce
Greenhorn

Joined: Mar 24, 2006
Posts: 5
Thanks for the reply Nathan, yeah, the DriverObject is outputting the expected text when I run it indicating that if there is a problem it's gone unnoticed.

I'll try executing the java files with the flags you mentioned to see if I can get any further that way.

I was thinking about using the client code with some JSP pages I was creating, so I'm not sure how that will go - am I right in thinking that I could use the ClientObject as a javabean seeing as it's simply a load of getters and setters (ok, it has a main method too right now for debugging purposes). Was also thinking about having a java aplet load on a webpage to display a graph.

You know how easy I could do considering I need to setup classpaths and code bases too?

By the way, do I need to load the security manager when I create the remote object the way I mentioned above? the code I've seen before implementing things that way didn't.

Cheers again for your help.
Alastair Bryce
Greenhorn

Joined: Mar 24, 2006
Posts: 5
Recompiled the source code after making the change you suggested to the ClientObject - still got problems. Here is a screen dump from both:

DriverObject


ClientObject


So it looks like the DriverObject is doing what it's supposed to (though technically it might not be advertising right and notflagging that fact). The "[Ljava.lang.String;@122cdb6" outputted by the ClientObject appeared (I think anyways) once I added "System.out.println(registry.list());" right after using the getRegistry() method - is that the problem or is it just println isn't the thing to do here?

Thanks.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You are getting "[Ljava.lang.String;@122cdb6" because it's just printing out the ".toString()" for the array - you need to print the contents of the array - something more like -


In the output for the server, I noticed that you didn't mention seeing the string "Advertising completed." - this string is printed *after* the actual registry bind in your code above, and the last line you mention is before it. If this is the output from your server - it appears that something is preventing your server from getting to the actual bind - and that the error from the client is correct.

edited -
Found it...

[ March 30, 2006: Message edited by: Nathan Pruett ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java RMI Client AccessControlException