Introduction Remoting and web services using Spring

4.3.9.RELEASE Spring Framework 668

28. Remoting and web services using Spring

28.1 Introduction

Spring features integration classes for remoting support using various technologies. The remoting support eases the development of remote-enabled services, implemented by your usual Spring POJOs. Currently, Spring supports the following remoting technologies: • Remote Method Invocation RMI. Through the use of the RmiProxyFactoryBean and the RmiServiceExporter Spring supports both traditional RMI with java.rmi.Remote interfaces and java.rmi.RemoteException and transparent remoting via RMI invokers with any Java interface. • Spring’s HTTP invoker. Spring provides a special remoting strategy which allows for Java serialization via HTTP, supporting any Java interface just like the RMI invoker. The corresponding support classes are HttpInvokerProxyFactoryBean and HttpInvokerServiceExporter . • Hessian. By using Spring’s HessianProxyFactoryBean and the HessianServiceExporter you can transparently expose your services using the lightweight binary HTTP-based protocol provided by Caucho. • Burlap. Burlap is Caucho’s XML-based alternative to Hessian. Spring provides support classes such as BurlapProxyFactoryBean and BurlapServiceExporter . • JAX-WS. Spring provides remoting support for web services via JAX-WS the successor of JAX-RPC, as introduced in Java EE 5 and Java 6. • JMS. Remoting using JMS as the underlying protocol is supported via the JmsInvokerServiceExporter and JmsInvokerProxyFactoryBean classes. • AMQP. Remoting using AMQP as the underlying protocol is supported by the Spring AMQP project. While discussing the remoting capabilities of Spring, we’ll use the following domain model and corresponding services: public class Account implements Serializable{ private String name; public String getName{ return name; } public void setNameString name { this .name = name; } } public interface AccountService { public void insertAccountAccount account; public ListAccount getAccountsString name; } 4.3.9.RELEASE Spring Framework 669 the implementation doing nothing at the moment public class AccountServiceImpl implements AccountService { public void insertAccountAccount acc { do something... } public ListAccount getAccountsString name { do something... } } We will start exposing the service to a remote client by using RMI and talk a bit about the drawbacks of using RMI. We’ll then continue to show an example using Hessian as the protocol.

28.2 Exposing services using RMI