hessian2 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -10
  3. data/README.md +203 -199
  4. data/lib/hessian2.rb +14 -14
  5. data/lib/hessian2/client.rb +57 -57
  6. data/lib/hessian2/constants.rb +164 -164
  7. data/lib/hessian2/fault.rb +3 -3
  8. data/lib/hessian2/handler.rb +18 -18
  9. data/lib/hessian2/hessian_client.rb +3 -3
  10. data/lib/hessian2/parser.rb +619 -619
  11. data/lib/hessian2/type_wrapper.rb +49 -49
  12. data/lib/hessian2/version.rb +3 -3
  13. data/lib/hessian2/writer.rb +506 -504
  14. data/spec/binary_spec.rb +51 -51
  15. data/spec/boolean_spec.rb +26 -26
  16. data/spec/class_wrapper_spec.rb +52 -52
  17. data/spec/create_monkeys.rb +14 -14
  18. data/spec/date_spec.rb +45 -45
  19. data/spec/double_spec.rb +78 -78
  20. data/spec/int_spec.rb +54 -54
  21. data/spec/list_spec.rb +66 -66
  22. data/spec/long_spec.rb +68 -68
  23. data/spec/map_spec.rb +36 -36
  24. data/spec/null_spec.rb +17 -17
  25. data/spec/object_spec.rb +78 -78
  26. data/spec/ref_spec.rb +43 -43
  27. data/spec/spec_helper.rb +23 -23
  28. data/spec/string_spec.rb +61 -61
  29. data/spec/struct_wrapper_spec.rb +47 -47
  30. data/spec/type_wrapper_spec.rb +102 -102
  31. data/test/app.rb +24 -24
  32. data/test/async/em_http_asleep.rb +25 -25
  33. data/test/async/em_http_sleep.rb +25 -25
  34. data/test/async/monkey.asleep.rb +27 -27
  35. data/test/async/mysql2_aquery.rb +37 -37
  36. data/test/fault/monkey.undefined_method.rb +5 -5
  37. data/test/fault/monkey.wrong_arguments.rb +5 -5
  38. data/test/fiber_concurrency/em_http_asleep.rb +17 -17
  39. data/test/fiber_concurrency/em_http_sleep.rb +17 -17
  40. data/test/fiber_concurrency/monkey.asleep.fiber_aware.rb +18 -18
  41. data/test/fiber_concurrency/mysql2_query.rb +29 -29
  42. data/test/fiber_concurrency/net_http_asleep.rb +19 -19
  43. data/test/fiber_concurrency/net_http_sleep.rb +19 -19
  44. data/test/fibered_rainbows/Gemfile +15 -15
  45. data/test/fibered_rainbows/config.ru +11 -11
  46. data/test/fibered_rainbows/rainbows.rb +13 -13
  47. data/test/monkey_service.rb +16 -16
  48. data/test/prepare.rb +7 -7
  49. data/test/thread_concurrency/active_record_execute.rb +29 -29
  50. data/test/thread_concurrency/monkey.asleep.rb +22 -22
  51. data/test/thread_concurrency/net_http_asleep.rb +24 -24
  52. data/test/thread_concurrency/net_http_sleep.rb +24 -24
  53. data/test/threaded_rainbows/Gemfile +13 -13
  54. data/test/threaded_rainbows/config.ru +9 -9
  55. data/test/threaded_rainbows/rainbows.rb +13 -13
  56. metadata +46 -4
