Re: java.rmi.UnmarshalException

Gregg Wonderly <[email protected]> Tue, 13 May 2008 10:13:13 -0500
Newsgroups gmane.comp.java.sun.jini
Message-ID <[email protected]>
liang li wrote:
> hi, all
>  
>     when i developed a jini program, i met i big problem, like this:
> java.rmi.UnmarshalException: error unmarshalling return; nested 
> exception is:
>  java.lang.ClassNotFoundException: 
> com.wri.hy.onecgs.jini.service.logging.Log4JiniImpl

With all RMI/Jini based client/server applications, you are typically using some 
type of mobile code.  Typically that mobile code, is based on the 
parameterization of your interface methods.  That is, the values that your 
interface's methods require you to provide when calling, and the values that you 
get back as results.

For example

public interface MyInterface extends Remote {
	public Results getSomeWorkDone( WorkItem item ) throws RemoteException;
}

will typically (I am skipping smart proxies with custom 
marshalling/unmarshalling here) require that the "Results" class/interface 
implementation and the WorkItem class/interface implementation be classes that 
both the client and the server know about.

One of the primary considerations of mobile code is to minimize the need of the 
client to "have" all types, but instead to "have" interface types, and download 
implementations that the server returns to it.

The most predominate example is that if your client was looking for a service 
that implemented "MyInterface", shown above, that it would download the code for 
that service implementation so that it would always get the most up to date 
implementation (bug fixes etc).

To facilitate that, you need to provide a "codebase" setting for your service 
using the RMIClassLoaderSPI provisions in the JVM.  This is done automatically 
for you, if you follow the steps that the Jini starter kit documentation, or the 
RMI examples (you seem to be using Jini 1.2.X stuff which is outdated since the 
release of Jini 2.0 several years ago) that are on the web.

Do you have a commandline option on your server's Java command line of the form 
-Djava.rmi.server.codebase=http://mywebserver/classtree/ or some such?  If not, 
then your downloaded classes, at your client, will have no "codebase annotation" 
and thus the "RMIClassLoader" will have no idea how to get implementations of 
such classes.

Gregg Wonderly

--------------------------------------------------------------------------
Getting Started:     http://www.jini.org/wiki/Category:Getting_Started
Community Web Site:  http://jini.org
jini-users Archive:  http://archives.java.sun.com/archives/jini-users.html
Unsubscribing:       email "signoff JINI-USERS"  to [email protected]