[opencms-dev] can not get RMI stub registered in tomcat from standalone application
jim
jim.ji at transplace.com.cn
Fri Sep 30 02:23:37 CEST 2005
hi all,
I am trying to register a rmi service inside tomcat,so that it will be in the same application context as opencms and can use the object CmsObject to fulfill my request,This following is what I do for test purpose:
1,create IOpencms.java like this
IOPencms.java
/*
/*
* Created on 2005-9-29
*
*/
import java.rmi.*;
/**
* @author jimw
*
* mailto:jimingwei780225 at hotmail.com
*/
public interface IOpencms extends java.rmi.Remote {
public void sayHello()throws RemoteException;
}
2,create implementation class
import java.net.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
public class Opencms extends UnicastRemoteObject implements IOpencms{
public Opencms()throws RemoteException{}
public void sayHello()throws RemoteException{
System.out.println("hello,world");
}
}
3,create stub and skeleton
Opencms_Skel.class Opencms_Stub.class
4,create a Servlet that will be started once the opencms app is deployed .
the following code is in its init() method.
try {
// TODO Auto-generated constructor stub
Registry registry=LocateRegistry.createRegistry(6666);
System.out.println("I am fine");
registry.bind("opencms0",new Opencms_Stub());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
5,modify web.xml and restart tomcat,everything works file in tomcat.Up to now,everything is ok.
Pay attention to the following:
6,then I created a standalone client to test.
public static void main(String[] args)throws Exception {
try {
Registry registry=LocateRegistry.getRegistry(6666);
System.out.println(registry.list()[0]);
IOpencms opencms=(IOpencms)registry.lookup("opencms0");
opencms.sayHello();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
7,the exception is :
opencms0
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.EOFException
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at RMIClient.main(RMIClient.java:38)
Caused by: java.io.EOFException
at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:310)
at java.io.ObjectInputStream$BlockDataInputStream.readUnsignedShort(ObjectInputStream.java:2712)
at java.io.ObjectInputStream$BlockDataInputStream.readUTF(ObjectInputStream.java:2768)
at java.io.ObjectInputStream.readUTF(ObjectInputStream.java:1021)
at java.rmi.server.RemoteObject.readObject(RemoteObject.java:407)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:919)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1813)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
... 2 more
8,conclusion:
as you can see,client can find the stub named "opencms0",but when it try to get the stub,exception is thrown,it seems that I can not get the stub from rmi registry who is running inside tomcat.
9.I need your help,if this problem is solved,then I can use CmsObject inside the implementation class .
More information about the opencms-dev
mailing list