下载地址: http://sourceforge.net/projects/hessiankit/
介绍:http://www.jayway.com/2008/07/10/hessiankit-released/
协议介绍 http://hessian.caucho.com/
HessianKit
HessianKit is a Framework for Objective-C 2.0 to allow Mac OS X 10.5, and iPhone 2.0 applications to seamlessly communicate with hessian web services.
HessianKit provided typed proxy objects to formward calls to, and and handle responses from any hessian web service, seamlessly just as if they where local objects. HessianKit also provide functionality to automatically generate classes for published value objects. Both web service proxies and value objects are defined as basic Objective-C Protocols.
Unless the client uses custom value objects, CWHessianConnection
is the only class in HessianKit that is needed to be created directly. Instances of CWDistantHessianObject
are fetched from CWHessianConnection
using proxyWithURL:protocol:
. If custom value objects are needed use the CWValueObject
to realize objects using protocol definitions, or implement classes conforming to CWNSCoding
protocol.
If the web service exposes the following Java-interface:
public interface Service { int getPersonCount(); Person getPerson(int index); }
Then the Objective-C client would define the service Protocol as this:
@protocol Service -(int)getPersonCount; -(id<Person>)getPerson:(int)index; @end
Assumin Person
is a value object defined as this in Java:
public class Persson implements Serializable { private int age; private String name; public Person(int age, String name) { setAge(age); setName(name); } public int getAge() { return age; } public void setAge(int v) { age = v; } public String getName() { return name; } public void setName(String v) { name = v; } }
The Objective-C client would define the same value object as a Protocol like this:
@protocol Person @property(assign, nonatomic) int age; @property(retain, nonatomic) NSString* name; @end
Value object from the web service will automatically be created as a subclas of CWValueObject
if the class name matches a defined protocol. Value object to be sent to the web service can be created useing the class method valueObjectWithProtocol:
of CWValueObject
, or by using any class conforming to NSCoding
.
Given the above example the code to get all available persons and write their age and name to logs, could be wimplemented as this:
NSURL* url = [URL URLWithString:@"http:/someserver.org/hessianservice"]; id<Service> proxy = [CWHessianConnection rootProxyWithURL:url protocol:@protocol(Service)]; int count = [proxy getPersonCount]; for (int index = 0; index < count; index++) { id<Person> person = [proxy getPerson:index]; NSLog(@"age: %d name: %@", person.age, person.name); }
Since Java and Objective-C differ in the naming of methods, some translation must be done when sending call tho the hessian web service. Method names are first looked up using the class method methodNameForSelector:
of CWHessianArchiver
, if a method name is not returned, the method name to use will be generated with these steps:
- Split the selector name on ':' delimiter character.
- Capitalize first charcter of all splitted parts but the first.
- Join splitted parts without delimiter.
- If method takes one or more arguments the nme is mangled by appending "__#" where # is the number of arguments.
Some examples of method tranlsations:
Objective-C Java doFoo
doFoo
getFoo:
getFoo__1
doFoo:bar:
doFooBar__2
doUgly:::
doUgly__3
Many Objective-C constructs feels alien in Java and vice versa, therefor non-automatic method translation can somethimes be prefered, in the above interface
Service
the method namedperson
is not good looking Objective-C, albeit acceptable Java. To add a manual translation just do:[CWHessianArchiver setMethodName:@"getPersonCount" forSelector:@selector(personcount)]; [CWHessianArchiver setMethodName:@"getPerson" forSelector:@selector(personAtIndex:)];
And change the Objective-C Protocol accordingly:
@protocol Service -(int)personCount; -(id<Person>)personAtIndex:(int)index; @end
And now the much more Objective-C friendly code can be written:
NSURL* url = [URL URLWithString:@"http:/someserver.org/hessianservice"]; id<Service> proxy = [CWHessianConnection proxyWithURL:url protocol:@protocol(Service)]; int count = [proxy personCount]; for (int index = 0; index < count; index++) { id<Person> person = [proxy personAtIndex:index]; NSLog(@"age: %d name: %@", person.age, person.name);
相关推荐
Hessian jar包通常包含了实现Hessian协议所需的类库,使得开发者能够在Java应用程序中使用Hessian进行服务调用。 在本例中,提供的"Hessian的jar包.zip"包含了一个名为"hessian的4.0.33.jar"的文件,这是Hessian的...
本文将深入探讨Hessian的核心概念、工作原理,并提供一个简单的使用示例。 ### Hessian核心概念 1. **二进制序列化**:Hessian使用高效的二进制格式进行序列化和反序列化,与XML或JSON相比,这种格式的数据体积更...
1. **配置Spring**:在Spring的配置文件中定义Hessian服务的bean,通过`<bean>`标签声明服务接口和其实现类,使用`hessian-proxy-factory-bean`来创建Hessian服务的代理。 2. **暴露Hessian服务**:通过Spring的`...
这个jar包可以被Java应用程序引用,以便使用Hessian进行服务调用或者提供Hessian服务。它提供了序列化和反序列化机制,使得Java对象可以通过网络高效地传输。Hessian支持多种类型的数据交换,包括基本数据类型、复杂...
3. **Hessian服务暴露**:使用Spring的AOP(面向切面编程)和HessianProxyFactoryBean,将服务接口暴露为Hessian服务。这样,客户端可以通过HTTP请求调用这些服务。 4. **配置Hibernate**:在Spring配置文件中设置...
在使用这些Hessian版本时,开发者还需要关注如何正确地配置和集成到自己的项目中。这包括设置服务器端和客户端的Hessian服务,定义服务接口,处理序列化和反序列化的过程,以及调试可能出现的问题。在进行版本升级时...
在IT行业中,尤其是在移动开发领域,Hessian是一种广泛使用的二进制协议,它允许远程对象调用(Remote Object Invocation)。本知识点主要关注的是在Android平台上,如何使用Hessian进行异步请求访问,以便提高应用...
1. **添加依赖**:首先,客户端和服务端都需要引入Hessian的jar包,以便使用其提供的API和功能。 2. **服务端设置**:在服务端,需要定义业务接口,并创建该接口的实现类。这个实现类需要继承`HessianServlet`,...
在测试过程中,可以利用`hkcss-client-1.0-SNAPSHOT.jar`和`hkss-common-1.0-SNAPSHOT.jar`来构建客户端,使用`hessian-4.0.7.jar`作为基础通信库,然后参照`新建文本文档.txt`的说明进行配置和执行测试。...
2. 处理结果:服务器执行完方法后,返回的数据会通过Hessian协议反序列化成对象,Android客户端可以直接使用。 五、错误处理与调试 1. 异常处理:在调用远程方法时,可能会出现网络异常或服务器异常,需要捕获并...
本教程将详细介绍C#中Hessian的使用及其相关知识点。 首先,Hessian协议设计的目标是简洁高效,它能将常见的数据类型如字符串、整型、浮点型等转换为二进制格式,从而在网络传输时占用更少的带宽。这种协议特别适合...
现在,让我们通过一个简单的Java示例来了解如何使用Hessian。在这个例子中,我们将创建一个服务器端服务并暴露一个方法,然后在客户端调用这个远程方法。 1. 首先,我们需要在服务器端定义一个服务接口和实现类。...
4. **创建 Hessian 客户端**:在需要调用服务的客户端应用中,使用 Hessian 工具类或客户端库创建一个 Hessian Proxy,通过 URL 调用远程服务。 5. **测试服务调用**:编写测试代码,验证 Hessian 客户端是否能成功...
与其他基于XML的RPC协议(如SOAP)相比,Hessian更简洁、快速,因为它使用了二进制编码,而非文本格式。 **一、Hessian协议基础** 1. **二进制编码**:Hessian使用高效的二进制编码,对数据类型进行压缩,减少了在...
首先,`hessian-4.0.7.jar`文件是预编译的Hessian库,可以直接在Java项目中使用。它提供了各种类和接口,如`com.caucho.hessian.io.Hessian2Input`和`com.caucho.hessian.io.Hessian2Output`,用于序列化和反序列化...
对于Java项目,可以通过Maven或Gradle添加Hessian的jar包。例如,在Maven的pom.xml文件中添加如下依赖: ```xml <groupId>com.caucho</groupId> <artifactId>hessian <version>4.0.65 ``` ### 创建Hessian...
java hessian-3.0.38.jar。修改了原生的jar包,解决了hessian 序列化BigDecimal的精度问题。注意,请在hessian服务端和客户端中分别替换此jar包哦!! 只替换服务端hessian jar包还是会有问题。
远程方法调用的比较,Hessian方法的介绍和相关配置.Hessian是一个轻量级的remoting on http工具,...只是它不使用SOAP协议,但相比webservice而言更简单、快捷。这个文件可以是hessian在spring项目和web项目的简单配置
Hessian是一种高效的二进制序列化协议,常用于...通过使用Hessian,开发者可以轻松地构建分布式系统,实现服务之间的便捷调用。案例中的文件提供了不同角度的分析和实践指导,帮助我们更好地理解和应用Hessian技术。
4. 在客户端,通过Spring的`HessianClientInterceptor`或者直接使用`HessianProxyFactory`来创建Hessian代理,调用远程服务。 5. 配置服务器端(如Tomcat)以部署Spring应用上下文和Hessian服务。 6. 运行并测试服务...