Announcement Announcement Module
Collapse
No announcement yet.
Custom ClassLoader and RMI Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom ClassLoader and RMI

    Hi

    On Spring 3.0.4, we have a platform where java packages can be deployed with their own application contexts. This works great, even in a cluster until they need to start passing their own classes over remote method calls.

    I have boiled the problem down to a small host/client replication package where the host creates a url classloader then starts a spring context using the classloader.

    The host starts up just fine but when the client tries to access the print method I get a ClassNotFoundException thrown on the host (then shown and thrown on the client).

    It seems to me like the Object Input Stream on the host doesn't have the correct classloader. But I can't figure out how to set it. It seems like beanClassLoader doesn't have an effect on the problem.


    Please can someone set me straight what the problem/solution is or whether this isn't a workable solution for deploying dynamic Java using Spring.

    Thanks in advance

    Paul.


    Host Java:
    URLClassLoader cl = Util.getClassLoader();
    ResourceXmlApplicationContext ctx = new ResourceXmlApplicationContext(new String[]{"host.xml"}, null, cl);

    Host context:

    <bean id="service" class="ServiceImpl"/>

    <bean class="org.springframework.remoting.rmi.RmiService Exporter">
    <property name="serviceName" value="Service"/>
    <property name="service" ref="service"/>
    <property name="serviceInterface" value="Service"/>
    <property name="registryPort" value="9999"/>
    <property name="servicePort" value="9999"/>
    </bean>


    Client Java:
    URLClassLoader cl = Util.getClassLoader();

    ResourceXmlApplicationContext ctx = new ResourceXmlApplicationContext(new String[]{"client.xml"}, null, cl);

    Service svc = (Service) ctx.getBean("service");
    svc.print(new Message("Hello"));

    Client context:
    <bean id="service" class="org.springframework.remoting.rmi.RmiProxyFa ctoryBean">
    <property name="serviceUrl" value="rmi://localhost:9999/Service" />
    <property name="serviceInterface" value="Service"/>
    <property name="refreshStubOnConnectFailure" value="true"/>
    </bean>



    Error (thrown on host but shown on client):

    Exception in thread "main" org.springframework.remoting.RemoteAccessException : Could not access remote service [rmi://localhost:9999/Service]; nested exception is java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: Message (no security manager: RMI class loader disabled)
    at org.springframework.remoting.rmi.RmiClientIntercep torUtils.convertRmiAccessException(RmiClientInterc eptorUtils.java:192)
    at org.springframework.remoting.rmi.RmiClientIntercep tor.doInvoke(RmiClientInterceptor.java:347)
    at org.springframework.remoting.rmi.RmiClientIntercep tor.invoke(RmiClientInterceptor.java:259)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy1.print(Unknown Source)
    at Client.main(Client.java:14)
    Caused by: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: Message (no security manager: RMI class loader disabled)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:325)
    at sun.rmi.transport.Transport$1.run(Transport.java:1 53)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport. java:149)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:466)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport.java:707)
    at java.lang.Thread.run(Thread.java:595)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceiv edFromServer(StreamRemoteCall.java:247)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Str eamRemoteCall.java:223)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:1 26)
    at java.rmi.server.RemoteObjectInvocationHandler.invo keRemoteMethod(RemoteObjectInvocationHandler.java: 179)
    at java.rmi.server.RemoteObjectInvocationHandler.invo ke(RemoteObjectInvocationHandler.java:132)
    at $Proxy0.invoke(Unknown Source)
    at org.springframework.remoting.rmi.RmiClientIntercep tor.doInvoke(RmiClientInterceptor.java:398)
    at org.springframework.remoting.rmi.RmiClientIntercep tor.doInvoke(RmiClientInterceptor.java:344)
    ... 5 more
    Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: Message (no security manager: RMI class loader disabled)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:285)
    at sun.rmi.transport.Transport$1.run(Transport.java:1 53)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport. java:149)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:466)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport.java:707)
    at java.lang.Thread.run(Thread.java:595)
    Caused by: java.lang.ClassNotFoundException: Message (no security manager: RMI class loader disabled)
    at sun.rmi.server.LoaderHandler.loadClass(LoaderHandl er.java:371)
    at sun.rmi.server.LoaderHandler.loadClass(LoaderHandl er.java:165)
    at java.rmi.server.RMIClassLoader$2.loadClass(RMIClas sLoader.java:620)
    at java.rmi.server.RMIClassLoader.loadClass(RMIClassL oader.java:247)
    at sun.rmi.server.MarshalInputStream.resolveClass(Mar shalInputStream.java:197)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectI nputStream.java:1544)
    at java.io.ObjectInputStream.readClassDesc(ObjectInpu tStream.java:1466)
    at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1699)
    at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1305)
    at java.io.ObjectInputStream.readArray(ObjectInputStr eam.java:1634)
    at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1299)
    at java.io.ObjectInputStream.defaultReadFields(Object InputStream.java:1910)
    at java.io.ObjectInputStream.readSerialData(ObjectInp utStream.java:1834)
    at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1719)
    at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1305)
    at java.io.ObjectInputStream.readObject(ObjectInputSt ream.java:348)
    at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRe f.java:290)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:279)
    ... 6 more

  • #2
    In fact I checked the beanClassLoader attribute and it gets set automatically, so I am still completely confused why there is a problem at all.

    Comment


    • #3
      Replication pack

      Come on guys - this is a simple spring issue with a full replication pack. I don't think there are any configuration issues here at all. Surely this is the right place to post a query like this and hope for an answer?

      It looks like a bug to me.

      Can't somebody help??

      I have tried to attach a replication zip - not sure it will work but here goes. It contains two eclipse projects. You run the Host from the 'Test RMI' project, which will start and wait for connections. Then from the 'Test RMI service implementation', run the client, which connects to the host and tries to run the print method on the remote service.

      Comment

      Working...
      X