1.下载hessian包,spring-romote包
2.编写服务端接口,以及实现类(必须要有接口interface,接口调用来的)
2.配置服务端xml 提供servlet请求入扣
3.配置客户端 (此处建议 如果你的客户端比如pc,wap,手机客户端 端不属于你 请勿使用hessian)
4.将服务端要开放的接口以及方法以jar包形式给客户端
下面跟着我来一步一步实现hessian 相当简单
服务端
package com.wyh
//接口
interface ITest{
public String holleHession(String params);
}
//实现类
class Test implements ITest
{
Override
public String holleHession(String params){
system.out.println(params);
}
}
//服务端 http://localhost:8080/test
web.xml
<!-- heesian -->
<servlet>
<servlet-name>tourheesian</servlet-name>
<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>service-class</param-name>
<param-value>com.wyh.Test</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>tourheesian</servlet-name>
<url-pattern>/tourheesian</url-pattern>
</servlet-mapping>
这里需要注意的是 客户端与服务端的hessian包必须是一致的 不然会出现expected integer at 0x53 java.lang.String....的错误
服务端 地址
请求服务端地址为 http://localhost:8080/test
import com.wyh.ITest
public clss testClient {
public static void main (String [] args){
HessianProxyFactory hessian = new HessianProxyFactory();
ITest test = null;
try {
test = (ITest)hessian.create(ITest.class,"http://localhost:8080/test/tourheesian");
system.out.println(test.holleHession("调用成功,就是这么简单"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
spring 配置之后简化
<bean id="test" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8080/51you_tour/tourheesian</value>
</property>
<property name="serviceInterface">
<value>com.wyh.ITest</value>
</property>
</bean>
import com.wyh.ITest
public clss testClient {
public static void main (String [] args){
try {
ITest test = (ITest)BeanUtils.getBean("test");
system.out.println(test.holleHession("调用成功,就是这么简单"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
总结:
刚接触对hessian认识还不是很深,在此就不做多评价。