• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamic Class Downloading From an HTTP Server

 
mridul das
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pretty new to RMI. I have a simple HTTP sever(found in the net) whic serves the classes to the client through a server socket as follows
out.writeBytes("HTTP/1.0 200 OK\r\n");
out.writeBytes("Content-Length: " + bytecodes.length +
"\r\n");
out.writeBytes("Content-Type: application/java\r\n\r\n");
out.write(bytecodes);
out.flush();

While I try this from the same machine
Class cls1 = RMIClassLoader.loadClass(new URL("http://machine-name:2001/"),"className");
the class seems to be loaded.
But the same code on trying from a different machine gives the following exception
java.lang.ClassNotFoundException: jnp.server.Test_Stub
at java.net.URLClassLoader$1.run(URLClassLoader.java:196)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
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:631)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:169)
at Main.test(Main.java:55)
at Main.main(Main.java:33)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:222)
at java.io.BufferedInputStream.read(BufferedInputStream.java:277)
at sun.net.www.MeteredStream.read(MeteredStream.java:106)
at java.io.FilterInputStream.read(FilterInputStream.java:111)
at sun.misc.Resource.getBytes(Resource.java:64)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
... 13 more
Could anyone help me understand what the prob is .
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caused by: java.net.SocketException: Connection reset

This is the root cause. Are you certain that you can connect to port 2001 on the server from the machine that's giving you problems? Are there any error messages in the server log?
 
mridul das
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I commented out a peice of code which was
finally{
socket.close();
}
Since then it seems to be working.
But havent found the answer to why was it working in the local machine. The stub was not in the classpath however
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!