Hessian 发布服务及客户端实现

服务接口:

package com.test;

public interface TFSFacade {

String sayHello(String username);

}


业务实现:
package com.test;

public class TFSFacadeImpl implements TFSFacade {

public String sayHello(String username) {
return "Hello, " + username;
}
}


web.xml 配置信息:
	
<servlet>
<servlet-name>hessian</servlet-name>
<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<param-name>home-class</param-name>
<param-value>com.test.TFSFacadeImpl</param-value>
</init-param>
<init-param>
<param-name>home-api</param-name>
<param-value>com.test.TFSFacade</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>hessian</servlet-name>
<url-pattern>/hessian/tfs.xsp</url-pattern>
</servlet-mapping>


客户端调用:


package com.test;

import java.net.MalformedURLException;

import com.caucho.hessian.client.HessianProxyFactory;

public class Main {

/**
* @param args
* @throws MalformedURLException
*/
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub

String target = "http://localhost:8080/TFS/hessian/tfs.xsp";

HessianProxyFactory factory = new HessianProxyFactory();
TFSFacade client = (TFSFacade) factory.create(TFSFacade.class, target);

System.out.println(client.sayHello("美女"));
}

}


结果输出:

Hello, 美女
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值