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
package com.geeksforgeeks;
public interface Calculation {
int cube( int number);
}
|
B. File: CalculationImpl.java
Java
package com.geeksforgeeks;
public class CalculationImpl implements Calculation {
public int cube( int 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" ?>
< bean id = "calculationBean"
class = "com.geeksforgeeks.CalculationImpl" >
</ bean >
< bean name = "/Calculation.http" class = "org.springframework.remoting.caucho.BurlapServiceExporter" >
< property name = "service" ref = "calculationBean" ></ property >
< property name = "serviceInterface" value = "com.geeksforgeeks.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" ?>
< bean id = "calculationBean" class = "org.springframework.remoting.caucho.BurlapProxyFactoryBean" >
< property name = "serviceInterface" value = "com.geeksforgeeks.Calculation" ></ property >
</ bean >
</ beans >
|
F. File: Client.java
This class gets the instance of Calculation and calls the cube method.
Java
package com.geeksforgeeks;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Client {
public static void main(String[] args)
{
ApplicationContext context
= new ClassPathXmlApplicationContext(
"client-beans.xml" );
Calculation calculation
= (Calculation)context.getBean(
"calculationBean" );
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.
Feeling lost in the vast world of Backend Development? It's time for a change! Join our
Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
- Comprehensive Course
- Expert Guidance for Efficient Learning
- Hands-on Experience with Real-world Projects
- Proven Track Record with 100,000+ Successful Geeks
Last Updated :
24 Mar, 2022
Like Article
Save Article