Results 1 to 7 of 7

Thread: Help with Simple RMI

  1. #1

    Default 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. #2
    Join Date
    Sep 2004
    Location
    Copenhagen, Denmark
    Posts
    113

    Default

    Do you need to call the prepare() method? Note: I am just guessing here.
    /Claus

  3. #3
    Join Date
    Sep 2004
    Location
    Copenhagen, Denmark
    Posts
    113

    Default

    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?
    /Claus

  4. #4
    Join Date
    Jan 2007
    Posts
    7

    Default

    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.

  5. #5

    Default

    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();
    		}
    	
    		
    		
    		
    	}
    	
    	
    }

  6. #6
    Join Date
    Jan 2007
    Posts
    7

    Default

    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,

  7. #7

    Default

    Thanks Jim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •