Improve your contact center performance. See how you can make a difference.
Watch Now
Engage and build your ICT audience with CIOL online advertising.
Know more
Consuming remote services To consume a remote service, we'll use the Spring's RmiProxyFactoryBean. As the name suggests, the RmiProxyFactoryBean is a factory bean that creates a proxy to an RMI service. In our demo example we'll write a POJO which has a dependency in the remote service (later, we'll wire this depencecy through Spring DI), as shown here:
package com.pcquest.remoting.client; import com.pcquest.remoting. service.*;
public class SimpleObject { private rmservice remoteService;
public void setRemoteService(rmservice remoteService) { this.remoteService = remoteService; } ...
Now, let's look at the Spring configuration file for plumbing all related dependencies:
<bean id="rmiService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceUrl" value="rmi://localhost:1199/MyService"/> <property name="serviceInterface" value="com.pcquest.remoting.service.rmservice"/> </bean> <bean id="simple" class="com.pcquest.remoting.client.SimpleObject"> <property name="remoteService" ref="rmiService"/> </bean>
As shown, the URL of the RMI service is set through the serviceUrl property. The serviceInterface property identifies the interface that the remote service implements. The client will call business methods on the same interface. Further, after the remote service is resolved, it's injected into the simple object as discussed before.
Conclusion Spring provides easy integration points for RMI protocol. However, RMI is Java based remoting technique; both the client and the server must be written in Java. Also, RMI uses arbitrary ports for communication; this could cause problems working across firewalls. In the next part, we'll explore how Spring supports HTTP remoting.
<< PREVIOUS