HessianKit Released

Fredrik Olsson

HessianKit, an implementation of the Hessian binary web service protocol for Objective-C 2.0 have now been released under Apache License 2. It is available on sourceforge at:
http://sourceforge.net/projects/hessiankit

HessianKit is available for Mac OS X 10.5 and later, and iPhone OS 2.0. The three main goals are:
* To be as compliant and forgiving as possible.
* Provide seamless Objective-C experience against web services implemented in Java.
* Avoid glue-code.

This is done by allowing clients to define proxy and value object as Objective-C protocols, and let HessianKit generate conforming classes on the fly. HessianKit is design to be similar to Distributed Objects in Mac OS X Cocoa (not available for iPhone OS). Re-inventing the wheel is avoided by building on available technology in Cocoa (Touch) such as key-value-coding, introspection, and invocation forwarding.

HessianKit is currently 1.0beta, but is production ready, and is used for implementing iPhone clients for web services previously designed for JavaME applications.

So how does it work? Lets assume we have a hessian web service publishing the following Java interface:

 
public interface HelloService {
  public String helloWorld();
}

The Objective-C implementation would then need to define the same Java interface as an Obj-C protocol.

 
@protocol CWHelloService
-(NSString*)helloWorld;
@end

With the interface/protocol defined the client creates proxies to the web service as follows.

 
NSURL* url = [NSURL URLWithString@"http://www.mydomain.com/helloservice"];
id<CWHelloService> proxy = (id<CWHelloService>)[CWHessianConnection proxyWithURL:url protocol:@protocol(CWHelloService)];
NSLog(@"hello: %@", [proxy helloWorld]);

And that is it.

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 CWHessianArchiver methodNameForSelector:], if a method name is not returned, the method name to use will be generated to match Java and Obj-C conventions as closely as possible. Some examples.

doFoo      ==>  doFoo
getFoo:    ==>  getFoo__1
doFoo:bar: ==>  doFooBar__2
doFugly::: ==>  doFugly__3

Data will be serialized using standard Hessian types; boolean, int, and double. All Obj-C classes that implements NSCoding can be serialized for transports as Maps. Some classes are getting some special treatment for convinience on both sides.

NSArray      - Maps to Java array or java.util.List, tansfered as Hessian list.
NSDictionary - Maps to Java java.util.Map, or domain class, trabsfered as Hessian map.
NSData       - Maps to Java byte array, transfered as Hessian binary data.
NSDate       - Maps to Java long or java.util.Date, transfered as Hessian date.
NSString     - Maps to Java java.lang.String, transfered as Hessian string.
NSXMLNode    - Maps to Java org.w3c.dom.Node, transfered as Hessian xml.

That is it, now off to coding HessianKit 1.0 Final Candidate.

Fredrik Olsson
Consultant at Jayway

Tags: , , , , ,

16 comments ↓

#1 Pakko972 on 05.28.09 at 21:47

Hi, I wanted to know if this framework is the only way to use Hessian in iPhone app developpement? I found HessianObjC was very easy to use but I just can’t use it with iPhone’s sdk.
If someone could give me some advice, it would be very nice
Thanks

#2 Fredrik Olsson on 05.29.09 at 8:05

I am biased, but here goes my reply; To my knowledge HessianKit is the only publicly available framework for using Hessian on iPhone.

I would also argue that HessianKit is superior to HessianObjC. I make this claim because HessianObjC is basically a collection of utility classes for calling remote functions. Whereas HessianKit exposes true proxies for remote objects. This is a much more object oriented way, and less cumbersome for any project with more then two or three remote calls.

The advantage for HessianObjC is that it supports v2 of the Hessian binary protocol. HessianKit do not yet support v2, but will soon; along with remote calls between iPhone 3.0 devices over the bluetooth.

#3 Shikhar on 05.07.10 at 10:40

Hi I have downloaded Hessian Kit. My question is how I can include this kit in my existing iPhone project. What is the framework or files I need to add in my existing iPhone project to use Hessian protocol.
Please if any one can suggest me the steps to include Hessian file in iPhone proj, it would be great help for me.

Thanks
SD

#4 David on 05.14.10 at 16:15

