Hessian使用记录

来源:互联网 发布:西门子编程实例精解 编辑:程序博客网 时间:2024/06/06 11:04

以前所接触的rpc一直都是使用resful或者webservice,到了新公司,接触了另外一种实现rpc的框架-Hessian。

实际上hessian是实现了rmi功能的一个框架,不同于webservice的soap,hessian是自己给予http协议实现的一种rpc协议。它很轻便,适合传输二进制数据。

服务端很容易实现,

demo1:

<servlet>
<servlet-name>hessian</servlet-name>
<servletclass>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<param-name>service-class</param-name>
<param-value>com.cxf.service.IbaseImpl</param-value>
</init-param>
</servlet>


<servlet-mapping>
<servlet-name>hessian</servlet-name>
<url-pattern>/hessian</url-pattern>
</servlet-mapping>


demo2:集成spring



客户端实现:

demo1:使用HessianProxyFactory


当然 也可以用使用HessianProxyFactoryBean 

demo2:


<bean id="clientSpring" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
               <value>http://localhost:8080/hessian/helloSpring</value>
</property>
<property name="serviceInterface">
<value>com.cxf.service.Ibase</value>
</property>
</bean>

              ApplicationContext contex = new ClassPathXmlApplicationContext("applicationContext.xml");
// 获得客户端的Hessian代理工厂bean
Ibase i = (Ibase ) contex.getBean("clientSpring");
User user=ibase.baseMethod("cuixuefeng","12",new User());
                     System.out.println(user.getException().getMessage());
                     System.out.println(user.getUsername());

0 0
原创粉丝点击