原文地址:http://www.studytrails.com/frameworks/spring/spring-remoting-burlap.jsp

Concept Overview

In the earlier tutorials we saw an introduction to Spring remoting and its support for RMI and Hessian. In this tutorial we look at another remoting protocol supported by Spring - Burlap. Burlap is an XML based protocol for web services. It has been developed by Caucho. It is similar to Hessian, the only difference being Hessian is binary and Burlap is XML. Like Hessian, Burlap needs to be hosted over HTTP. Similar to Hessian, it has a BurlapServiceExporter and a BurlapProxyFactoryBean class. Note that since Burlap is not being actively developed, its support has been deprecated since Spring 4.0.

Sample Program Overview

The sample program below is a Greeting Service and demonstrates Spring support for Burlap. 

Required Libraries
  • aopalliance.jar
  • commons-logging.jar
  • log4j.jar
  • org.springframework.aop.jar
  • org.springframework.asm.jar
  • org.springframework.beans.jar
  • org.springframework.context.jar
  • org.springframework.context.support.jar
  • org.springframework.core.jar
  • org.springframework.expression.jar
  • org.springframework.web.jar
  • org.springframework.web.servlet.jar
  • hessian-3.1.5.jar
Interaction Flow

  • Client sends a message call
  • This message call is handled by a Burlap Proxy created by BurlapProxyFactoryBean
  • The Burlap Proxy converts the call into a remote call over HTTP
  • The Burlap Service Adapter created by BurlapServiceExporter intercepts the remote call over HTTP
  • It forwards the method call to Service
Burlap Server Code Package Structure

Burlap Server Source Code

Create the GreetingService interface as shown below. 
Create a method named getGreeting() that takes a name as a parameter and returns the greeting message (see line 5 below).

GreetingService.java
1
2
3
4
5
6
package com.studytrails.tutorials.springremotingburlapserver;
 
public interface GreetingService {
 
String getGreeting(String name);
}

Create a class GreetingServiceImpl as shown below. 
It implements the GreetingService interface (described earlier) 
Implement the getGreeting() method by sending a greeting message (see lines 6-8 below).

GreetingServiceImpl.java
1
2
3
4
5
6
7
8
9
10
package com.studytrails.tutorials.springremotingburlapserver;
 
public class GreetingServiceImpl implements GreetingService{
 
@Override
public String getGreeting(String name) {
return "Hello " + name + "!";
}
 
}

Create the burlap-servlet.xml file (see below).

Declare the 'greetingService' (see lines 14-15 below).

Export the 'greetingService' using Spring's BurlapServiceExporter class (see lines 17-21 below). 
Note the following properties of BurlapServiceExporter class:

  • service: the service class bean which shall handle the Burlap call (see line 18 below)
  • serviceInterface: The interface to be used by Spring to create proxies for Burlap (see line 19 below)
burlap-servlet.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="UTF-8" ?>
 
 
 
<bean id="greetingService"
class="com.studytrails.tutorials.springremotingburlapserver.GreetingServiceImpl" />
 
<bean name="/greetingService.http"
class="org.springframework.remoting.caucho.BurlapServiceExporter">
<property name="service" ref="greetingService" />
<property name="serviceInterface" value="com.studytrails.tutorials.springremotingburlapserver.GreetingService"/>
</bean>
</beans>

Create the web.xml file (see below).

Create the servlet mapping for the url pattern '*.http' (see line 16 below) for Spring's DispatcherServlet (see line 10 below)

web.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 
<web-app>
<display-name>Spring Remoting: Burlap Server</display-name>
 
<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>
Burlap Client Code Package Structure

Burlap Client Source Code

Create the GreetingService interface as shown below. 
Copy the GreetingService interface created for Burlap Server (described above) and paste it in Burlap Client source code while retaining the java package structure.

Note: For reference, the source code is shown below.

GreetingService.java
1
2
3
4
5
6
package com.studytrails.tutorials.springremotingburlapserver;
 
public interface GreetingService {
 
String getGreeting(String name);
}

Create a class TestSpringRemotingBurlap shown below to test Spring Burlap Remoting. 
Load spring configuration file (see line 11 below) 
Get a reference to GreetingService using the bean name 'greetingService' (see line 12 below) 
Call the GreetingService.getGreting() method by passing the name 'Alpha' (see line 13 below) 
Print the greeting message (see line 14 below).

