RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Spring and Hessian for Fast, Easy Java Remoting

The Hessian binary web service protocol is a powerful and easy-to-use alternative to RMI, XML/SOAP, and REST/JSON for remote communication. Learn how to integrate Spring and Hessian and then create Hessian components as simple Java objects.

he world of enterprise Java has an overwhelming array of choices for remoting: RMI, XML/SOAP, REST/JSON, etc. Each comes with its own industry-acknowledged strengths and weaknesses, such as complex setup (RMI) or performance overhead (XML/SOAP). A lesser known but very powerful and easy-to-use option is the Hessian binary web service protocol. The binary aspect of Hessian delivers excellent performance, and its native integration within Java allows you to expose remote services purely via a regular Java interface.

Hessian's most rewarding feature, though, is the ability to pass full Java POJO object graphs from one process to another easily without the overhead of XML marshalling, an unfortunate side effect of SOAP web services. Also, Hessian is implemented in a variety of different languages, so you theoretically can execute efficient binary remoting between Java and Python or Java and C# as well.

This article walks through using the Hessian protocol as an alternative to the more widely accepted RMI, XML/SOAP, and REST/JSON approaches for remote communication. It also explains how to integrate Spring and Hessian and then create Hessian components as simple Java objects.

Basic Hessian Example

The basic Hessian setup is quite simple. You first need to externalize all the API interfaces and POJOs shared between the two endpoints into a separate JAR library, which will not contain any of the API implementation, just the interface (i.e., the contract). On the server side, Hessian provides a special HessianServlet, which you can extend to provide and expose the interface implementation. On the client side, you can use a HessianProxyFactory object to generate a local proxy of the interface from a mere URL.

The basic example from the Hessian web site illustrates this setup as follows:

Interface (shared across client and server):
public interface BasicAPI {
     public String hello();
Server implementation:
public class BasicService extends HessianServlet implements BasicAPI {
  private String _greeting = "Hello, world";
  public void setGreeting(String greeting)
    _greeting = greeting;
  public String hello()
    return _greeting;
String url = "http://hessian.caucho.com/test/test";

HessianProxyFactory factory = new HessianProxyFactory();
BasicAPI basic = (BasicAPI) factory.create(BasicAPI.class, url);

System.out.println("hello(): " + basic.hello());
If you have done the wsdl2java and java2wsdl Ant dance when exposing services via XML/SOAP, you surely will appreciate this straightforward path to implementing a Hessian-based web service. It's just 100% pure Java with some magic behind the scenes to tie it all together.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date