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 = (RMIServer) factory.getBean("RMIServer");
String r = bean1.getresult("asdf");
System.out.println(r);
// ////////////client/////////////////
res = new ClassPathResource("context.xml");
factory = new XmlBeanFactory(res);
RMIservice bean2 = (RMIservice) factory.getBean("RMIservice");
String s = bean2.getresult("AAA");
System.out.println(s);
}
}
interface RMIservice {
String getresult(String s);
}
interface RMIServer extends Remote {
String getresult(String s) throws 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 a) throws RemoteException {
String r = "hi " + a;
return r;
}
}
|