什么是Hessian
The Hessian binary web service protocol makes web services usable without requiring a large framework, and without learning yet another alphabet soup of protocols. Because it is a binary protocol, it is well-suited to sending binary data without any need to extend the protocol with attachments.
Hessian版HelloWorld
1. 创建基于Maven的web项目
2. pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>user.project</artifactId> <groupId>com.tom</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>learn.hessian</artifactId> <dependencies> <dependency> <groupId>com.caucho</groupId> <artifactId>hessian</artifactId> <version>4.0.38</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <!--jetty plugin to manage embedded jetty--> <!--No goal is specified--> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.7</version> <configuration> <connectors> <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> <port>8668</port> <maxIdleTime>30000</maxIdleTime> </connector> </connectors> <webAppSourceDirectory>${project.basedir}/web </webAppSourceDirectory> <contextPath>/web</contextPath> </configuration> </plugin> </plugins> </build> </project>
上面主要配置了三部分内容,一是依赖的Hessian包,二是Hessian依赖的servlet-api包(Hessian包虽然依赖servlet-api,但在Hessian包的依赖关系中并没有显示的去依赖servlet-api包),三是添加jetty插件,用于启动web项目
3.定义服务器和客户端都会依赖的接口service
在HelloWorld中,没有复杂的Model对象,在实际项目中,服务器端和客户端共同依赖的内容包括模型对象和接口Service
package com.tom.hessian.common; import java.io.IOException; public interface IGreetingService { public String greeting(String name) throws IOException; }
4.定义服务器接口实现
package com.tom.hessian.server; import com.tom.hessian.common.IGreetingService; import java.io.IOException; public class GreetingService implements IGreetingService{ @Override public String greeting(String name) throws IOException { return "Welcome ot the Hassian world, " + name; } }
5. 配置web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <servlet> <servlet-name>hessian</servlet-name> <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class> <init-param> <param-name>home-api</param-name><!--接口声明--> <param-value>com.tom.hessian.common.IGreetingService</param-value> </init-param> <init-param> <param-name>home-class</param-name><!--接口实现--> <param-value>com.tom.hessian.server.GreetingService</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>hessian</servlet-name> <url-pattern>/hessian</url-pattern> </servlet-mapping> </web-app>
6.客户端代码
package com.tom.hessian.client; import com.caucho.hessian.client.HessianProxyFactory; import com.tom.hessian.common.IGreetingService; public class GreetingServiceTest { public static void main(String[] args) throws Exception { //RPC访问地址 String url = "http://localhost:8668/web/hessian"; //接口的动态代理工厂 HessianProxyFactory factory = new HessianProxyFactory(); IGreetingService greetingService = (IGreetingService) factory.create(IGreetingService.class, url); //远程方法调用 System.out.println("hello(), " + greetingService.greeting("tom")); } }
7.运行
启动jetty服务器,运行客户端main方法,得到如下输出,证明远程方法调用成功
hello, welcome ot the Hassian world, tom
相关推荐
java运行依赖jar包
hessian实例,一个HELLOWORLD hessian实例,一个HELLOWORLD hessian实例,一个HELLOWORLD
hessian轻量级 rpc实现
RPC框架的研究,主要是Hessian和其它框架的对比,从性能、易用性等方面着手分析。
一个自己实现的极为简单的RPC框架,可以用来做Hessian等技术框架研究的参考。
Hessian RPC-RMI技术 整合Structs Spring Hibernate Ibatis 包含Hessian配置说明、服务器Server Demo、客户端Client Demo.
如果用tomcat部署服务器,需要hessian的认证,请在E:\tomcat\apache-tomcat-7.0.69\conf\tomcat-users.xml下面配置信息:如下 <role rolename="Hessian"/> 账号" password="密码" roles="Hessian"/>
Java中的RPC框架比较多,各有特色,广泛使用的有RMI、Hessian、Dubbo等。RPC还有一个特点就是能够跨语言,本资源只以JAVA语言里的RPC为例。其他的框架结构也类似,区别在于对象的序列化方法,传输对象的通讯协议,...
java运行依赖jar包
NULL 博文链接:https://wolfsoft.iteye.com/blog/799450
HARPC(High Availability RPC)是基于Thrift的跨语言、高可用的RPC框架。具备高性能、高可用、轻量级等特点 * 跨语言通信 * 方便的使Java、Python、C++三种程序可以相互通信 * 负载均衡和容灾处理 * 方便的实现...
蛇形rpc 一个基于 Hessian 的 RPC 框架( ) “蛇”这个名字来自中国蛇的动物年(2013年)。 与hessian相比,snake-rpc有几个新特点: 能够序列化 InputStream/OutputStream; 无限的 InputStream/OutputStream 参数...
spring springmvc hessian rpc客户端及服务端示例demo,可直接运行,适合hessian入门的同学们学习,仅供有需要的同学们参考
Hessian远程调用框架学习一,第一个JAVA使用hessian的入门demo,简单实用易理解
webservice技术,基于spring+hessian框架开发的简单实例
RPC,全称为RemoteProcedureCall,即远程过程调用,它是一个计算机通信协议。它允许像调用本地服务一样调用远程服务。它可以有不同的实现方式。如RMI(远程方法调用)、Hessian、Http invoker等。另外,RPC是与语言...
hessian简单demo,server发布服务+client调用服务,包含源码和hessian的jar包
SOFARPC是一种高性能,高可扩展性的生产级Java RPC框架。 在Ant Financial中,SOFARPC已经使用了十多年,并且已经发展了五代。 SOFARPC致力于简化应用程序之间的RPC调用,并为应用程序提供方便,无代码入侵,稳定且...
远程方法调用的比较,Hessian方法的介绍和相关配置.Hessian是一个轻量级的remoting on http工具,采用的是Binary RPC协议,所以它很适合于发送二进制数据,同时又具有防火墙穿透能力。Hessian一般是通过Web应用来提供...
Hessian 是一种轻量级的二进制RPC通讯框架,基于HTTP使用servlet 暴漏web service. 本文描述了单独使用和及spring集成使用,并介绍了证书加密,签名及非证书类如DES加密方式. 文尾附官方实例链接.