Hessian RPC实例

1.hessian-demo-api

package com.weizhi.hessian.demo.api;

/**
 * @ClassName IRpcService
 * @Description TODO
 * @Author weizhi2018
 * @Date 2013-9-27 下午02:58:46
 * 
 */

public interface IRpcService {
	public String deal(String data);
}

2.hessian-demo-server

用tomcat6发布服务

package com.weizhi.hessian.demo.server;

import com.caucho.hessian.server.HessianServlet;
import com.weizhi.hessian.demo.api.IRpcService;

/**
 * @ClassName RpcServer
 * @Description TODO
 * @Author weizhi2018
 * @Date 2013-9-27 下午02:59:43
 * 
 */

public class RpcServerImpl extends HessianServlet implements IRpcService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/*
	 * @see com.weizhi.hessian.demo.api.IRpcService#deal(java.lang.String)
	 */
	public String deal(String data) {
		if (data == null || "".equals(data))
			return "[Invalid Parameter]";
		return "[Tested," + data + "]";
	}

}

web.xml
<?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>service</servlet-name>
		<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
		<init-param>
			<param-name>service-class</param-name>
			<param-value>com.weizhi.hessian.demo.server.RpcServerImpl</param-value>
		</init-param>
		<init-param>
			<param-name>service-api</param-name>
			<param-value>com.weizhi.hessian.demo.api.IRpcService</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>service</servlet-name>
		<url-pattern>/service</url-pattern>
	</servlet-mapping>

	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>

3.hessian-demo-client


package com.weizhi.hessian.demo.client;

import java.net.MalformedURLException;

import com.caucho.hessian.client.HessianProxyFactory;
import com.weizhi.hessian.demo.api.IRpcService;

/**
 * @ClassName RpcClient
 * @Description TODO
 * @Author weizhi2018 
 * @Date 2013-9-27 下午05:55:09 
 *
 */

public class RpcClient {

	/**
	 * @throws MalformedURLException  
	 * @Title main 
	 * @Description TODO
	 * @Author weizhi2018 
	 * @param args        
	 * @throws 
	 */

	public static void main(String[] args) throws MalformedURLException {
		String url = "http://localhost:8080/hessian-demo-server/service";

		HessianProxyFactory factory = new HessianProxyFactory();
		IRpcService service = (IRpcService) factory.create(IRpcService.class, url);
		
		String data1 = "weizhi2018";
		System.out.println("return:" + service.deal(data1));
		
		String data2 = "";
		System.out.println("return:" + service.deal(data2));
	}

}

4. hessian-4.0.7.jar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值