@@ -1,57 +1,57 @@
1
- require 'uri'
2
- require 'hessian2'
3
-
4
- module Hessian2
5
- class Client
6
- attr_accessor :user, :password
7
- attr_reader :scheme, :host, :port, :path, :proxy
8
-
9
- def initialize(url, options = {})
10
- uri = URI.parse(url)
11
- @scheme, @host, @port, @path = uri.scheme, uri.host, uri.port, uri.path.empty? ? '/' : uri.path
12
- @path += "?#{uri.query}" if uri.query
13
- raise "Unsupported Hessian protocol: #{@scheme}" unless %w(http https).include?(@scheme)
14
- @async = options.delete(:async)
15
- @fiber_aware = options.delete(:fiber_aware)
16
- if @async || @fiber_aware
17
- begin
18
- require 'em-synchrony/em-http'
19
- rescue LoadError => error
20
- raise "Missing EM-Synchrony dependency: gem install em-synchrony em-http-request"
21
- end
22
- else
23
- require 'net/http'
24
- end
25
- @proxy = options
26
- end
27
-
28
-
29
- def method_missing(id, *args)
30
- return invoke(id.id2name, args)
31
- end
32
-
33
- private
34
-
35
- def invoke(method, args)
36
- req_head = { 'Content-Type' => 'application/binary' }
37
- req_body = Hessian2.call(method, args)
38
-
39
- if @async
40
- EM::HttpRequest.new("#{@scheme}://#{@host}:#{@port}#{@path}").apost(body: req_body, head: req_head)
41
- elsif @fiber_aware
42
- http = EM::HttpRequest.new("#{@scheme}://#{@host}:#{@port}#{@path}").post(body: req_body, head: req_head)
43
- Hessian2.parse_rpc(http.response)
44
- else
45
- req = Net::HTTP::Post.new(@path, req_head)
46
- req.basic_auth @user, @password if @user
47
- conn = Net::HTTP.new(@host, @port, *@proxy.values_at(:host, :port, :user, :password))
48
- conn.use_ssl = true and conn.verify_mode = OpenSSL::SSL::VERIFY_NONE if @scheme == 'https'
49
- conn.start do |http|
50
- res = http.request(req, req_body)
51
- Hessian2.parse_rpc(res.body)
52
- end
53
- end
54
- end
55
-
56
- end
57
- end
1
+ require 'uri'
2
+ require 'hessian2'
3
+
4
+ module Hessian2
5
+ class Client
6
+ attr_accessor :user, :password
7
+ attr_reader :scheme, :host, :port, :path, :proxy
8
+
9
+ def initialize(url, options = {})
10
+ uri = URI.parse(url)
11
+ @scheme, @host, @port, @path = uri.scheme, uri.host, uri.port, uri.path.empty? ? '/' : uri.path
12
+ @path += "?#{uri.query}" if uri.query
13
+ raise "Unsupported Hessian protocol: #{@scheme}" unless %w(http https).include?(@scheme)
14
+ @async = options.delete(:async)
15
+ @fiber_aware = options.delete(:fiber_aware)
16
+ if @async || @fiber_aware
17
+ begin
18
+ require 'em-synchrony/em-http'
19
+ rescue LoadError => error
20
+ raise "Missing EM-Synchrony dependency: gem install em-synchrony em-http-request"
21
+ end
22
+ else
23
+ require 'net/http'
24
+ end
25
+ @proxy = options
26
+ end
27
+
28
+
29
+ def method_missing(id, *args)
30
+ return invoke(id.id2name, args)
31
+ end
32
+
33
+ private
34
+
35
+ def invoke(method, args)
36
+ req_head = { 'Content-Type' => 'application/binary' }
37
+ req_body = Hessian2.call(method, args)
38
+
39
+ if @async
40
+ EM::HttpRequest.new("#{@scheme}://#{@host}:#{@port}#{@path}").apost(body: req_body, head: req_head)
41
+ elsif @fiber_aware
42
+ http = EM::HttpRequest.new("#{@scheme}://#{@host}:#{@port}#{@path}").post(body: req_body, head: req_head)
43
+ Hessian2.parse_rpc(http.response)
44
+ else
45
+ req = Net::HTTP::Post.new(@path, req_head)
46
+ req.basic_auth @user, @password if @user
47
+ conn = Net::HTTP.new(@host, @port, *@proxy.values_at(:host, :port, :user, :password))
48
+ conn.use_ssl = true and conn.verify_mode = OpenSSL::SSL::VERIFY_NONE if @scheme == 'https'
49
+ conn.start do |http|
50
+ res = http.request(req, req_body)
51
+ Hessian2.parse_rpc(res.body)
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+ end
@@ -1,164 +1,164 @@
1
- module Hessian2
2
- #=== Hessian 2.0 Web Services Protocol Bytecode map
3
- #
4
- # x00 - x42 # reserved
5
- # x43 # rpc call ('C')
6
- # x44 # reserved
7
- # x45 # envelope ('E')
8
- # x46 # fault ('F')
9
- # x47 # reserved
10
- # x48 # hessian version ('H')
11
- # x49 - x4f # reserved
12
- # x4f # packet chunk ('O')
13
- # x50 # packet end ('P')
14
- # x51 # reserved
15
- # x52 # rpc result ('R')
16
- # x53 - x59 # reserved
17
- # x5a # terminator ('Z')
18
- # x5b - x5f # reserved
19
- # x70 - x7f # final packet (0 - 4096)
20
- # x80 - xff # final packet for envelope (0 - 127)
21
- #
22
- #=== Hessian 2.0 Serialization Protocol Bytecode map
23
- #
24
- # x00 - x1f # utf-8 string length 0-31*
25
- # x20 - x2f # binary data length 0-15*
26
- # x30 - x33 # utf-8 string length 0-1023
27
- # x34 - x37 # binary data length 0-1023
28
- # x38 - x3f # three-octet compact long (-x40000 to x3ffff)
29
- # x40 # reserved (expansion/escape)
30
- # x41 # 8-bit binary data non-final chunk ('A')
31
- # x42 # 8-bit binary data final chunk ('B')
32
- # x43 # object type definition ('C')
33
- # x44 # 64-bit IEEE encoded double ('D')
34
- # x45 # reserved
35
- # x46 # boolean false ('F')
36
- # x47 # reserved
37
- # x48 # untyped map ('H')
38
- # x49 # 32-bit signed integer ('I')
39
- # x4a # 64-bit UTC millisecond date
40
- # x4b # 32-bit UTC minute date
41
- # x4c # 64-bit signed long integer ('L')
42
- # x4d # map with type ('M')
43
- # x4e # null ('N')
44
- # x4f # object instance ('O')
45
- # x50 # reserved
46
- # x51 # reference to map/list/object - integer ('Q')
47
- # x52 # utf-8 string non-final chunk ('R')
48
- # x53 # utf-8 string final chunk ('S')
49
- # x54 # boolean true ('T')
50
- # x55 # variable-length list/vector ('U')
51
- # x56 # fixed-length list/vector ('V')
52
- # x57 # variable-length untyped list/vector ('W')
53
- # x58 # fixed-length untyped list/vector ('X')
54
- # x59 # long encoded as 32-bit int ('Y')
55
- # x5a # list/map terminator ('Z')
56
- # x5b # double 0.0
57
- # x5c # double 1.0
58
- # x5d # double represented as byte (-128.0 to 127.0)
59
- # x5e # double represented as short (-32768.0 to 32767.0)
60
- # x5f # double represented as float
61
- # x60 - x6f # object with direct type
62
- # x70 - x77 # fixed list with direct length
63
- # x78 - x7f # fixed untyped list with direct length
64
- # x80 - xbf # one-octet compact int (-x10 to x2f, x90 is 0)*
65
- # xc0 - xcf # two-octet compact int (-x800 to x7ff)
66
- # xd0 - xd7 # three-octet compact int (-x40000 to x3ffff)
67
- # xd8 - xef # one-octet compact long (-x8 to xf, xe0 is 0)
68
- # xf0 - xff # two-octet compact long (-x800 to x7ff, xf8 is 0)
69
- module Constants
70
- BC_BINARY = 0x42
71
- BC_BINARY_CHUNK = 0x41
72
- BC_BINARY_DIRECT = 0x20
73
- BINARY_DIRECT_MAX = 0x0f
74
- BC_BINARY_SHORT = 0x34
75
- BINARY_SHORT_MAX = 0x3ff
76
-
77
- BC_CLASS_DEF = 0x43
78
-
79
- BC_DATE = 0x4a
80
- BC_DATE_MINUTE = 0x4b
81
-
82
- BC_DOUBLE = 0x44
83
-
84
- BC_DOUBLE_ZERO = 0x5b
85
- BC_DOUBLE_ONE = 0x5c
86
- BC_DOUBLE_BYTE = 0x5d
87
- BC_DOUBLE_SHORT = 0x5e
88
- BC_DOUBLE_MILL = 0x5f
89
-
90
- BC_FALSE = 0x46
91
-
92
- BC_INT = 0x49
93
-
94
- INT_DIRECT_MIN = -0x10
95
- INT_DIRECT_MAX = 0x2f
96
- BC_INT_ZERO = 0x90
97
-
98
- INT_BYTE_MIN = -0x800
99
- INT_BYTE_MAX = 0x7ff
100
- BC_INT_BYTE_ZERO = 0xc8
101
-
102
- BC_END = 0x5a
103
-
104
- INT_SHORT_MIN = -0x40000
105
- INT_SHORT_MAX = 0x3ffff
106
- BC_INT_SHORT_ZERO = 0xd4
107
-
108
- BC_LIST_VARIABLE = 0x55
109
- BC_LIST_FIXED = 0x56
110
- BC_LIST_VARIABLE_UNTYPED = 0x57
111
- BC_LIST_FIXED_UNTYPED = 0x58
112
-
113
- BC_LIST_DIRECT = 0x70
114
- BC_LIST_DIRECT_UNTYPED = 0x78
115
- LIST_DIRECT_MAX = 0x7
116
-
117
- BC_LONG = 0x4c
118
- LONG_DIRECT_MIN = -0x08
119
- LONG_DIRECT_MAX = 0x0f
120
- BC_LONG_ZERO = 0xe0
121
-
122
- LONG_BYTE_MIN = -0x800
123
- LONG_BYTE_MAX = 0x7ff
124
- BC_LONG_BYTE_ZERO = 0xf8
125
-
126
- LONG_SHORT_MIN = -0x40000
127
- LONG_SHORT_MAX = 0x3ffff
128
- BC_LONG_SHORT_ZERO = 0x3c
129
-
130
- BC_LONG_INT = 0x59
131
-
132
- BC_MAP = 0x4d
133
- BC_MAP_UNTYPED = 0x48
134
-
135
- BC_NULL = 0x4e
136
-
137
- BC_OBJECT = 0x4f
138
- BC_OBJECT_DEF = 0x43
139
-
140
- BC_OBJECT_DIRECT = 0x60
141
- OBJECT_DIRECT_MAX = 0x0f
142
-
143
- BC_REF = 0x51
144
-
145
- BC_STRING = 0x53
146
- BC_STRING_CHUNK = 0x52
147
-
148
- BC_STRING_DIRECT = 0x00
149
- STRING_DIRECT_MAX = 0x1f
150
- BC_STRING_SHORT = 0x30
151
- STRING_SHORT_MAX = 0x3ff
152
-
153
- BC_TRUE = 0x54
154
-
155
- P_PACKET_CHUNK = 0x4f
156
- P_PACKET = 0x50
157
-
158
- P_PACKET_DIRECT = 0x80
159
- PACKET_DIRECT_MAX = 0x7f
160
-
161
- P_PACKET_SHORT = 0x70
162
- PACKET_SHORT_MAX = 0xfff
163
- end
164
- end
1
+ module Hessian2
2
+ #=== Hessian 2.0 Web Services Protocol Bytecode map
3
+ #
4
+ # x00 - x42 # reserved
5
+ # x43 # rpc call ('C')
6
+ # x44 # reserved
7
+ # x45 # envelope ('E')
8
+ # x46 # fault ('F')
9
+ # x47 # reserved
10
+ # x48 # hessian version ('H')
11
+ # x49 - x4f # reserved
12
+ # x4f # packet chunk ('O')
13
+ # x50 # packet end ('P')
14
+ # x51 # reserved
15
+ # x52 # rpc result ('R')
16
+ # x53 - x59 # reserved
17
+ # x5a # terminator ('Z')
18
+ # x5b - x5f # reserved
19
+ # x70 - x7f # final packet (0 - 4096)
20
+ # x80 - xff # final packet for envelope (0 - 127)
21
+ #
22
+ #=== Hessian 2.0 Serialization Protocol Bytecode map
23
+ #
24
+ # x00 - x1f # utf-8 string length 0-31*
25
+ # x20 - x2f # binary data length 0-15*
26
+ # x30 - x33 # utf-8 string length 0-1023
27
+ # x34 - x37 # binary data length 0-1023
28
+ # x38 - x3f # three-octet compact long (-x40000 to x3ffff)
29
+ # x40 # reserved (expansion/escape)
30
+ # x41 # 8-bit binary data non-final chunk ('A')
31
+ # x42 # 8-bit binary data final chunk ('B')
32
+ # x43 # object type definition ('C')
33
+ # x44 # 64-bit IEEE encoded double ('D')
34
+ # x45 # reserved
35
+ # x46 # boolean false ('F')
36
+ # x47 # reserved
37
+ # x48 # untyped map ('H')
38
+ # x49 # 32-bit signed integer ('I')
39
+ # x4a # 64-bit UTC millisecond date
40
+ # x4b # 32-bit UTC minute date
41
+ # x4c # 64-bit signed long integer ('L')
42
+ # x4d # map with type ('M')
43
+ # x4e # null ('N')
44
+ # x4f # object instance ('O')
45
+ # x50 # reserved
46
+ # x51 # reference to map/list/object - integer ('Q')
47
+ # x52 # utf-8 string non-final chunk ('R')
48
+ # x53 # utf-8 string final chunk ('S')
49
+ # x54 # boolean true ('T')
50
+ # x55 # variable-length list/vector ('U')
51
+ # x56 # fixed-length list/vector ('V')
52
+ # x57 # variable-length untyped list/vector ('W')
53
+ # x58 # fixed-length untyped list/vector ('X')
54
+ # x59 # long encoded as 32-bit int ('Y')
55
+ # x5a # list/map terminator ('Z')
56
+ # x5b # double 0.0
57
+ # x5c # double 1.0
58
+ # x5d # double represented as byte (-128.0 to 127.0)
59
+ # x5e # double represented as short (-32768.0 to 32767.0)
60
+ # x5f # double represented as float
61
+ # x60 - x6f # object with direct type
62
+ # x70 - x77 # fixed list with direct length
63
+ # x78 - x7f # fixed untyped list with direct length
64
+ # x80 - xbf # one-octet compact int (-x10 to x2f, x90 is 0)*
65
+ # xc0 - xcf # two-octet compact int (-x800 to x7ff)
66
+ # xd0 - xd7 # three-octet compact int (-x40000 to x3ffff)
67
+ # xd8 - xef # one-octet compact long (-x8 to xf, xe0 is 0)
68
+ # xf0 - xff # two-octet compact long (-x800 to x7ff, xf8 is 0)
69
+ module Constants
70
+ BC_BINARY = 0x42
71
+ BC_BINARY_CHUNK = 0x41
72
+ BC_BINARY_DIRECT = 0x20
73
+ BINARY_DIRECT_MAX = 0x0f
74
+ BC_BINARY_SHORT = 0x34
75
+ BINARY_SHORT_MAX = 0x3ff
76
+
77
+ BC_CLASS_DEF = 0x43
78
+
79
+ BC_DATE = 0x4a
80
+ BC_DATE_MINUTE = 0x4b
81
+
82
+ BC_DOUBLE = 0x44
83
+
84
+ BC_DOUBLE_ZERO = 0x5b
85
+ BC_DOUBLE_ONE = 0x5c
86
+ BC_DOUBLE_BYTE = 0x5d
87
+ BC_DOUBLE_SHORT = 0x5e
88
+ BC_DOUBLE_MILL = 0x5f
89
+
90
+ BC_FALSE = 0x46
91
+
92
+ BC_INT = 0x49
93
+
94
+ INT_DIRECT_MIN = -0x10
95
+ INT_DIRECT_MAX = 0x2f
96
+ BC_INT_ZERO = 0x90
97
+
98
+ INT_BYTE_MIN = -0x800
99
+ INT_BYTE_MAX = 0x7ff
100
+ BC_INT_BYTE_ZERO = 0xc8
101
+
102
+ BC_END = 0x5a
103
+
104
+ INT_SHORT_MIN = -0x40000
105
+ INT_SHORT_MAX = 0x3ffff
106
+ BC_INT_SHORT_ZERO = 0xd4
107
+
108
+ BC_LIST_VARIABLE = 0x55
109
+ BC_LIST_FIXED = 0x56
110
+ BC_LIST_VARIABLE_UNTYPED = 0x57
111
+ BC_LIST_FIXED_UNTYPED = 0x58
112
+
113
+ BC_LIST_DIRECT = 0x70
114
+ BC_LIST_DIRECT_UNTYPED = 0x78
115
+ LIST_DIRECT_MAX = 0x7
116
+
117
+ BC_LONG = 0x4c
118
+ LONG_DIRECT_MIN = -0x08
119
+ LONG_DIRECT_MAX = 0x0f
120
+ BC_LONG_ZERO = 0xe0
121
+
122
+ LONG_BYTE_MIN = -0x800
123
+ LONG_BYTE_MAX = 0x7ff
124
+ BC_LONG_BYTE_ZERO = 0xf8
125
+
126
+ LONG_SHORT_MIN = -0x40000
127
+ LONG_SHORT_MAX = 0x3ffff
128
+ BC_LONG_SHORT_ZERO = 0x3c
129
+
130
+ BC_LONG_INT = 0x59
131
+
132
+ BC_MAP = 0x4d
133
+ BC_MAP_UNTYPED = 0x48
134
+
135
+ BC_NULL = 0x4e
136
+
137
+ BC_OBJECT = 0x4f
138
+ BC_OBJECT_DEF = 0x43
139
+
140
+ BC_OBJECT_DIRECT = 0x60
141
+ OBJECT_DIRECT_MAX = 0x0f
142
+
143
+ BC_REF = 0x51
144
+
145
+ BC_STRING = 0x53
146
+ BC_STRING_CHUNK = 0x52
147
+
148
+ BC_STRING_DIRECT = 0x00
149
+ STRING_DIRECT_MAX = 0x1f
150
+ BC_STRING_SHORT = 0x30
151
+ STRING_SHORT_MAX = 0x3ff
152
+
153
+ BC_TRUE = 0x54
154
+
155
+ P_PACKET_CHUNK = 0x4f
156
+ P_PACKET = 0x50
157
+
158
+ P_PACKET_DIRECT = 0x80
159
+ PACKET_DIRECT_MAX = 0x7f
160
+
161
+ P_PACKET_SHORT = 0x70
162
+ PACKET_SHORT_MAX = 0xfff
163
+ end
164
+ end
@@ -1,3 +1,3 @@
1
- module Hessian2
2
- class Fault < RuntimeError; end
3
- end
1
+ module Hessian2
2
+ class Fault < RuntimeError; end
3
+ end
@@ -1,18 +1,18 @@
1
- require 'hessian2'
2
-
3
- module Hessian2
4
- module Handler
5
-
6
- def handle(data)
7
- val = Hessian2.parse_rpc(data)
8
- begin
9
- res = self.send(*val)
10
- rescue NoMethodError, ArgumentError => e
11
- Hessian2.write_fault(e)
12
- else
13
- Hessian2.reply(res)
14
- end
15
- end
16
-
17
- end
18
- end
1
+ require 'hessian2'
2
+
3
+ module Hessian2
4
+ module Handler
5
+
6
+ def handle(data)
7
+ val = Hessian2.parse_rpc(data)
8
+ begin
9
+ res = self.send(*val)
10
+ rescue NoMethodError, ArgumentError => e
11
+ Hessian2.write_fault(e)
12
+ else
13
+ Hessian2.reply(res)
14
+ end
15
+ end
16
+
17
+ end
18
+ end