Hello,
I am trying to use HessianKit in my iPhone project. I have built the static lib, included it and the .h files, it builds fine and install on the iPhone, but I have an exception when I use it:
‘NSInvalideArgumentException’, reason:
‘*** -[NSProxy doesNotRecognizeSelector:archivedDataForInvocation:] called!’

My code is this (very similar to your example):
NSURL* url = [NSURL URLWithString@"http://url/to/service"];
id proxy = (id)[CWHessianConnection proxyWithURL:url protocol:@protocol(LoginService)];
NSLog(@”hello: %@”, [proxy providerInfo]);

The protocol:
@protocol LoginService
– (NSString*)providerInfo;
@end

If I comment the call to providerInfo, it raises no exception.

I run this with iPhone 3.1.3 and the server is in fact google app engine with a Spring servlet and the Hessian exporter.

If I run the same API at the same URL with a Java client, it works fine.

Thanks,
David

#5 peter on 06.26.10 at 1:00

I have exact same problem and still unable to fix, any ideas?

#6 Fredrik Olsson on 06.28.10 at 8:41

Peter & David: Comment notifications seems to be down, so apologies for the late reply. You have both become victims to a bug in GCC, it is not so often that the problem is a faulty compiler but this is it.

GCC is a bit too aggressive, specifically it will deem all methods declared in a category from a statically linked library as not used, and thus remove them. In this case the -[CWDistantHessianObject archivedDataForInvocation] method is declared in a private category, not the public interface of CWDistantHessianObject.

There are three workarounds that work:

  1. Change compiler to LLVM if targetting iOS 4 or Mac OS X 10.6 and later.
  2. Turn on the -ObjC linker flag, this will stop GCC from removing any unused methods and may increase binary size.
  3. Use HessianKit as source, instead of static library; just drag and drop the HessianClasses folder on your project.
#7 Mike on 12.17.10 at 0:30

Nice work. What happens if you call [proxy helloWorld] and the server takes a long time to respond or doesn’t respond.. does it just lock up an iphone or ipad app? Is there a way to specify “requestfinished” and “requestfailed” methods? Thanks!

#8 Luis De Marchi on 02.03.11 at 14:49

I am in Brazil:

“Use HessianKit as source, instead of static library; just drag and drop the HessianClasses folder on your project.”

1 warning->
warning: no rule to process file ‘$(PROJECT_DIR)/Makefile’ of type sourcecode.make for architecture i386

#9 Luis De Marchi on 02.03.11 at 20:02

Get object?

Ex client: -(car) getCar;

Server:
Serializable]
public class car {}

????

#10 Mark on 05.15.11 at 13:57

It works! tks from Taiwan.

#11 Mike on 06.11.11 at 19:36

Hi, I’m just starting with HessianKit and using the example in the documentation.
I have a Hessian servlet exposing the (java) Service interface.

public interface Service {
int getPersonCount();
Person getPerson(int index);
}

I use
id proxy = [CWHessianConnection proxyWithURL:url protocol:@protocol(Service)];
int count = [proxy getPersonCount];

and they’re fine.

Using
id person = [proxy getPerson:index];
NSLog(@”%@”,person);

also works and I see all the person details in this format

2011-06-11 18:07:38.155 SpaceTest[4573:a0f] {
age = 7;
name = “Person number 7″;
}

The problem occurs when I try
[person age]
and I get an unknown selector error.(But ‘code completion’ for [person a...] works! )
What am I doing wrong?

Many Thanks

Mike

#12 Fredrik Olsson on 06.14.11 at 8:39

@Mike I believe the problem you have is that only the root object ignores the package the class is defined in in Java world. For all other interface and classes you must manually setup translations, or keep classes in the default package.

There is initial work in the v2.0 branch of HessianKit to add better support for translating between packages in Java and/or prefixes on Cocoa world.

#13 Mike on 06.16.11 at 20:25

Thanks Fredrik – that worked fine.

#14 albert on 07.05.11 at 12:53

Hello, Could do someone explain me how to build the static library from the HessianKit Project in order to include it to my project? I’m working with Xcode4.

Thanks in advance

#15 jacob bullock on 07.12.11 at 1:46

I am struggling to get this incorporated into my project. I believe I have build the static library, but i still seem unable to get it working. i am willing to pay someone for the time to help me get setup. thanks.

#16 Luís De Marchi on 09.19.11 at 21:23

expected to version 2.0 for which date?

Leave a Comment