Announcement Announcement Module
Collapse
No announcement yet.
Help with Simple RMI Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with Simple RMI

    Hi guys:

    I have the server application:
    Interface:
    Code:
    public interface ServiceInterface extends Remote {
    
    	public String syaHello() throws RemoteException;
    
    }
    Implementation:
    Code:
    public class ServiceImplementation extends UnicastRemoteObject implements ServiceInterface{
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 2262342784592437834L;
    
    	protected ServiceImplementation() throws RemoteException {
    		super();
    		// TODO Auto-generated constructor stub
    	}
    
    	public String syaHello() throws RemoteException {		
    		return "Server says, Hey";
    	}	
    }
    xml
    Code:
    <beans>
    	<bean id="printService" class="au.com.test.ServiceImplementation"></bean>
    
    
    	<bean id="rmiServer" class="org.springframework.remoting.rmi.RmiServiceExporter">
    		<!-- does not necessarily have to be the same name as the bean to be exported -->
    		<property name="serviceName" value="PrintService"/>
    		<property name="service" ref="printService"/>
    		<property name="serviceInterface" value="au.com.test.ServiceInterface"/>
    		<!-- defaults to 1099 -->
    		<property name="registryPort" value="1199"/>
    	</bean>
    
    </beans>
    Main:
    Code:
    public class Main {
    
    	public static void main(String[] args){
    		
    		ApplicationContext context = new ClassPathXmlApplicationContext("service.xml");
    		
    RmiServiceExporter server = (RmiServiceExporter)context.getBean("rmiServer");
    			server.prepare();
    			System.out.println("I am ready, Server !!!");		
    		
    	}
    }
    When i try to run the main class, it throws Exception:

    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'rmiServer' defined in class path resource [service.xml]: Invocation of init method failed; nested exception is java.rmi.server.ExportException: object already exported
    Caused by: java.rmi.server.ExportException: object already exported

    Do you have any idea?


    Thanks
    Tony

  • #2
    Do you need to call the prepare() method? Note: I am just guessing here.

    Comment


    • #3
      And try looking at the source code / javadoc for RmiServiceExporter to see what properties you can set in your .xml file for this exporter. Maybe there is a flag to avoid your problem.

      Or could it be that some other program has bound the port number?

      Comment


      • #4
        I don't believe you need to extend UnicastRemoteObject in your implementation class. I think this gets handled by the RmiServiceExporter. I've got a similar scenario and I didn't extend UnicastRemoteObject and everything seems to work.

        Comment


        • #5
          Yeh, thanks its work.

          And i noticed that i can not call server.perpare( );

          so will spring do all the things for rmi ?

          main class
          Code:
          public class Main {
          
          	public static void main(String[] args){
          		
          		ApplicationContext context = new ClassPathXmlApplicationContext("service.xml");
          		
          		try{
          			RmiServiceExporter server = (RmiServiceExporter)context.getBean("rmiServer");
          			System.out.println("I am ready, Server !!!");
          		}catch(Exception e){
          			e.printStackTrace();
          		}
          	
          		
          		
          		
          	}
          	
          	
          }

          Comment


          • #6
            The short answer is 'yes'. Using Spring you can do as much or as little of an RMI implementation as you like. I ran into an interesting issue today that I'll pass along as well.

            I was trying to lookup an object that was resident on another server, but that server was down so the lookup failed. I was using the RmiProxyFactoryBean to instantiate the rmi service within an application context. Well of course an exception was thrown and that prevented proper startup of my application. My problem and solution are posted in the following thread:
            http://forum.springframework.org/showthread.php?t=36004

            Maybe this will be helpful for you at some point.
            Good luck,

            Comment


            • #7
              Thanks Jim

              Comment

              Working...
              X