Remoting and Web Services
Spring provides support for remoting with various technologies. The remoting support eases the development of remote-enabled services, implemented via Java interfaces and objects as input and output. Currently, Spring supports the following remoting technologies:
-
Remote Method Invocation (RMI): Through the use of
RmiProxyFactoryBean
andRmiServiceExporter
, Spring supports both traditional RMI (withjava.rmi.Remote
interfaces andjava.rmi.RemoteException
) and transparent remoting through RMI invokers (with any Java interface). -
remoting-httpinvoker: Spring provides a special remoting strategy that allows for Java serialization though HTTP, supporting any Java interface (as the RMI invoker does). The corresponding support classes are
HttpInvokerProxyFactoryBean
andHttpInvokerServiceExporter
. -
remoting-caucho-protocols-hessian: By using Spring’s
HessianProxyFactoryBean
and theHessianServiceExporter
, you can transparently expose your services through the lightweight binary HTTP-based protocol provided by Caucho. -
remoting-web-services: Spring provides remoting support for web services through JAX-WS.
-
remoting-jms: Remoting via JMS as the underlying protocol is supported through the
JmsInvokerServiceExporter
andJmsInvokerProxyFactoryBean
classes in thespring-jms
module. -
remoting-amqp: Remoting via AMQP as the underlying protocol is supported by the separate Spring AMQP project.
While discussing the remoting capabilities of Spring, we use the following domain model and corresponding services:
public class Account implements Serializable{
private String name;
public String getName(){
return name;
}
public void setName(String name) {
this.name = name;
}
}
public interface AccountService {
public void insertAccount(Account account);
public List<Account> getAccounts(String name);
}
// the implementation doing nothing at the moment
public class AccountServiceImpl implements AccountService {
public void insertAccount(Account acc) {
// do something...
}
public List<Account> getAccounts(String name) {
// do something...
}
}
This section starts by exposing the service to a remote client by using RMI and talk a bit about the drawbacks of using RMI. It then continues with an example that uses Hessian as the protocol.