RMI error when running client file

Hi everyone,

I have created some java files that I would like to run. First I compiled and ran it using Eclipse. That worked perfect. Now, I want to do the same thing using Netbeans because I need to create a web application and I thought it would be easier to do that with the Netbeans IDE. The (remote) server is up and running, but when I run the client file I get this error:

Nov 15, 2005 1:31:33 PM org.apache.catalina.core.ApplicationContext log

INFO: Manager: list: Listing contexts for virtual host 'localhost'

Nov 15, 2005 1:31:34 PM org.apache.catalina.core.ApplicationContext log

INFO: Manager: list: Listing contexts for virtual host 'localhost'

Nov 15, 2005 1:31:35 PM org.apache.catalina.core.ApplicationContext log

INFO: Manager: restart: Reloading web application at '/HQWebApplication'

Nov 15, 2005 1:31:35 PM org.apache.catalina.core.StandardContext reload

INFO: Reloading this Context has started

Nov 15, 2005 1:31:59 PM org.apache.catalina.core.ApplicationContext log

INFO: Manager: list: Listing contexts for virtual host 'localhost'

Nov 15, 2005 1:31:59 PM org.apache.catalina.core.ApplicationContext log

INFO: Manager: list: Listing contexts for virtual host 'localhost'

java.rmi.UnmarshalException: error unmarshalling return; nested exception is:

java.lang.ClassNotFoundException: webremotedisplay.application.service.RemoteCommunication_Stub (no security manager: RMI class loader disabled)

at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)

at java.rmi.Naming.lookup(Naming.java:84)

at webremotedisplay.application.service.CommunicationClient.getStub(CommunicationClient.java:27)

at webremotedisplay.application.service.RemoteCommunicationProxy.<init>(RemoteCommunicationProxy.java:26)

at login.LoginHandler.allowUser(LoginHandler.java:82)

at login.LoginHandler.doPost(LoginHandler.java:54)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)

at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)

at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)

at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

at java.lang.Thread.run(Thread.java:595)

Caused by: java.lang.ClassNotFoundException: webremotedisplay.application.service.RemoteCommunication_Stub (no security manager: RMI class loader disabled)

at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:371)

at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)

at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)

at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)

at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)

at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1538)

at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)

... 25 more

failed

Can anyone tell me why it doesn't work anymore?

Thanks for your help!!!

E_J

[4760 byte] By [El_Javaistaa] at [2007-10-2 5:14:15]
# 1
> java.rmi.UnmarshalException: error unmarshalling> return; nested exception is: > java.lang.ClassNotFoundException:> webremotedisplay.application.service.RemoteCommunication_Stub (no security manager: RMI class loader disabled)
ejpa at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...
# 2
Hi,Might be due to a missing --> System.setSecurityManager(new RMISecurityManager());in the RMI code.This should solve your problem.Regards,Pawan.
Pawan_Singha at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...
# 3

Pawan, thank you very much for your answer. I had already tried your solution before, but when I enter that line of code I get a connection exception, so I don't know whether that helps me or not... Maybe there's something else I have to do? Still don't know why it's working in Eclipse (as a simple server-client application), and giving me errors in Netbeans (when the application is almost the same, but in this case the client files are put in a web application file)

this is the exception I get now:

Exception in thread "main" java.security.AccessControlException: access denied (java.net.SocketPermission 192.168.2.139:5555 connect,resolve)

at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)

at java.security.AccessController.checkPermission(AccessController.java:427)

at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)

at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)

at java.net.Socket.connect(Socket.java:501)

at java.net.Socket.connect(Socket.java:457)

at java.net.Socket.<init>(Socket.java:365)

at java.net.Socket.<init>(Socket.java:178)

at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)

at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)

at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:569)

at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)

at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)

at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:306)

at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)

at java.rmi.Naming.lookup(Naming.java:84)

at webremotedisplay.application.service.CommunicationClient.getStub(CommunicationClient.java:30)

at webremotedisplay.application.service.RemoteCommunicationProxy.<init>(RemoteCommunicationProxy.java:27)

at webremotedisplay.application.service.RemoteCommunicationProxy.main(RemoteCommunicationProxy.java:571)

Java Result: 1

Still appreciate any help !!

E_J

El_Javaistaa at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...
# 4

Hi E_j,

I can see a progress there. What i mean is that you are on the right track.

This exception is about the policy that JVM is following. As, you know Java security model uses policy files to decide how libral should it be in it's behaviour.

Coming to the specific exception, it looks like there is no connect permissin to port 5555 on Host 192.168.2.139.

We would need following grant permission in ".policy" file.

grant {

permission java.net.SocketPermission "192.168.2.139:1024-", "accept, connect, listen, resolve";

};

Hope this would help.

Regards,

Pawan.

Pawan_Singha at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...
# 5

