Open In App
Related Articles

Spring – Remoting By Hessian

Improve Article
Save Article
Like Article

We may use the HessianServiceExporter and HessianProxyFactoryBean classes to implement the hessian remoting service. The major advantage of Hessian’s is that Hessian works well on both sides of a firewall. Hessian is a portable language that may be used with other languages like PHP and.Net.

Implementation: To make a simple hessian application, you’ll need to make the following files:

  3. web.xml
  4. hessian-servlet.xml
  5. client-beans.xml

The project structure looks as follows: 

A. File:


// Java Program to illustrate Simple Interface
// Containing one method cube.
package com.geeksforgeeks;
// Interface
public interface Calculation {
    int cube(int number);

B. File:


// Java Program to Illustrate Implementation
// of the Calculation interface
package com.geeksforgeeks;
// Class
// Implementing interface
public class CalculationImpl implements Calculation {
    // Method
    public int cube(int number)
        // Returning cube of a number
        return number * number * number;

C. File: web.xml

The front controller is defined in this XML file called DispatcherServlet. Any request that ends in.http will be routed to DispatcherServlet.


<?xml version="1.0" encoding="UTF-8"?>

D. File: hessian-servlet.xml

It has to be placed in the WEB-INF folder. It must be called servletname-servlet.xml. It specifies CalculationImpl and HessianServiceExporter as beans.


<?xml version="1.0" encoding="UTF-8"?>
    <bean id="calculationBean" class="com.geeksforgeeks.CalculationImpl"></bean>
    <bean name="/Calculation.http" class="org.springframework.remoting.caucho.HessianServiceExporter">
        <property name="service" ref="calculationBean"></property>
        <property name="serviceInterface" value="com.geeksforgeeks.Calculation"></property>

E. File: client-beans.xml

The bean for HessianProxyFactoryBean is defined in this XML file. This class requires two attributes to be defined.

  1. serviceUrl
  2. serviceInterface

F. File:

This class obtains a Calculation object and runs the cube function.


package com.geeksforgeeks;
import org.springframework.context.ApplicationContext;
public class Client 
    public static void main(String[] args) 
        ApplicationContext context = new ClassPathXmlApplicationContext("client-beans.xml");
        Calculation calculation = (Calculation)context.getBean("calculationBean");


 Note: In order to generate the above output,

  • Start and deploy the project, assuming that the server is listening on port 8888. Change the serviceURL in client-beans.xml if the port number is changed.
  • The file should then be compiled and run.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 24 Mar, 2022
Like Article
Save Article
Similar Reads
Complete Tutorials