TestSpringRemotingBurlap.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package com.studytrails.tutorials.springremotingburlapclient;
 
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
 
import com.studytrails.tutorials.springremotingburlapserver.GreetingService;
 
public class TestSpringRemotingBurlap {
 
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-client.xml");
GreetingService greetingService = (GreetingService)context.getBean("greetingService");
String greetingMessage = greetingService.getGreeting("Alpha");
System.out.println("The greeting message is : " + greetingMessage);
}
}

Create the spring-config-client.xml file (see below). 
Declare the 'greetingService' using Spring's BurlapProxyFactoryBean class (see lines 13-16 below). 
Note the following properties of BurlapProxyFactoryBean class:

  • serviceUrl : refers the URL of the remote service (see line 14 below). 
    Note URL part 'greetingService' corresponds to bean name property of BurlapServiceExporter bean defined in burlap-servlet.xml (defined earlier)
  • serviceInterface: The interface to be used by Spring to create proxies for Burlap (see line 15 below)
spring-config-client.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation="
 
<bean id="greetingService" class="org.springframework.remoting.caucho.BurlapProxyFactoryBean">
<property name="serviceInterface" value="com.studytrails.tutorials.springremotingburlapserver.GreetingService"/>
</bean>
 
</beans>
Running Sample Program
Burlap Server Sample Program

This sample program has been packaged as a jar installer which will copy the source code (along with all necessary dependencies)on your machine and automatically run the program for you as shown in the steps below. To run the sampleprogram, you only need Java Runtime Environment (JRE) on your machine and nothing else.

Download And Automatically Run Burlap Server Sample Program
  • Save the springremotingburlapserver-installer.jar on your machine
  • Execute/Run the jar using Java Runtime Environment


(Alternatively you can go the folder containing the springremotingburlapserver-installer.jar and execute the jar using java -jar springremotingburlapserver-installer.jar command)

  • You will see a wizard page as shown below

  • Enter the location of the directory where you want the program to install and run (say, C:\Temp)

  • The installer will copy the program on your machine and automatically execute it. The expected output indicating that the program has run successfully on your machine is shown in the image below. 
    This shows that the Burlap Server program has run successfully on your machine

Burlap Client Sample Program

This sample program has been packaged as a jar installer which will copy the source code (along with all necessary dependencies)on your machine and automatically run the program for you as shown in the steps below. To run the sampleprogram, you only need Java Runtime Environment (JRE) on your machine and nothing else.

Download And Automatically Run Burlap Client Sample Program
  • Save the springremotingburlapclient-installer.jar on your machine
  • Execute/Run the jar using Java Runtime Environment


(Alternatively you can go the folder containing the springremotingburlapclient-installer.jar and execute the jar using java -jar springremotingburlapclient-installer.jar command)

  • You will see a wizard page as shown below

  • Enter the location of the directory where you want the program to install and run (say, C:\Temp)

  • The installer will copy the program on your machine and automatically execute it. The expected output indicating that the program has run successfully on your machine is shown in the image below. 
    This shows that the Burlap Client program has run successfully on your machine

Browsing the Program
Burlap Server Sample Code

This source code for this program is downloaded in the folder specified by you (say, C:\Temp) as an eclipse project called springremotingburlapserver . All the required libraries have also been downloaded and placed in the same location. You can open this project from Eclipe IDE and directly browse the source code. See below for details of the project structure.

Redeploying this sample program in a different web server

The WAR file for this example is available as springremotingburlapserver.war in the download folder specified by you earlier (e.g. C:\Temp). The path for the WAR file is <DOWNLOAD_FOLDER_PATH>/springremotingburlapserver/dist/springremotingburlapserver.war. 
This WAR file can be deployed in any webserver of your choice and example can be executed. 

Burlap Client Sample Code

This source code for this program is downloaded in the folder specified by you (say, C:\Temp) as an eclipse project called springremotingburlapclient . All the required libraries have also been downloaded and placed in the same location. You can open this project from Eclipe IDE and directly browse the source code. See below for details of the project structure.

