Skip to content

villadora/node-hessian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node Hessian Proxy

RPC Proxy support hessian 2.0 protocol, with fully tested via test service in http://hessian.caucho.com/test/test2

I couldn't not find a stable hessian 1.0 protocol test service. so 1.0 is not fully implmented yet.

Build Status

Installation

npm install hessian-proxy

Usage

var Proxy = require('hessian-proxy').Proxy;

var proxy = new Proxy('http://example.com/test', username, password, proxy);

proxy.invoke(methodName, [arg1, arg2, arg3..], function(err, reply) {
    // ... do with reply
});

// use writer2
var Writer = require('hessian-proxy').Writer2; // for hessian2.0

var writer = new Writer();
writer.writeCall(method, [arg1, arg2…]);

var buffer = writer.getBuffer();

// use reader2
var Reader = require('hessian-proxy').Reader2; // for hessian2.0

var reader = new Reader();
var data = reader.readRPCMessage(buffer).getData();

Support Value Types

Binary

Binary will be represented by Buffer in node js.

Boolean

true or false

Date

Represented as Date type.

Double

In javascript, all double are numbers and represented via 64-bit double. so it will not be able to write a 32-bit float format, but it can read 32-bit float as double.

Int

Just as normal int.

List

Arrays will be sent as list, typed list need to add a property 'type' to the array. Typed List will have type in 'type' property.

// untyped list
var list = [1,2,3];

// typed list
var list = ['a', 'b', 'c'];
list.__type__ = '[string';

Long

use Long.js to handle long value.

var Long = require('long');

var long = new Long(low, high);

// or 
var long = { low: lowbit, high: highbit };

Map

If you don't care about key type, all the keys will be string. the normal Object will be treated as a map. If you want to parse/send maps that use objects as key. You have to expose a ES6 standard Map Class to global namespace.

And typed Map will have type in 'mapType' property.

For example:

global.Map = require('es6-map-shim').Map;
// normal untyped map, all the key will be string
var map = {  
	1: 1,
	'a': 0, 
	'b': 2
};

// normal typed map
var map = {  
    'a': 0, 
    'b': 1
};

map.__mapType__ = 'java.util.Hashtable';

// es6 Map, object can be used as key
var map = new Map();
map.set(['a'], 0);
map.set('b', 1);
map.set(true, 'true');

// add type
map.__mapType__ = 'java.util.Hashtable';

Ref

The proxy will take the job for you if the objects are equal via strict equal '===='.

Object

To send Object, objects must have a type in 'type' property. Otherwise, it will be send as a map.

var obj = {
    'value': 0,
    'next': 1
};

obj.__type__ = 'com.test.TestObject';

Null

Just as null.

Web Service

For webservice support call, reply, fault. packet+ and envelope+ current are not supported yet.

See test/test2.js to get more examples how to use specific type.

Reference

Hessian 2.0 Serialization

Hessian 2.0 Web Service Protocol

Hessian Test

Hessian 1.0 Spec

Notice: There are some mistakes in the document and make a lot of confuse when writing protocol according to spec, especially when doing test and just find test docs are not correct for some arguments values.

License

(The BSD License)

Copyright (c) 2013, Villa.Gao <[email protected]>;
All rights reserved.