From 1430b19e102d0baf129047239792862785d91877 Mon Sep 17 00:00:00 2001 From: Alexey Zhelonkin Date: Tue, 11 Nov 2014 08:19:15 +0100 Subject: [PATCH] added "apiClass" header and "apiClassHeader" parameter to the invoke() method. --- .gitignore | 3 ++- lib/proxy.js | 8 ++++---- test/test.js | 14 ++++++++------ test/test2.js | 10 +++++----- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 04f0382..1171c93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store node_modules *.log -jar/ \ No newline at end of file +jar/ +.idea \ No newline at end of file diff --git a/lib/proxy.js b/lib/proxy.js index b0b3b86..dcd9f1c 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -10,7 +10,7 @@ var url = require('url'), Reader2 = require('./reader2'); -function Proxy(uri, username, password, proxy) { +function Proxy(uri, username, password) { events.EventEmitter.call(this); var parsed = url.parse(uri); @@ -24,13 +24,12 @@ function Proxy(uri, username, password, proxy) { assert((this.protocol == 'http' || this.protocol == 'https'), 'Unsupported Hessian protocal: ' + this.protocol); this.version = 2; - this.proxy = proxy; } util.inherits(Proxy, events.EventEmitter); -Proxy.prototype.invoke = function(method, args, callback) { +Proxy.prototype.invoke = function(method, apiClassHeader, args, callback) { var self = this, WriterClz = (this.version === 1) ? Writer : Writer2, @@ -42,7 +41,8 @@ Proxy.prototype.invoke = function(method, args, callback) { port: this.port, path: this.pathname, headers: { - 'Content-Type': 'application/binary' + 'Content-Type': 'application/binary', + 'apiClass': apiClassHeader }, method: 'POST' }; diff --git a/test/test.js b/test/test.js index 89f4bc7..1f2dbcf 100644 --- a/test/test.js +++ b/test/test.js @@ -11,9 +11,9 @@ describe('hessian 1.0 test', function() { proxy.version = 1; }); - function MAKE_ARGTEST(method, args) { + function MAKE_ARGTEST(method, apiClassHeader, args) { it(method, function(done) { - proxy.invoke(method, args, function(err, res) { + proxy.invoke(method, apiClassHeader, args, function(err, res) { assert.isTrue(res); done(err); }); @@ -21,14 +21,14 @@ describe('hessian 1.0 test', function() { } it('methodNull', function(done) { - proxy.invoke('methodNull', [], function(err, res) { + proxy.invoke('methodNull', "", [], function(err, res) { assert.isNull(res); done(err); }); }); it('replyNull', function(done) { - proxy.invoke('replyNull', null, function(err, res) { + proxy.invoke('replyNull', "", null, function(err, res) { assert.isNull(res); done(err); }); @@ -44,9 +44,10 @@ describe('hessian 1.0 test', function() { var dates = [new Date(0), new Date(1998, 4, 8, 7, 51), new Date(1998, 4, 8, 7, 51)]; var method = 'argDate_1', arg = dates[1]; + var apiClassHeader = ""; it(method, function(done) { - proxy.invoke(method, [arg], function(err, res) { + proxy.invoke(method, apiClassHeader, [arg], function(err, res) { console.log(res); done(err); }); @@ -139,8 +140,9 @@ describe('hessian 1.0 test', function() { assert.isNumber(arg); // MAKE_ARGTEST('argDouble_' + name, [arg]); var method = 'argDouble_' + name; + var apiClassHeader = ""; it(method, function(done) { - proxy.invoke(method, [arg], function(err, res) { + proxy.invoke(method, apiClassHeader, [arg], function(err, res) { // assert.isTrue(res); if (res !== true) console.log(res.toString()); diff --git a/test/test2.js b/test/test2.js index c0da97b..da50219 100644 --- a/test/test2.js +++ b/test/test2.js @@ -40,7 +40,7 @@ describe('hessian 2.0 test', function() { it('methodNull', function(done) { - proxy.invoke('methodNull', [], function(err, res) { + proxy.invoke('methodNull', "", [], function(err, res) { assert.isNull(res); done(err); }); @@ -48,7 +48,7 @@ describe('hessian 2.0 test', function() { function MAKE_ARGTEST(method, args, as) { it(method, function(done) { - proxy.invoke(method, args, function(err, res) { + proxy.invoke(method, "", args, function(err, res) { if (as) as(res); else assert.isTrue(res); done(err); @@ -58,7 +58,7 @@ describe('hessian 2.0 test', function() { function MAKE_REPLYTEST(method, reply, as) { it(method, function(done) { - proxy.invoke(method, [], function(err, res) { + proxy.invoke(method, "", [], function(err, res) { if (as) as(res, reply); else assert.strictEqual(res, reply); done(err); @@ -373,7 +373,7 @@ describe('hessian 2.0 test', function() { // MAKE_ARGTEST('argDouble_' + name, [arg]); var method = 'argDouble_' + name; it(method, function(done) { - proxy.invoke(method, [{ + proxy.invoke(method, "", [{ val: arg, type: 'double' }], function(err, res) { @@ -383,7 +383,7 @@ describe('hessian 2.0 test', function() { }); it('replyDouble_' + name, function(done) { - proxy.invoke('replyDouble_' + name, [], function(err, res) { + proxy.invoke('replyDouble_' + name, "", [], function(err, res) { assert(res == arg); done(err); });