Coucho can provide both Hessian and Burlap. Burlap is an xml-based Hessian substitute. We may use the BurlapServiceExporter and BurlapProxyFactoryBean classes to implement burlap’s remoting service.
Implementation: You need to create the following files for creating a simple burlap application:
- Calculation.java
- CalculationImpl.java
- web.xml
- burlap-servlet.xml
- client-beans.xml
- Client.java
The project structure will look as follows:
A. File: Calculation.java
Java
// Java Program to illustrate Simple Interface// Containing a Method package com.neveropen; // Interfacepublic interface Calculation { int cube(int number);} |
B. File: CalculationImpl.java
Java
// Java Program to Implement Calculation Interface package com.neveropen; // Class// Implementing interfacepublic 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
<?xml version="1.0" encoding="UTF-8"?><web-app> <servlet> <servlet-name>burlap</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup></servlet> <servlet-mapping> <servlet-name>burlap</servlet-name> <url-pattern>*.http</url-pattern></servlet-mapping> </web-app> |
D. File: burlap-servlet.xml
It has to be placed in the WEB-INF folder. It must be called servletname-servlet.xml. It specifies CalculationImpl and BurlapServiceExporter as beans.
XML
<?xml version="1.0" encoding="UTF-8"?> xsi:schemaLocation="http://www.springframework.org/schema/beans <bean id="calculationBean" class="com.neveropen.CalculationImpl"> </bean> <bean name="/Calculation.http" class="org.springframework.remoting.caucho.BurlapServiceExporter"> <property name="service" ref="calculationBean"></property> <property name="serviceInterface" value="com.neveropen.Calculation"></property> </bean> </beans> |
E. File: client-beans.xml
The bean for BurlapProxyFactoryBean is defined in this XML file. This class requires two attributes to be defined.
- serviceUrl
- serviceInterface
XML
<?xml version="1.0" encoding="UTF-8"?> xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="calculationBean" class="org.springframework.remoting.caucho.BurlapProxyFactoryBean"> <property name="serviceInterface" value="com.neveropen.Calculation"></property> </bean></beans> |
F. File: Client.java
This class gets the instance of Calculation and calls the cube method.
Java
// Java Program to Illustrate Client Class package com.neveropen; // Importing required classesimport org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext; // Classpublic class Client { // Main driver method public static void main(String[] args) { // Creating an object of ApplicationContext class ApplicationContext context = new ClassPathXmlApplicationContext( "client-beans.xml"); Calculation calculation = (Calculation)context.getBean( "calculationBean"); // Printing cube of a random number System.out.println(calculation.cube(3)); }} |
Output:
27
Note: In order to run the above code fragment to get the 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 Client.java file should then be compiled and run.

