hessian 0.5.3 → 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +8 -1
- data/lib/hessian.rb +26 -6
- metadata +21 -14
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake/gempackagetask'
|
3
3
|
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
4
5
|
|
5
6
|
task :default => [:test]
|
6
7
|
|
@@ -9,7 +10,7 @@ Rake::TestTask.new do |t|
|
|
9
10
|
t.warning = true
|
10
11
|
end
|
11
12
|
|
12
|
-
PKG_VERSION = "0
|
13
|
+
PKG_VERSION = "1.0"
|
13
14
|
PKG_FILES = FileList[
|
14
15
|
'LICENSE',
|
15
16
|
'Rakefile',
|
@@ -29,6 +30,12 @@ spec = Gem::Specification.new do |s|
|
|
29
30
|
s.require_path = "lib"
|
30
31
|
end
|
31
32
|
|
33
|
+
Rake::RDocTask.new do |rdoc|
|
34
|
+
rdoc.main = "README"
|
35
|
+
rdoc.rdoc_files.include("README", "lib/**/*.rb")
|
36
|
+
rdoc.options << "-S"
|
37
|
+
end
|
38
|
+
|
32
39
|
package_task = Rake::GemPackageTask.new(spec) do |pkg|
|
33
40
|
pkg.need_zip = true
|
34
41
|
pkg.need_tar_gz = true
|
data/lib/hessian.rb
CHANGED
@@ -3,6 +3,13 @@ require 'net/http'
|
|
3
3
|
require 'net/https'
|
4
4
|
|
5
5
|
module Hessian
|
6
|
+
class TypeWrapper
|
7
|
+
attr_accessor :hessian_type, :object
|
8
|
+
def initialize(hessian_type, object)
|
9
|
+
@hessian_type, @object = hessian_type, object
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
6
13
|
class Binary
|
7
14
|
attr :data
|
8
15
|
def initialize(data)
|
@@ -18,6 +25,7 @@ module Hessian
|
|
18
25
|
end
|
19
26
|
|
20
27
|
class HessianClient
|
28
|
+
attr_accessor :user, :password
|
21
29
|
attr_reader :scheme, :host, :port, :path, :proxy
|
22
30
|
def initialize(url, proxy = {})
|
23
31
|
uri = URI.parse(url)
|
@@ -25,19 +33,21 @@ module Hessian
|
|
25
33
|
raise "Unsupported Hessian protocol: #@scheme" unless @scheme == 'http' || @scheme == 'https'
|
26
34
|
@proxy = proxy
|
27
35
|
end
|
28
|
-
|
36
|
+
|
29
37
|
def method_missing(id, *args)
|
30
38
|
return invoke(id.id2name, args)
|
31
39
|
end
|
32
40
|
|
33
41
|
private
|
34
42
|
def invoke(method, args)
|
35
|
-
|
43
|
+
call = HessianWriter.new.write_call method, args
|
36
44
|
header = { 'Content-Type' => 'application/binary' }
|
45
|
+
req = Net::HTTP::Post.new(@path, header)
|
46
|
+
req.basic_auth @user, @password if @user
|
37
47
|
conn = Net::HTTP.new(@host, @port, *@proxy.values_at(:host, :port, :user, :password))
|
38
48
|
conn.use_ssl = true and conn.verify_mode = OpenSSL::SSL::VERIFY_NONE if @scheme == 'https'
|
39
49
|
conn.start do |http|
|
40
|
-
res = http.
|
50
|
+
res = http.request(req, call)
|
41
51
|
HessianParser.new.parse_response res.body
|
42
52
|
end
|
43
53
|
end
|
@@ -51,9 +61,11 @@ module Hessian
|
|
51
61
|
end
|
52
62
|
|
53
63
|
private
|
54
|
-
def write_object(val)
|
64
|
+
def write_object(val, hessian_type = nil)
|
55
65
|
return 'N' if val.nil?
|
56
66
|
case val
|
67
|
+
when TypeWrapper: write_object(val.object, val.hessian_type)
|
68
|
+
when Struct: write_object(val.members.inject({}) { |map, m| map[m] = val[m]; map })
|
57
69
|
when Binary: [ 'B', val.data.length ].pack('an') << val.data
|
58
70
|
when String: [ 'S', val.length ].pack('an') << val.unpack('C*').pack('U*')
|
59
71
|
when Integer
|
@@ -69,12 +81,13 @@ module Hessian
|
|
69
81
|
when FalseClass: 'F'
|
70
82
|
when Array
|
71
83
|
ref = write_ref val; return ref if ref
|
72
|
-
|
84
|
+
t = hessian_type_string(hessian_type, val)
|
85
|
+
str = 'Vt' << t << 'l' << [ val.length ].pack('N')
|
73
86
|
val.each { |v| str << write_object(v) }
|
74
87
|
str << 'z'
|
75
88
|
when Hash
|
76
89
|
ref = write_ref val; return ref if ref
|
77
|
-
str =
|
90
|
+
str = 'Mt' << hessian_type_string(hessian_type, val)
|
78
91
|
val.each { |k, v| str << write_object(k); str << write_object(v) }
|
79
92
|
str << 'z'
|
80
93
|
else
|
@@ -82,6 +95,13 @@ module Hessian
|
|
82
95
|
end
|
83
96
|
end
|
84
97
|
|
98
|
+
def hessian_type_string(hessian_type, object)
|
99
|
+
if hessian_type.nil? && object.respond_to?(:hessian_type)
|
100
|
+
hessian_type = object.hessian_type
|
101
|
+
end
|
102
|
+
hessian_type ? [ hessian_type.length, hessian_type ].pack('na*') : "\000\000"
|
103
|
+
end
|
104
|
+
|
85
105
|
def to_long(val)
|
86
106
|
str, pos = " " * 8, 0
|
87
107
|
56.step(0, -8) { |o| str[pos] = val >> o & 0x00000000000000ff; pos += 1 }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: hessian
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0
|
7
|
-
date: 2006-
|
6
|
+
version: "1.0"
|
7
|
+
date: 2006-07-22 00:00:00 +02:00
|
8
8
|
summary: A Ruby Hessian client.
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
11
|
email: chrsan@gmail.com
|
12
12
|
homepage: http://www.baanii.se/
|
13
13
|
rubyforge_project:
|
@@ -18,25 +18,32 @@ bindir: bin
|
|
18
18
|
has_rdoc: false
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
20
|
requirements:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
25
24
|
version:
|
26
25
|
platform: ruby
|
27
26
|
signing_key:
|
28
27
|
cert_chain:
|
28
|
+
post_install_message:
|
29
29
|
authors:
|
30
|
-
|
30
|
+
- Christer Sandberg
|
31
31
|
files:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
- LICENSE
|
33
|
+
- Rakefile
|
34
|
+
- lib/hessian.rb
|
35
|
+
- test/test_hessian_parser.rb
|
36
36
|
test_files: []
|
37
|
+
|
37
38
|
rdoc_options: []
|
39
|
+
|
38
40
|
extra_rdoc_files: []
|
41
|
+
|
39
42
|
executables: []
|
43
|
+
|
40
44
|
extensions: []
|
45
|
+
|
41
46
|
requirements: []
|
42
|
-
|
47
|
+
|
48
|
+
dependencies: []
|
49
|
+
|