Re: java.rmi.UnmarshalException

liang li <[email protected]> Wed, 14 May 2008 09:11:42 +0800
Newsgroups gmane.comp.java.sun.jini
Message-ID <[email protected]>
thanks gregg.
     i will show your more detail:
1) my interface class:

public interface Log4Jini extends Remote
{
    public void log(String className, int level, Object msg)
            throws RemoteException;

    public void log(String className, int level, Object msg, Throwable t)
            throws RemoteException;

}

2 ) implements Log4Jini  interface

public class Log4JiniImpl implements Serializable, Log4Jini,
ServiceIDListener
{

    protected Log log = LogFactory.getLog(Log4JiniImpl.class);

    public void serviceIDNotify(ServiceID id)
    {
        if (log.isInfoEnabled())
        {
            log.info("Service ID is: " + id);
        }

    }

    public void log(String className, int level, Object msg, Throwable t)
            throws RemoteException
    {
        // do something

    }

    public void log(String className, int level, Object msg)
            throws RemoteException
    {
        // do something

    }

    public Log4JiniImpl() throws RemoteException
    {
        super();
    }

}

3) write an service

public class Log4JiniService
{
    protected Log log = LogFactory.getLog(Log4JiniService.class);

    private final static long LOG4J_CONFIG_AND_WATCH_DELAY = 30000;

    private static final String COMPONENT =
"com.wri.hy.onecgs.jini.service.logging";

    private transient String[] initialMemberGroups;

    private String log4jPropertyFile;

    private void initializeSecurityManager()
    {
        if (System.getSecurityManager() == null)
        {
            System.setSecurityManager(new RMISecurityManager());
        }
    }

    private void initializeJoinManager()
    {
        try
        {
            Log4JiniImpl impl = new Log4JiniImpl();

            LookupDiscoveryManager manager = new LookupDiscoveryManager(
                    initialMemberGroups, null, null);



            JoinManager joinManager = new JoinManager(impl, null,
                    (Log4JiniImpl) impl, manager, null);
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    public Log4JiniService(String[] args, final LifeCycle lc)
            throws ConfigurationException, LoginException, IOException
    {

        final Configuration config = ConfigurationProvider.getInstance(args,
                Log4JiniService.class.getClassLoader());

        init(args, config);

    }

    public Log4JiniService(String[] args)
            throws ConfigurationException, LoginException, IOException
    {

        final Configuration config = ConfigurationProvider.getInstance(args,
                Log4JiniService.class.getClassLoader());

        init(args, config);
    }

    private void init(String[] anArgs, Configuration config)
            throws ConfigurationException, RemoteException
    {

        try
        {
            initialMemberGroups = (String[]) config.getEntry(COMPONENT,
                    "initialMemberGroups", String[].class);

            log4jPropertyFile = (String) config.getEntry(COMPONENT,
                    "log4jPropertyFile", String.class);

            PropertyConfigurator.configureAndWatch(log4jPropertyFile,
                    LOG4J_CONFIG_AND_WATCH_DELAY);

            initializeSecurityManager();
            initializeJoinManager();
        }
        catch (Exception anE)
        {
            if (log.isErrorEnabled())
            {
                log.error("loginContext has insufficient privileges", anE);
            }
        }
    }

    public static void main(String args[])
    {
        try
        {
            new Log4JiniService(args);

            Object keepAlive = new Object();
            synchronized (keepAlive)
            {
                keepAlive.wait();
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

}



4)  build my java source file

5) run rmic command

rmic -v1.2 -keep -classpath
c:\\jini2_1\\lib\\jini-core.jar;c:\\jini2_1\\lib\\jini-ext.jar;.
Log4JiniImpl

6)  jar my class(named jiniLogger.jar)

7) copy jiniLogger.jar to c:\\jini2_1\\lib

8) copy jiniLogger.jar to c:\\jini2_1\\lib-dl, and rename jiniLogger-dl.jar
, and only Log4Jini.class and Log4JiniImpl_Stub.class are left (i delete
Log4JiniImpl.class and Log4JiniService.class, i think both is not needed for
clients)

9) run launch-all.exe(start jini)

10) register my service

java -Djava.security.policy=C:/jini2_1/installverify/support/jsk-all.policy
-Djava.rmi.server.codebase="http://192.168.8.3:8081/jiniLogger-dl.jar<http://192.168.8.3:8081/onecgs-dl.jar>
http://192.168.8.3:8081/jsk-dl.jar" -classpath
"C:\\jini2_1\\lib\\commons-codec-1.1.jar;C:\\jini2_1\\lib\\commons-lang-2.1.jar;C:\\jini2_1\\lib\\commons-logging-1.1.1.jar;C:\\jini2_1\\lib\\icu4j-3.4.4.jar;C:\\jini2_1\\lib\\jasypt-1.4.1.jar;C:\\jini2_1\\lib\\log4j-1.2.15.jar;C:\\jini2_1\\lib\\jiniLogger.jar;C:\\jini2_1\\lib\\jini-ext.jar;C:\\jini2_1\\config"
Log4JiniService C:\\jini2_1\\installverify\\support\\log4Jini.config

11) using jini service browser, i found the  name of my service is
Log4JiniImpl.

12) i run an client on another pc, an exception is thrown:

java.rmi.UnmarshalException: error unmarshalling return; nested exception
is:
 java.lang.ClassNotFoundException: Log4JiniImpl
 at com.sun.jini.reggie.RegistrarProxy.lookup(RegistrarProxy.java:120)

13) i googled, in the web:

http://jan.newmarch.name/java/jini/tutorial/TroubleShooting.xml#RMI%20Stubs

*Typical error *

*java.rmi.StubNotFoundException:
         Stub class not found: rmi.FileClassifierImpl_Stub;
nested exception is:
        java.lang.ClassNotFoundException: rmi.FileClassifierImpl_Stub*

**

*Many of the examples export services as remote RMI objects. These objects
are subclasses of UnicastRemoteObject. What gets exported is not the object
itself, but a stub that will act as proxy for the object (which continues to
run back in the server). The stub has to be created using the rmic compiler
as in *

*rmic -v1.2 -d . rmi.FileClassifierImpl*

*This will create a FileClassifierImpl_Stub.class in the rmi subdirectory.
The stub class file needs to be accessible to the Java runtime in the same
way as the original class file.*

*note:*

*the article say XXXX_stub is not found, however, my exception say my
Log4JiniImpl class is not found, not Log4JiniImpl_stub?*

what is wrong?

need help!

best regards

byron lee



2008/5/13, Gregg Wonderly <[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]