RMI Remoting : RMI « Spring « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Spring » RMI 




RMI Remoting

       
File: context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
   <bean id="rmserver" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
     <property name="serviceUrl">
         <value>rmi://localhost/rmserver</value>   
     </property>
     <property name="serviceInterface">
         <value>rmserver</value>
     </property>
   </bean>
   <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
     <property name="service">
         <value>rmservice</value>   
     </property>
     <property name="serviceName">
         <value>service1</value>   
     </property>
     <property name="serviceInterface">
         <value>rmservice</value>
     </property>
   </bean>

   <bean id="rmservice" class="RMIserviceimpl">
   </bean>

   <bean id="rmserverimpl" class="RMIserverimpl">
      <property name="rmserver"><ref bean="RMIserver"/></property>
   </bean>
   
</beans>


File: Main.java

import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

class rmserviceclient {
  public static void main(String args[]) throws Exception {
    Resource res = new ClassPathResource("context.xml");
    BeanFactory factory = new XmlBeanFactory(res);
    RMIServer bean1 = (RMIServerfactory.getBean("RMIServer");

    String r = bean1.getresult("asdf");

    System.out.println(r);

    // ////////////client/////////////////
    res = new ClassPathResource("context.xml");
    factory = new XmlBeanFactory(res);
    RMIservice bean2 = (RMIservicefactory.getBean("RMIservice");
    String s = bean2.getresult("AAA");
    System.out.println(s);
  }
}

interface RMIservice {
  String getresult(String s);
}

interface RMIServer extends Remote {
  String getresult(String sthrows RemoteException;
}

class RMIserviceimpl implements RMIservice {
  public static void main(String args[]) {
    System.out.println("ready");
  }

  public RMIserviceimpl() {
    System.out.println("constructor   ok");
  }

  public String getresult(String a) {
    String r = "Hi " + a;

    return r;
  }
}

class RMIserverimpl extends UnicastRemoteObject implements RMIServer {
  public static void main(String args[]) {
    try {
      RMIserverimpl ob = new RMIserverimpl();
      Naming.rebind("RMIServer", ob);

      System.out.println("ready");
    catch (Exception e1) {
      System.out.println("registered");
    }
  }

  public RMIserverimpl() throws RemoteException {
    System.out.println("constructor   ok");
  }

  public String getresult(String athrows RemoteException {
    String r = "hi " + a;

    return r;
  }
}




           
       














Spring-RMIRemoting.zip( 2,894 k)
Related examples in the same category
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.