Hessian使用记录
以前所接觸的rpc一直都是使用resful或者webservice,到了新公司,接觸了另外一種實(shí)現(xiàn)rpc的框架-Hessian。
實(shí)際上hessian是實(shí)現(xiàn)了rmi功能的一個(gè)框架,不同于webservice的soap,hessian是自己給予http協(xié)議實(shí)現(xiàn)的一種rpc協(xié)議。它很輕便,適合傳輸二進(jìn)制數(shù)據(jù)。
服務(wù)端很容易實(shí)現(xiàn),
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
客戶端實(shí)現(xiàn):
demo1:使用HessianProxyFactory
當(dāng)然 也可以用使用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());
總結(jié)
以上是生活随笔為你收集整理的Hessian使用记录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 通过反射执行方法
- 下一篇: Java 标注过期方法 注解: @De