Magazine
 
Spring

2. D:\springdemo\rmserverimpl.java

import java.rmi.*;
import java.rmi.server.*;
public class rmserverimpl extends
UnicastRemoteObject implements rmserver {
public static void main(String args[]) {
try {
rmserverimpl ob = new rmserverimpl();
Naming.rebind(“rmserver”,ob);
System.out.println(“ready”);
}
catch(Exception e1) {
System.out.println(“”+e1);
}
}
public rmserverimpl() throws
RemoteException {
System.out.println(“constructor ok”);
}
public String getresult(String a) throws
RemoteException
{
return “Hai...” + a;
}
}

3. D:\springdemo\rmserver.xml

<?xml version=”1.0" encoding=”UTF-8"?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD
BEAN//EN” ”http://
www.springframework.org/dtd/ springbeans.
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
id=”rmserverimpl” class=”rmserverimpl”>
<property name=”rmserver”>
<ref bean=”rmserver”/>
</property>
</bean>
</beans>

 

4. D:\springdemo\rmspring.java

import java.rmi.*;
import org.springframework.beans.factory.*;
import
org.springframework.beans.factory.xml.*;
import org.springframework.core.io.*;
public class rmspring {
public static void main(String args[]) {
try {
System.out.println(“Wait..”);
Resource res = new
ClassPathResource(“rmi.xml”);
BeanFactory factory = new
XmlBeanFactory(res);
rmserver bean1 = (rmserver)
factory.getBean(“rmserver”);
String r=bean1.getresult(args[0]);
System.out.println(r);
}
catch(Exception e1) {
System.out.println(“” + e1);
}
}
}

III Compile and run the classes as
shown:

D:\springdemo>javac rmserver.java
D:\springdemo>javac rmserverimpl.java
D:\springdemo>rmic rmserverimpl (To create
stub and skeleton)
D:\springdemo>javac rmspring.java
D:\springdemo>start rmiregistry (a blank
window will appear)
D:\springdemo>java rmserverimpl
Open another Window and run the client
code by giving the argument
D:\springdemo>java rmspring “Amit”

We will get the output as:

Wait...
Sep 28, 2007 3:53:10 PM
org.springframework.core.CollectionFactory
<clinit>
INFO: JDK 1.4+ collections available
Sep 28, 2007 3:53:10 PM
org.springframework.beans.factory.xml.
XmlBeanDefinitionReader loadBeanDefinitions

 

Oct 2007 | Java Jazz Up | 43
 
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70, 71, 72, 73, 74, 75, 76, 77, 78,   Download PDF