Spring Remoting: Burlap--转的更多相关文章

  1. Spring Remoting: Remote Method Invocation (RMI)--转

    原文地址:http://www.studytrails.com/frameworks/spring/spring-remoting-rmi.jsp Concept Overview Spring pr ...

  2. Spring Remoting: HTTP Invoker--转

    原文地址:http://www.studytrails.com/frameworks/spring/spring-remoting-http-invoker.jsp Concept Overview ...

  3. Lingo (Spring Remoting) : Passing client credentials to the server

    http://www.jroller.com/sjivan/entry/lingo_spring_remoting_passing_client Lingo (Spring Remoting) : P ...

  4. Spring Remoting: Hessian--转

    原文地址:http://www.studytrails.com/frameworks/spring/spring-remoting-hessian.jsp Concept Overview The p ...

  5. Asynchronous calls and remote callbacks using Lingo Spring Remoting

    http://www.jroller.com/sjivan/entry/asynchronous_calls_and_callbacks_using Asynchronous calls and re ...

  6. Spring Remoting by HTTP Invoker Example--reference

    Spring provides its own implementation of remoting service known as HttpInvoker. It can be used for ...

  7. spring remoting源码分析--Hessian分析

    1. Caucho 1.1 概况 spring-remoting代码的情况如下: 本节近分析caucho模块. 1.2 分类 其中以hession为例,Hessian远程服务调用过程: Hessian ...

  8. Spring Remoting: Hessian

  9. spring源码分析之spring-web remoting模块概况及基本概念

    spring-web总体分为三部分:caucho.httpinvoker.jaxws,其总体构造图如下: uml结构: 先看看网上搜索到的上述实现的原理吧:Spring RMI,Hessian/Bur ...

随机推荐

  1. 将数据导出到Excel2007格式。

    增加数据格式 public static void TableToExcel2(DataTable table, string filename, string sheetname) { XSSFWo ...

  2. chrome诡异的Provisional headers are shown

    昨天吐槽了cocos2d-js的问题,所以就准备调研几个其它HTML5引擎,发现PIXI性能极高,但是没有音频.而Phaser.js是在PIXI.js的基础之上进行的封装.而国内有一家公司,开发一个叫 ...

  3. 漫谈Puppet4

    激动人心的改进 速度,速度,还是速度 稳定性和鲁棒性的提升 全新的Parser “不变"的agent 不兼容的改动 包管理方式的变化 配置文件/目录的路径变化 其他路径变化 Director ...

  4. MySQL 学习用employee数据库表参考使用

    download place:https://launchpad.net/test-db/ ,choose this file from the right panel:employees_db-fu ...

  5. 《STL系列》之vector原理及实现

    最近忙得蛋疼,但还是想写点属于自己的东西.也不知道写点啥,最后决定试着自己实现STL中常用的几个集合,一来加深自己对STL的理解,二来看看自己是否有这个能力实现.实现目标就是:1能和STL兼容:2最大 ...

  6. Jmeter之JDBC Request使用方法(oracle)

    JDBC Request: 这个sampler可以向数据库发送一个jdbc请求(sql语句),它经常需要和JDBC Connection Configuration 配置元件一起配合使用. 目录: 一 ...

  7. 初始zookeeper与集群搭建实例

    zookeeper是什么 Zookeeper,一种分布式应用的协作服务,是Google的Chubby一个开源的实现,是Hadoop的分布式协调服务,它包含一个简单的原语集,应用于分布式应用的协作服务, ...

  8. Scala 深入浅出实战经典 第39讲:ListBuffer、ArrayBuffer、Queue、Stack操作代码实战

    王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-64讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...

  9. C#版Windows服务安装卸载小工具-附源码

    前言 在我们的工作中,经常遇到Windows服务的安装和卸载,在之前公司也普写过一个WinForm程序选择安装路径,这次再来个小巧灵活的控制台程序,不用再选择,只需放到需要安装服务的目录中运行就可以实 ...

  10. bash的循环中无法保存变量

    在bash中,如果循环在一个子shell中运行,那么在循环中对循环外面的变量的更改将在循环退出后不可见.像下面的例子: #!/bin/sh python run.py | while read lin ...