hi Pawan,

Thanks again for your help! Unfortunately, I still get some errors that are similar to the first one. However, I have modified the java.policy file in the security folder of the JRE/lib dir on the client side. In that file I have witten the code you gave me. To be sure I haven't forgotten anything, I have done the same thing on the server side, implementing my own IP-address instead of the server's.

As I said before, I had also changed the client file itself.

String ipaddress = conf.getIpaddress();

try{

[b]System.setSecurityManager(new RMISecurityManager());[/b]

stub = (RemoteCommunicationInterface)Naming.lookup("rmi://" + ipaddress + ":5555/RemoteCommunicationInterface"); /*lookup in the registry*/

}

catch(MalformedURLException mue){

mue.printStackTrace();

}

catch(NotBoundException nbe){

nbe.printStackTrace();

}

catch(RemoteException re){

re.printStackTrace();

}

This is the error I got now:

java.rmi.UnmarshalException: error unmarshalling return; nested exception is:

java.lang.ClassNotFoundException: webremotedisplay.application.service.RemoteCommunication_Stub

at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)

at java.rmi.Naming.lookup(Naming.java:84)

at webremotedisplay.application.service.CommunicationClient.getStub(CommunicationClient.java:30)

at webremotedisplay.application.service.RemoteCommunicationProxy.<init>(RemoteCommunicationProxy.java:27)

at webremotedisplay.application.service.RemoteCommunicationProxy.main(RemoteCommunicationProxy.java:571)

Caused by: java.lang.ClassNotFoundException: webremotedisplay.application.service.RemoteCommunication_Stub

at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:242)

at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:430)

at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)

at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)

at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)

at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)

at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1538)

at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)

... 5 more

What may I have forgotten? Thanks in advance!!!

E_J

El_Javaistaa at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...
# 6

Hi,

I am sorry, i have few queries regarding your code.

1. As per you code you are looking up on 5555. Is RMI Registry running on this port?

lookup("rmi://" + ipaddress + ":5555/RemoteCommunicationInterface");

2. Is you RMI Server and/or RMI Client, sitting behind a firewall?

3. Are you using "RMI Codebase" property?

This would give me a better understanding of the issue.

And, i think we are not far from the resolution.

Pawan.

Pawan_Singha at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...
# 7

Hi Pawan,

To give you an answer for your questions:

1. Yes, as you can see in the following line of code (server-side)

Registry reg = LocateRegistry.createRegistry(5555);

2. No, there's no firewall.

3. No, I haven't used that property. Could that be the reason why it doesn't work? It's something new to me. Where do I have to use that? Why can it be useful? I hope that this will bring the solution.

Thanks a lot!

E_J

El_Javaistaa at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...
# 8

Hi,

In responce to your query regarding CodeBase, please read text in following link.

http://java.sun.com/j2se/1.4.2/docs/guide/rmi/codebase.html

Hope it is a good text to get a basic idea.

Also, please make sure :

1. Stub and Skeleton files generated are well included in CLASSPATH variable, on their respective sides.

2. These files have a Read permission for user running RMI Server / Client. (if you are working on Unix.)

Pawan.

Pawan_Singha at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...
# 9

Hi,

In responce to your query regarding CodeBase, please read text in following link.

http://java.sun.com/j2se/1.4.2/docs/guide/rmi/codebase.html

Hope it is a good text to get a basic idea.

Also, please make sure :

1. Stub and Skeleton files generated are well included in CLASSPATH variable, on their respective sides.

2. These files have a Read permission for user running RMI Server / Client. (if you are working on Unix.)

Pawan.

Pawan_Singha at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...
# 10

I'm still getting that error... I've checked the classpath variable on the server side, and it contains the bin directory of my project. Besides that, I've modified the permissions for all the files so that it's accessible for all users. I'm still wondering why it did work (and it still does) when I used Eclipse (as a simple application) and it gives errors when my I work with Netbeans and my application has changed into a web application. There can't be that big difference between both applications, isn't there?

thanks in advance,

regards,

E_J

El_Javaistaa at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...
# 11
Hi,I got to know there is a configuration in NetBeans which helps you to enable / disable Distributed Java.Please read the following link : http://www.vsj.co.uk/java/display.asp?id=298Please do let me know if it worked for you.Pawan.
Pawan_Singha at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...
# 12

Hi,

After reading this article, I tried to do the same thing in my IDE. I guess that RMI simply isn't supported in NetBeans 4.1. That could explain a lot of things of course. Do you (or anyone else) have any idea if that's absolutely true, and if yes, what can i do in that case to avoid that I have to rewite all my client and server files using another method (soap, sockets ...etc)

Thanks in advance,

E_J

El_Javaistaa at 2007-7-16 1:16:46 > top of Java-index,Core,Core APIs...