Burlap开发学习

Burlap 简介
Burlap也是有caucho提供,它和hessian的不同在于,它是基于XML-RPC协议的。
1、是基于什么协议实现的?
基于XML-RPC协议实现。
2、怎么发起请求?
根据Burlap提供的API。
3、怎么将请求转化为符合协议的格式的?
将请求信息转化为符合协议的XML格式,转化为流进行传输。
4、使用什么传输协议传输?
Http协议。
5、响应端基于什么机制来接收请求?
监听Http请求。
6、怎么将流还原为传输格式的?
根据XML-RPC协议进行还原。
7、处理完毕后怎么回应?
返回结果写入XML中,由Burlap返回至调用端。

声明服务端接口:

package com.easyway.caucho.burlap.ws;

import java.util.List;

/**
 * 声明服务端相关的服务
 * 
 * @author longgangbai
 * 
 */
public interface BurlapService {

	public String getUserName();

	public List<String> getList();

	public void setGreeting(String greeting);

	public String hello();

}

 实现服务端的服务代码示例如下:

package com.easyway.caucho.burlap.ws;

import java.util.ArrayList;
import java.util.List;

import com.caucho.burlap.server.BurlapServlet;

/**
 * 
 * 在Burlap中服务端的必须继承BurlapServlet 类同时实现相关的服务的接口
 * 
 * @author longgangbai
 * 
 */
public class BurlapWS extends BurlapServlet implements BurlapService {
	private String _greeting = "Hello, world";

	/** 
	 *  
	 */
	public void setGreeting(String greeting) {
		_greeting = greeting;
	}

	/**
	 *
	 */
	public String hello() {
		return _greeting;
	}

	/** 
	 *  
	 */
	public List<String> getList() {
		List<String> strList = new ArrayList<String>();
		strList.add("a");
		strList.add("c");
		strList.add("b");
		strList.add("d");
		strList.add("e");
		strList.add("g");
		strList.add("h");
		strList.add("j");
		strList.add("k");
		strList.add("l");
		strList.add("q");
		return strList;
	}

	/**
	 * 
	 */
	public String getUserName() {
		return _greeting;
	}

}

 

客户端访问代码如下:

package com.easyway.caucho.burlap.ws;

import java.net.MalformedURLException;

import com.caucho.burlap.client.BurlapProxyFactory;

/**
 * Burlap客户端测试代码
 * 
 * @author longgangbai
 * 
 */
public class BurlapServiceWSClient {
	public static void main(String[] args) {
		String url = "http://localhost:8080/BurlapWS/remoting/burlapWs";

		BurlapProxyFactory factory = new BurlapProxyFactory();
		BurlapService basic;
		try {
			basic = (BurlapService) factory.create(BurlapService.class, url);

			System.out.println("hello(): " + basic.getUserName());
			System.out.println("getList(): " + basic.getUserName());

		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

 

web.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
	<display-name>BurlapDemo</display-name>
	<servlet>
		<servlet-name>burlapWs</servlet-name>
		<servlet-class>com.easyway.caucho.burlap.ws.BurlapWS</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>burlapWs</servlet-name>
		<url-pattern>/remoting/burlapWs</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>

 

你可能感兴趣的:(Web,xml,servlet,javaee,sun)