Announcement Announcement Module
Collapse
No announcement yet.
Tomcat + Spring + RMI Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tomcat + Spring + RMI

    Hi all,

    I'm trying to get a simple Spring application to work in a Server/Client mode. I'm using Tomcat 5.5.23, Spring 2.0.5.

    For the Server I have the following code:

    HelloWorld.java

    Code:
    package com.all4me.rmiservertest;
    
    import java.rmi.*;
    
    public interface HelloWorld extends Remote {
        
        public String getHelloWorld() throws RemoteException;
        
    }

    HelloWorldImpl.java

    Code:
    package com.all4me.rmiservertest;
    import java.io.Serializable;
    
    public class HelloWorldImpl implements HelloWorld, Serializable {
        static final long serialVersionUID = 1L;
            
        /** Creates a new instance of HelloWorld */
        public HelloWorldImpl() {
        }
        
        public String getHelloWorld() {
            return "Yes it's the venerable Hello World again.";
        }
        
    }
    applicationContext.xml

    Code:
    <?xml version="1.0"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
        <bean id="helloWorldService" class="com.all4me.rmiservertest.HelloWorldImpl">
        </bean>
    
        <bean id="helloWorldServiceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
            <property name="serviceName" value="HelloWorld"/>
            <property name="service" ref="helloWorldService"/>
            <property name="serviceInterface" value="com.all4me.rmiservertest.HelloWorld"/>
            
            <property name="registryPort" value="9000"/>
            <property name="servicePort" value="9001"/>
        </bean>  
    </beans>

    web.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    	 version="2.4">
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
    	<welcome-file>
                index.jsp
            </welcome-file>
        </welcome-file-list>
    </web-app>
    For the Client I have the following Code:

    HelloWorldHandler.java

    Code:
    package com.all4me.rmiclienttest;
    
    import com.all4me.rmiservertest.HelloWorld;
    
    public class HelloWorldHandler {
        
        private static HelloWorld helloWorld;
        
        public void setHelloWorld(HelloWorld helloWorld) {
            this.helloWorld = helloWorld;
        }
        
        public HelloWorld getHelloWorld() {
            return helloWorld;
        }
        
        /** Creates a new instance of HelloWorldHandler */
        public HelloWorldHandler() {
        }
    
        public String getHelloWorldString() {
            return helloWorld.getHelloWorld();
        }
        
    }
    applicationContext.xml


    Code:
    <?xml version="1.0"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>     
        <bean id="helloWorldService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
            <property name="serviceUrl" value="rmi://localhost:9000/HelloWorld"/>
            <property name="serviceInterface" value="com.all4me.rmiservertest.HelloWorld"/>
        </bean>
        
        <bean id="helloWorldHandler" class="com.all4me.rmiclienttest.HelloWorldHandler">
            <property name="helloWorldService" ref="helloWorldService"/>
        </bean>
    </beans>
    web.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    	 version="2.4">
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
    	<welcome-file>
                index.jsp
            </welcome-file>
        </welcome-file-list>
    </web-app>

  • #2
    The server seems to deploy propery but when I try to deploy the Client I get (in the tomcat.log):

    Code:
    ERROR http-8081-Processor23 org.springframework.web.context.ContextLoader - Context initialization failed
     org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloWorldService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.remoting.RemoteLookupFailureException: Lookup of RMI stub failed; nested exception is java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
    	java.io.EOFException
    Caused by: 
    org.springframework.remoting.RemoteLookupFailureException: Lookup of RMI stub failed; nested exception is java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
    	java.io.EOFException
    Caused by: 
    java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
    	java.io.EOFException
    	at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    	at java.rmi.Naming.lookup(Naming.java:84)
    	at org.springframework.remoting.rmi.RmiClientInterceptor.lookupStub(RmiClientInterceptor.java:198)
    	at org.springframework.remoting.rmi.RmiClientInterceptor.prepare(RmiClientInterceptor.java:145)
    	at org.springframework.remoting.rmi.RmiClientInterceptor.afterPropertiesSet(RmiClientInterceptor.java:133)
    	at org.springframework.remoting.rmi.RmiProxyFactoryBean.afterPropertiesSet(RmiProxyFactoryBean.java:74)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1202)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:428)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
    	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
    	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
    	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
    	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
    	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:511)
    	at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1220)
    	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 org.apache.commons.modeler.BaseModelMBean.invoke(BaseModelMBean.java:457)
    	at com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(DynamicMetaDataImpl.java:213)
    	at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:220)
    	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:815)
    	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:784)
    	at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1397)
    	at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:815)
    	at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:344)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
    	at java.lang.Thread.run(Thread.java:595)
    Caused by: java.io.EOFException
    	at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2498)
    	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1273)
    	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
    	at sun.rmi.server.MarshalInputStream.readLocation(MarshalInputStream.java:285)
    	at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:228)
    	at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1500)
    	at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1463)
    	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1699)
    	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
    	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
    	... 55 more
    One last thing, this is running on Windows XP (both the Server and the Client). I know there was a problem with spaces in path names for RMI and there are no spaces in my path names.

    So does anyone have any ideas what I'm doing wrong here?

    Comment


    • #3
      *bump*

      Anyone? Anyone? Bueller? Bueller?

      Comment


      • #4
        Try testing your simple application without web container - imho, this config should work.
        Also, here might be an explanation of something related to your case.

        Comment


        • #5
          Well I'll continue to beat this dead horse as best I can. Here's what I found out today.

          First, thanks for the suggestion but running outside of Tomcat isn't going to help as that's my goal.

          Second, anyone that reads this after I've given up on it, this DOES work if you have the RMI Tomcat Server on a UNIX box (it may with another PC as well I haven't tried that) and you're connecting to it from a PC. The configuration that I know for sure where this problem exists is the Server and Client both seperate Tomcat servers running on the same PC.

          But, here's what I found out that works today. If you deploy the application to the Tomcat server and then restart the server you are then able to attach with the Tomcat client and it works. It has something to do with reloading the application (which you may want to turn off auto reloading).

          I found this on JSPWiki: Stupid Questions:

          Question: What causes these frequent Tomcat catalina.log messages "INFO: Illegal access: this web application instance has been stopped already."? I do not want to disable INFO level logging, so it would be nice to stop the root of the problem. I tried disabling RSS and Lucence and they still keep coming out. The full log entry looks like this: May 8, 2005 9:34:09 PM org.apache.catalina.loader.WebappClassLoader loadClass INFO: Illegal access: this web application instance has been stopped already. Could not load org.xml.sax.helpers.XMLReaderFactory. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.

          A:I found this explanation from web: It is possible that this is caused by Tomcat unsuccessfully reloading the web application. The app is unloaded, but all threads don't get shut down properly. As a result, when the threads try to run, they get clobbered by the fact that Tomcat has shut down its classloader, and an error is logged. The best fix is to turn off automatic webapp reloading for the application: in Tomcat's server.xml, find the <Context> declaration, and ensure it is set to: reloadable="false"
          This was after I turned on the full motherload of debugging and got this in my tomcat.log file:

          Code:
          INFO RMI TCP Connection(8)-192.168.66.2 org.apache.catalina.loader.WebappClassLoader - Illegal access: this web application instance has been stopped already.  Could not load java.rmi.server.RemoteObjectInvocationHandler.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
          As you can see this is *cough*stupidly*cough* an INFO message. This at a minimum should be a DEBUG.

          Anyway, that's what I've found out...

          Comment

          Working...
          X