Git Product home page Git Product logo

node-hessian's Introduction

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.

node-hessian's People

Contributors

villadora avatar fantasyni avatar

Watchers

James Cloos avatar dingyusong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.