Re: smart/dynamic proxies and java 1.5

"Mark E. Ackerman" <[email protected]> Wed, 4 Oct 2006 11:35:56 -0700
Newsgroups gmane.comp.java.sun.rmi
Message-ID <[email protected]>
Thanks Peter.

The info on exporting the server pointed me in the right direction.  I changed
the export call we were using.

And now it seems to work....

I would like to get rid of the reliance on the sun classes.

What we're doing to create the dynamic proxies is this:

protected java.rmi.Remote getServerSideProxies(ClassLoader cl)
{
         java.rmi.Remote server = super.getServerSideProxies(cl);

         _aServerProxy = new rma.rmi.proxy.AServerProxy( server, this);

         server = (RmiFileManager) java.lang.reflect.Proxy.newProxyInstance(
                 cl,new Class[] { RmiFileManager.class },_aServerProxy);
         return server;
}

Where getServerSideProxies() eventually returns this, where this is
an object that implements Remote.

Then we export the Remote Object returned from
getServerSideProxies().  There was a bunch of
magic that Rickard figured out way back when to make it work with
releases before 1.5.

We're also marshalling/unmarshalling data in the RMI stream for each
RMI call through marshalCustomCallData()
and unmarshalCustomCallData()

Mark
At 09:41 PM 10/3/2006, you wrote:
> > Anyone out there using RMI Smart Proxies/Dynamic Proxies (Rickard
> > Oberg posted the way to do this here a long time ago) with Java 1.5?
> > (or is there a new better way to use Dynamic Proxies in 1.5)
>
>See below.
>
> > We're inserting proxies on both the client and server side to do
> > stuff, logging, security etc.
> >
> > We're been using them successfully with Java 1.3 and 1.4 but they no
> > longer work with 1.5.  I figured I check to see if anyone else has
> > already run into this problem.
> >
> > We're getting StubNotFoundExceptions.
> >
> > Exception with exportObject on PortableRmiObject
> > (//xxx.xxx.xxx.165:64101/)RmiFileManagerImpl[RMAUnicastServerRef2
> > [liveRef:
> >
> [endpoint:[xxx.xxx.xxx.165:52010,rma.rmi.server.SinglePortServerSocketFactory@84eda628,rma.rmi.server.LimitedPortServerSocketFactory@52a393bc](local),objID:[0]]]]
> > Error:java.rmi.StubNotFoundException: Stub class not found:
> $Proxy0_Stub; nested exception is:
> > java.lang.ClassNotFoundException: $Proxy0_Stub
> > java.rmi.StubNotFoundException: Stub class not found:
> $Proxy0_Stub; nested exception is:
> > java.lang.ClassNotFoundException: $Proxy0_Stub
> >         at sun.rmi.server.Util.createStub(Util.java:274)
> >         at sun.rmi.server.Util.createProxy(Util.java:122)
> >         at
> sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:179)
> >         at
> sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:161)
> >         at
> hec.server.PortableRmiObject.exportObject(PortableRmiObject.java:812)
> >         at
> hec.server.PortableRmiObject.exportObject(PortableRmiObject.java:720)
> >         at
> hec.server.PortableRmiObject.exportServer(PortableRmiObject.java:365)
> >         at
> hec.server.PortableRmiObject.rebindServer(PortableRmiObject.java:228)
> >         at hec.server.RMIServer.startServer(RMIServer.java:156)
> >         at hec.server.RMIProxyServer.<init>(RMIProxyServer.java:66)
> >         at hec.server.FileManager.<init>(FileManager.java:23)
> >         at hec.server.FileManager.main(FileManager.java:92)
> >         Caused by: java.lang.ClassNotFoundException: $Proxy0_Stub
> >                 at java.lang.Class.forName0(Native Method)
> >                 at java.lang.Class.forName(Class.java:242)
> >                 at sun.rmi.server.Util.createStub(Util.java:268)
> >
> > ClassNotFoundException usually means its not in the classpath.  But
> > with the Smart Proxy stuff its never been in the classpath.  It gets
> > loaded through the use of a custom class loader.  My guess is that
> > how RMI does classloading was changed 1.5, but that's only a guess.
>
> From the name of the stub class being sought, it appears that you are
>trying to export an instance of a dynamic proxy class as a remote
>object.  I would need to see more details about the particular trick
>that you are using to get that to work with JDK versions earlier than
>5.0 in order to speculate about why it no longer works with 5.0.  The
>procedure used by the JDK RMI implementation to load the stub class
>for a remote object should be effectively the same in 5.0 as it was in
>previous versions, although the surrounding code was changed a bit.
>But the above stack trace seems to indicate direct use of sun.rmi.*
>APIs, which would mean that compatibility shouldn't be expected
>anyway:
>
>         http://java.sun.com/products/jdk/faq/faq-sun-packages.html
>
>With JDK 5.0, exporting remote objects that are instances of dynamic
>proxy classes is more directly supported because rmic-generated stub
>classes are usually no longer required:
>
>         http://java.sun.com/j2se/1.5.0/docs/guide/rmi/relnotes.html
>
>But that feature doesn't work in the case of the above stack trace
>because of the particular sun.rmi.server.UnicastServerRef method being
>used to export the object.  The issue is pretty similar to that of the
>public UnicastRemoteObject.exportObject(Remote) method described here:
>
>         http://archives.java.sun.com/cgi-bin/wa?A2=ind0501&L=rmi-users&P=556
>
>-- Peter
>
>===========================================================================
>To unsubscribe, send email to [email protected] and include in the body
>of the message "signoff RMI-USERS".  For general help, send email to
>[email protected] and include in the body of the message "help".
>
>For a list of frequently asked RMI questions please refer to:
>http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html
>
>To view past RMI-USERS postings, please see:
>http://archives.java.sun.com/archives/rmi-users.html

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html