Magazine
 
Spring

The client makes calls to the proxy to provide the service and the proxy calls the remote service on behalf of the client.Now let’s see - how to wire other RMI services into spring application and how to export our own services using the RMI model.

Remote Method Invocation (RMI) Model: RMI was first introduced in JDK 1.1. But developing and accessing RMI services involves various steps and also have lookups which makes the code hard to test. Spring simplifies the RMI by providing a ‘proxy factory bean’ that enables us to wire the RMI services into spring application as if they are local beans. Spring also provides a remote exporter that converts our ‘spring managed beans’ into RMI services. Spring’s ‘RmiProxyFactoryBean’ is a factory bean that creates a proxy to RMI service. It is declared in the spring configuration file under the <bean> tag as follows,

<bean
id=”service1"class=”org.springframework.remoting.rmi.
RmiProxyFactoryBean”>
<property name=”serviceUrl”>
<value>rmi://${hostname}/service1</
value>
</property>
<property name=”serviceInterface”>
<value>service1</value>
</property>
</bean>

The url of the RMI service is set through the ‘serviceUrl’ property. The ‘serviceInterface’ property specifies the interface that the service implements and only through that the client invokes methods on the service. For using the service the implementation code is wired to the RMI using the following code,

<bean id=”serviceimpl” class=”serviceimpl”>
<property name=”service1">
<ref bean=”service1"/>
</property>
</bean>

 

I. Lets Set up the Environment Variables
and start the things:

As the entire Spring Framework is included in spring.jar. We use it to run our examples.

1 Copy spring.jar from spring1.2.9\dist folder to the working folder (say D:\springdemo), also copy commonslogging. jar from apache tomcat- 6.0.10 to the working directory.

2 Set path for jdk1.4.2 and above versions.

3 Now set the classpath as shown:
D:\springdemo\>set
classpath=D:\springdemo;
D:\springdemo\spring.jar;
D:\springdemo\commons-logging.jar;

4 For a typical Spring Application we need the following files:

i. An interface that defines the functions.

ii. An Implementation that contains properties, its setter and getter methods, functions etc.

iii. A XML file called Spring configuration file.

iv.Client program that uses the function.

II. Create the following files

1. rmserver.java
2. rmserverimpl.java
3. rmserver.xml
4. rmspring.java

1. D:\springdemo\rmserver.java

import java.rmi.*;
public interface rmserver extends Remote
{
String getresult(String s) throws
RemoteException;
}

Oct 2007 | Java Jazz Up | 42
 
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