English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Spring Remote Processing (Through Burlap Example)

Houssian and Burlap are both provided by Coucho.

With the help of BurlapServiceExporter and BurlapProxyFactoryBean Class, we can implement the remote service provided by Burlap. The Burlap example is the same as Burlap, you just need to change Burlap to Burlap.

Example of remote processing through Burlap

You need to create the following files to create a simple Burlap application:

Calculation.java CalculationImpl.java web.xml burlap-servlet.xml client-beans.xml Client.java

1、Calculation.java

This is a simple interface containing a method for multi-dimensional datasets.

package com.w3codebox;
public interface Calculation {
int cube(int number);
}

2、CalculationImpl.java

This class provides the implementation of the Calculation interface.

package com.w3codebox;
public class CalculationImpl implements Calculation{
    public int cube(int number) {
        return number*number*number;
    }
}

3、web.xml

In this xml file, we define DispatcherServlet as the front controller. If any request follows the .http extension, it will be forwarded to DispatcherServlet.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  
    <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>

4and burlap-servlet.xml

It must be in the WEB-in the INF folder. Its name must be servletname-servlet.xml. It creates CalculationImpl and BurlapServiceExporter defines the bean.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd">
    
<bean id="calculationBean" class="com.w3codebox.CalculationImpl"></bean>
<bean name="/Calculation.http" 
class="org.springframework.remoting.caucho.BurlapServiceExporter">
    <property name="service" ref="calculationBean"></property>
    <property name="serviceInterface" value="com.w3codebox.Calculation"></property>
</bean>
</beans>

5、client-beans.xml

In this xml file, we define BurlapProxyFactoryBean defines the bean. You need to define two properties of this class.

serviceUrl serviceInterface

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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="serviceUrl" 
         value="http://localhost:8888/burlap/Calculation.http"></property>
    <property name="serviceInterface" value="com.w3codebox.Calculation"></property>
</bean>
</beans>

In this example, the name of our project is MaBu, which is used as the context root in the serviceURL.


6、Client.java

This class gets an instance of Calculation and calls the multidimensional dataset method.

package com.w3codebox;
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));
 }
}

How to Run This Example

Start and deploy the project, here we assume the server is8888running on the port number. If the port number is different, please change the client-serviceURL in beans.xml.

Then, compile and run the Client.java file.