Browse DevX
Sign up for e-mail newsletters from DevX


Spring and Hessian for Fast, Easy Java Remoting : Page 3

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.


Setting Up the Client

On the client side, you need to create an instance of a HessianProxyFactoryBean that points to your service URL:
<beans xmlns="http://www.springframework.org/schema/beans"
> <context:annotation-config /> <context:component-scan base-package="com.devx.hessian.client" /> <bean id="personService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean"> <property name="serviceUrl" value="" /> <property name="serviceInterface" value="com.dexv.hessian.IPersonService" /> </bean> </beans>
When your service URL is defined, you can just inject the HessianProxyFactoryBean instance into your client application using regular dependency injection:
public class MainClient {

   private IPersonService service = null;
   public void setPersonService(@Qualifier("personService") IPersonService service) {
      this.service = service;

Spring 2.5 and Hessian 2 Incompatibility Alert

As of version 3.2.0, the Hessian library started using a new version of the protocol called simply Hessian 2. Unfortunately, the current production version of Spring (namely 2.5.6.SEC01) has support for the original Hessian protocol only. Therefore, if you are on Spring 2.5, the version of Hessian that you should download is 3.1.6.

Fortunately, this has been corrected in the latest milestone builds of Spring 3.0. The code samples attached to this article use the latest Hessian 4.0.1 and Spring 3.0 M4 builds.

Jacek Furmankiewicz is a Senior Java EE and Erlang/OTP developer at Radialpoint. He has 15 years of professional IT experience and is a Sun Certified Java Programmer (SCJP).
Thanks for your registration, follow us on our social networks to keep up-to-date