em_hessian2 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../establish_connection', __FILE__)
2
+ require File.expand_path('../monkey', __FILE__)
3
+
4
+ ActiveRecord::Base.connection.execute("truncate table #{Monkey.table_name}")
5
+
6
+ now = Time.new
7
+ 1.upto(1000).each do |i|
8
+ Monkey.create(
9
+ id: i,
10
+ name: "#{i}号猴",
11
+ price: 0.25 * i,
12
+ born_at: now - 3600 * (1000 - i)
13
+ )
14
+ end
@@ -0,0 +1,195 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib_path = File.expand_path('../../lib', __FILE__)
3
+ $:.unshift(lib_path)
4
+ require 'hessian2'
5
+ require File.expand_path('../monkey', __FILE__)
6
+
7
+ c1 = Hessian2::Client.new('http://127.0.0.1:9292/monkey')
8
+
9
+ map1 = { name: '阿门', age: 7 }
10
+ cjmonkey1 = Hessian2::ClassWrapper.new('example.Monkey', map1)
11
+ cmonkey1 = Hessian2::ClassWrapper.new('Monkey', map1)
12
+ map1_list = [map1] * 7
13
+ list1 = [cjmonkey1] * 7
14
+ monkeys = []
15
+ 0x11.times do |i|
16
+ monkeys << Hessian2::ClassWrapper.new("example.Monkey#{i}", map1)
17
+ end
18
+ now = Time.new(2013, 1, 12, 14, 59, 59)
19
+
20
+ # c1.set_map_list_monkey_map_list_monkey(map1, list1, cmonkey1, map1, list1, cmonkey1)
21
+ # c1.set_list_monkey(Hessian2::ClassWrapper.new('[Monkey', map1_list * 2))
22
+
23
+ # c1.set_list_size0([])
24
+ # c1.set_list_monkey_size7(list1)
25
+
26
+ # 0x00..0x1f # utf-8 string length 0-31
27
+ c1.set_string_0('')
28
+ c1.set_string_x1f('j' * 0x1f)
29
+ c1.set_string_x1fu('金' * 0x1f)
30
+
31
+ # 0x20..0x2f # binary data length 0-15
32
+ c1.set_bin_0(Hessian2::TypeWrapper.new('B', ''))
33
+ c1.set_bin_xf(Hessian2::TypeWrapper.new('B', ['j' * 0xf].pack('a*')))
34
+
35
+ # 0x30..0x33 # utf-8 string length 0-1023
36
+ c1.set_string_x20('j' * 0x20)
37
+ c1.set_string_x20u('金' * 0x20)
38
+ c1.set_string_x3ff('j' * 0x3ff)
39
+ c1.set_string_x3ffu('金' * 0x3ff)
40
+
41
+ # 0x34..0x37 # binary data length 0-1023
42
+ c1.set_bin_x10(Hessian2::TypeWrapper.new('B', ['j' * 0x10].pack('a*')))
43
+ c1.set_bin_x3ff(Hessian2::TypeWrapper.new('B', ['j' * 0x3ff].pack('a*')))
44
+
45
+ # 0x38..0x3f # three-octet compact long (-x40000 to x3ffff)
46
+ c1.set_long_mx801(-0x801)
47
+ c1.set_long_x800(0x800)
48
+ c1.set_long_mx40000(-0x40000)
49
+ c1.set_long_x3ffff(0x3ffff)
50
+
51
+ # 0x41 # 8-bit binary data non-final chunk ('A')
52
+ c1.set_lighthouse(Hessian2::TypeWrapper.new('B', IO.binread(File.expand_path("../Lighthouse.jpg", __FILE__))))
53
+
54
+ # 0x42 # 8-bit binary data final chunk ('B')
55
+ c1.set_bin_x400(Hessian2::TypeWrapper.new('B', ['j' * 0x400].pack('a*')))
56
+ c1.set_bin_x8000(Hessian2::TypeWrapper.new('B', ['j' * 0x8000].pack('a*')))
57
+
58
+ # 0x43 # object type definition ('C')
59
+ # 0x60..0x6f # object with direct type
60
+ c1.set_monkey(Monkey.new(map1))
61
+
62
+ # 0x44 # 64-bit IEEE encoded double ('D')
63
+ c1.set_double_min(4.9E-324)
64
+ c1.set_double_max(1.7976931348623157E308)
65
+ c1.set_double_positive_infinity(Float::INFINITY)
66
+ c1.set_double_negative_infinity(-Float::INFINITY)
67
+ c1.set_double_nan(Float::NAN)
68
+ c1.set_123dot456(123.456)
69
+
70
+ # 0x46 # boolean false ('F')
71
+ c1.set_false(false)
72
+
73
+ # 0x48 # untyped map ('H')
74
+ c1.set_map_h(map1)
75
+
76
+ # 0x49 # 32-bit signed integer ('I')
77
+ c1.set_int_mx40001(-0x40001)
78
+ c1.set_int_mx40001(Hessian2::TypeWrapper.new('L', -0x40001))
79
+ c1.set_int_x40000(0x40000)
80
+ c1.set_int_mx40_000_000(-0x40_000_000)
81
+ c1.set_int_x3f_fff_fff(0x3f_fff_fff)
82
+
83
+ # 0x4a # 64-bit UTC millisecond date
84
+ c1.set_date_20130112145959(now)
85
+
86
+ # 0x4b # 32-bit UTC minute date
87
+ c1.set_date_201301121459(Time.new(now.year, now.mon, now.day, now.hour, now.min))
88
+
89
+ # 0x4c # 64-bit signed long integer ('L')
90
+ c1.set_long_mx80_000_001(-0x80_000_001)
91
+ c1.set_long_x80_000_000(0x80_000_000)
92
+ c1.set_long_mx8_000_000_000_000_000(-0x8_000_000_000_000_000)
93
+ c1.set_long_mx8_000_000_000_000_000(Hessian2::TypeWrapper.new('I', -0x8_000_000_000_000_000))
94
+ c1.set_long_mx8_000_000_000_000_000(Hessian2::TypeWrapper.new('I', '-0x8_000_000_000_000_000'))
95
+ c1.set_long_mx8_000_000_000_000_000(Hessian2::TypeWrapper.new('L', -0x8_000_000_000_000_000))
96
+ c1.set_long_mx8_000_000_000_000_000(Hessian2::TypeWrapper.new('L', '-0x8_000_000_000_000_000'))
97
+ c1.set_long_x7_fff_fff_fff_fff_fff(0x7_fff_fff_fff_fff_fff)
98
+
99
+ # 0x4d # map with type ('M')
100
+ c1.set_map(Hessian2::TypeWrapper.new('Monkey', map1))
101
+ begin c1.set_map(Hessian2::TypeWrapper.new('example.Monkey', map1)); rescue Hessian2::Fault => e; puts e.message; end
102
+
103
+ # 0x4e # null ('N')
104
+ c1.set_null(nil)
105
+
106
+ # 0x4f # object instance ('O')
107
+ begin c1.set_monkeys(monkeys); rescue Hessian2::Fault => e; puts "#{e.message}"; end
108
+
109
+ # 0x51 # reference to map/list/object - integer ('Q')
110
+ c1.set_map_list_monkey_map_list_monkey(map1, list1, cmonkey1, map1, list1, cmonkey1)
111
+ begin c1.set_map_list_monkey_map_list_monkey(map1, list1, cjmonkey1, map1, list1, cjmonkey1); rescue Hessian2::Fault => e; puts e.message; end
112
+
113
+ # 0x52 # utf-8 string non-final chunk ('R')
114
+ c1.set_string_x8001('j' * 0x8001)
115
+ c1.set_string_x8001u('金' * 0x8001)
116
+
117
+ # 0x53 # utf-8 string final chunk ('S')
118
+ c1.set_string_x400('j' * 0x400)
119
+ c1.set_string_x400u('金' * 0x400)
120
+ c1.set_string_x8000('j' * 0x8000)
121
+ c1.set_string_x8000u('金' * 0x8000)
122
+
123
+ # 0x54 # boolean true ('T')
124
+ c1.set_true(true)
125
+
126
+ # 0x55 # variable-length list/vector ('U')
127
+ # hessian2 write fixed-length list only
128
+
129
+ # 0x56 # fixed-length list/vector ('V')
130
+ c1.set_list_monkey(Hessian2::ClassWrapper.new('[Monkey', list1 * 2))
131
+
132
+ # 0x57 # variable-length untyped list/vector ('W')
133
+ # hessian2 write fixed-length list only
134
+
135
+ # 0x58 # fixed-length untyped list/vector ('X')
136
+ c1.set_list_monkey(list1 * 2)
137
+
138
+ # 0x59 # long encoded as 32-bit int ('Y')
139
+ c1.set_long_mx40001(-0x40001)
140
+ c1.set_long_x40000(0x40000)
141
+ c1.set_long_mx80_000_000(-0x80_000_000)
142
+ c1.set_long_x7f_fff_fff(0x7f_fff_fff)
143
+
144
+ # 0x5b # double 0.0
145
+ c1.set_double_0(0.0)
146
+
147
+ # 0x5c # double 1.0
148
+ c1.set_double_1(1.0)
149
+
150
+ # 0x5d # double represented as byte (-128.0 to 127.0)
151
+ c1.set_double_m128(-128.0)
152
+ c1.set_double_127(127.0)
153
+
154
+ # 0x5e # double represented as short (-32768.0 to 32767.0)
155
+ c1.set_double_m129(-129.0)
156
+ c1.set_double_128(128.0)
157
+ c1.set_double_m32768(-32768.0)
158
+ c1.set_double_32767(32767.0)
159
+
160
+ # 0x5f # double represented as float
161
+ # hessian2 write double-precision only
162
+
163
+ # 0x70..0x77 # fixed list with direct length
164
+ c1.set_list_size0(Hessian2::ClassWrapper.new('[Monkey', []))
165
+ c1.set_list_monkey_size7(Hessian2::ClassWrapper.new('[Monkey', map1))
166
+
167
+ # 0x78..0x7f # fixed untyped list with direct length
168
+ c1.set_list_size0([])
169
+ c1.set_list_monkey_size7(list1)
170
+
171
+ # 0x80..0xbf # one-octet compact int (-x10 to x3f, x90 is 0)
172
+ c1.set_int_mx10(-0x10)
173
+ c1.set_int_x3f(0x3f)
174
+
175
+ # 0xc0..0xcf # two-octet compact int (-x800 to x7ff)
176
+ c1.set_int_mx11(-0x11)
177
+ c1.set_int_x40(0x40)
178
+ c1.set_int_mx800(-0x800)
179
+ c1.set_int_x7ff(0x7ff)
180
+
181
+ # 0xd0..0xd7 # three-octet compact int (-x40000 to x3ffff)
182
+ c1.set_int_mx801(-0x801)
183
+ c1.set_int_x800(0x800)
184
+ c1.set_int_mx40000(-0x40000)
185
+ c1.set_int_x3ffff(0x3ffff)
186
+
187
+ # 0xd8..0xef # one-octet compact long (-x8 to xf, xe0 is 0)
188
+ c1.set_long_mx8(Hessian2::TypeWrapper.new('L', -0x8))
189
+ c1.set_long_xf(Hessian2::TypeWrapper.new('L', 0xf))
190
+
191
+ # 0xf0..0xff # two-octet compact long (-x800 to x7ff, xf8 is 0)
192
+ c1.set_long_mx9(Hessian2::TypeWrapper.new('L', -0x9))
193
+ c1.set_long_x10(Hessian2::TypeWrapper.new('L', 0x10))
194
+ c1.set_long_mx800(Hessian2::TypeWrapper.new('L', -0x800))
195
+ c1.set_long_x7ff(Hessian2::TypeWrapper.new('L', 0x7ff))
@@ -0,0 +1,20 @@
1
+ import java.util.ArrayList;
2
+ import java.util.Date;
3
+ import java.util.HashMap;
4
+ import java.util.Map;
5
+
6
+ import com.caucho.hessian.client.HessianProxyFactory;
7
+
8
+ import example.IMonkeyService;
9
+ import example.Monkey;
10
+
11
+
12
+ public class HessianTest {
13
+ public static void main(String[] args) throws Exception {
14
+ String url = "http://127.0.0.1:9292/monkey";
15
+
16
+ HessianProxyFactory factory = new HessianProxyFactory();
17
+ IMonkeyService client = (IMonkeyService) factory.create(IMonkeyService.class, url);
18
+
19
+ }
20
+ }
@@ -0,0 +1,283 @@
1
+ package example;
2
+
3
+ import java.util.ArrayList;
4
+ import java.util.Date;
5
+ import java.util.List;
6
+ import java.util.Map;
7
+
8
+ public interface IMonkeyService {
9
+
10
+ // 0x00..0x1f # utf-8 string length 0-31
11
+ public String get_string_0();
12
+ public String get_string_x1f();
13
+ public String get_string_x1fu();
14
+
15
+ public void set_string_0(String str1);
16
+ public void set_string_x1f(String str1);
17
+ public void set_string_x1fu(String str1);
18
+
19
+ // 0x20..0x2f # binary data length 0-15
20
+ public byte[] get_bin_0();
21
+ public byte[] get_bin_xf();
22
+
23
+ public void set_bin_0(byte[] bin1);
24
+ public void set_bin_xf(byte[] bin1);
25
+
26
+ // 0x30..0x33 # utf-8 string length 0-1023
27
+ public String get_string_x20();
28
+ public String get_string_x20u();
29
+ public String get_string_x3ff();
30
+ public String get_string_x3ffu();
31
+
32
+ public void set_string_x20(String str1);
33
+ public void set_string_x20u(String str1);
34
+ public void set_string_x3ff(String str1);
35
+ public void set_string_x3ffu(String str1);
36
+
37
+ // 0x34..0x37 # binary data length 0-1023
38
+ public byte[] get_bin_x10();
39
+ public byte[] get_bin_x3ff();
40
+
41
+ public void set_bin_x10(byte[] bin1);
42
+ public void set_bin_x3ff(byte[] bin1);
43
+
44
+ // 0x38..0x3f # three-octet compact long (-x40000 to x3ffff)
45
+ public long get_long_mx801();
46
+ public long get_long_x800();
47
+ public long get_long_mx40000();
48
+ public long get_long_x3ffff();
49
+
50
+ public void set_long_mx801(long long1);
51
+ public void set_long_x800(long long1);
52
+ public void set_long_mx40000(long long1);
53
+ public void set_long_x3ffff(long long1);
54
+
55
+ // 0x41 # 8-bit binary data non-final chunk ('A')
56
+ public byte[] get_lighthouse();
57
+
58
+ public void set_lighthouse(byte[] bin1); //561276
59
+
60
+ // 0x42 # 8-bit binary data final chunk ('B')
61
+ public byte[] get_bin_x400();
62
+ public byte[] get_bin_x8000();
63
+
64
+ public void set_bin_x400(byte[] bin1);
65
+ public void set_bin_x8000(byte[] bin1);
66
+
67
+ // 0x43 # object type definition ('C') and 0x60..0x6f # object with direct type
68
+ // 0x4d # map with type ('M')
69
+ public Monkey get_monkey();
70
+
71
+ public void set_monkey(Monkey monkey1);
72
+
73
+ // 0x44 # 64-bit IEEE encoded double ('D')
74
+ public double get_double_min();
75
+ public double get_double_max();
76
+ public double get_double_positive_infinity();
77
+ public double get_double_negative_infinity();
78
+ public double get_double_nan();
79
+ public double get_123dot456();
80
+
81
+ public void set_double_min(double double1); // 4.9E-324
82
+ public void set_double_max(double double1); // 1.7976931348623157E308
83
+ public void set_double_positive_infinity(double double1);
84
+ public void set_double_negative_infinity(double double1);
85
+ public void set_double_nan(double double1);
86
+ public void set_123dot456(double double1);
87
+
88
+ // 0x46 # boolean false ('F')
89
+ public boolean get_false();
90
+
91
+ public void set_false(boolean false1);
92
+
93
+ // 0x48 # untyped map ('H')
94
+ public Map<String, Object> get_map_h();
95
+
96
+ public void set_map_h(Map<String, Object> map1);
97
+
98
+ // 0x49 # 32-bit signed integer ('I')
99
+ public int get_int_mx40001();
100
+ public int get_int_x40000();
101
+ public int get_int_mx40_000_000();
102
+ public int get_int_x3f_fff_fff();
103
+
104
+ public void set_int_mx40001(int int1);
105
+ public void set_int_x40000(int int1);
106
+ public void set_int_mx40_000_000(int int1);
107
+ public void set_int_x3f_fff_fff(int int1);
108
+
109
+ // 0x4a # 64-bit UTC millisecond date
110
+ public Date get_date_20130112145959();
111
+ public long get_long_20130112145959();
112
+
113
+ public void set_date_20130112145959(Date date1);
114
+
115
+ // 0x4b # 32-bit UTC minute date
116
+ public Date get_date_201301121459();
117
+
118
+ public void set_date_201301121459(Date date1);
119
+
120
+ // 0x4c # 64-bit signed long integer ('L')
121
+ public long get_long_mx80_000_001();
122
+ public long get_long_x80_000_000();
123
+ public long get_long_mx8_000_000_000_000_000();
124
+ public long get_long_x7_fff_fff_fff_fff_fff();
125
+
126
+ public void set_long_mx80_000_001(long long1);
127
+ public void set_long_x80_000_000(long long1);
128
+ public void set_long_mx8_000_000_000_000_000(long long1);
129
+ public void set_long_x7_fff_fff_fff_fff_fff(long long1);
130
+
131
+ // 0x4d # map with type ('M')
132
+ public Monkey get_map();
133
+
134
+ public void set_map(Monkey map1);
135
+
136
+ // 0x4e # null ('N')
137
+ public Object get_null();
138
+
139
+ public void set_null(Object obj);
140
+
141
+ // 0x4f # object instance ('O')
142
+ public ArrayList<Monkey> get_monkeys();
143
+
144
+ public void set_monkeys(ArrayList<Monkey> monkeys);
145
+
146
+ // 0x51 # reference to map/list/object - integer ('Q')
147
+ public ArrayList<Map<String, Object>> get_map_h_map_h();
148
+ public ArrayList<List> get_direct_untyped_list_list();
149
+ public ArrayList<List> get_untyped_list_list();
150
+ public ArrayList<int[]> get_direct_list_list();
151
+ public ArrayList<int[]> get_list_list();
152
+ public ArrayList<Monkey> get_monkey_monkey();
153
+
154
+ public void set_map_list_monkey_map_list_monkey(Map<String, Object> map1, int[] list1, Monkey monkey1,
155
+ Map<String, Object> map2, int[] list2, Monkey monkey2);
156
+
157
+ // 0x52 # utf-8 string non-final chunk ('R')
158
+ public String get_string_x8001();
159
+ public String get_string_x8001u();
160
+
161
+ public void set_string_x8001(String str1);
162
+ public void set_string_x8001u(String str1);
163
+
164
+ // 0x53 # utf-8 string final chunk ('S')
165
+ public String get_string_x400();
166
+ public String get_string_x400u();
167
+ public String get_string_x8000();
168
+ public String get_string_x8000u();
169
+
170
+ public void set_string_x400(String str1);
171
+ public void set_string_x400u(String str1);
172
+ public void set_string_x8000(String str1);
173
+ public void set_string_x8000u(String str1);
174
+
175
+ // 0x54 # boolean true ('T')
176
+ public boolean get_true();
177
+
178
+ public void set_true(boolean true1);
179
+
180
+ // 0x56 # fixed-length list/vector ('V')
181
+ // 0x58 # fixed-length untyped list/vector ('X')
182
+ public Monkey[] get_list();
183
+ public List get_untyped_list();
184
+
185
+ public void set_list(Monkey[] list1);
186
+
187
+ // 0x59 # long encoded as 32-bit int ('Y')
188
+ public long get_long_mx40001();
189
+ public long get_long_x40000();
190
+ public long get_long_mx80_000_000();
191
+ public long get_long_x7f_fff_fff();
192
+
193
+ public void set_long_mx40001(long long1);
194
+ public void set_long_x40000(long long1);
195
+ public void set_long_mx80_000_000(long long1);
196
+ public void set_long_x7f_fff_fff(long long1);
197
+
198
+ // 0x5b # double 0.0
199
+ public double get_double_0();
200
+
201
+ public void set_double_0(double double1);
202
+
203
+ // 0x5c # double 1.0
204
+ public double get_double_1();
205
+
206
+ public void set_double_1(double double1);
207
+
208
+ // 0x5d # double represented as byte (-128.0 to 127.0)
209
+ public double get_double_m128();
210
+ public double get_double_127();
211
+
212
+ public void set_double_m128(double double1);
213
+ public void set_double_127(double double1);
214
+
215
+ // 0x5e # double represented as short (-32768.0 to 32767.0)
216
+ public double get_double_m129();
217
+ public double get_double_128();
218
+ public double get_double_m32768();
219
+ public double get_double_32767();
220
+
221
+ public void set_double_m129(double double1);
222
+ public void set_double_128(double double1);
223
+ public void set_double_m32768(double double1);
224
+ public void set_double_32767(double double1);
225
+
226
+ // 0x70..0x77 # fixed list with direct length
227
+ // 0x78..0x7f # fixed untyped list with direct length
228
+ public Monkey[] get_list_size0();
229
+ public Monkey[] get_list_size7();
230
+ public List get_untyped_list_size0();
231
+ public List get_untyped_list_size7();
232
+
233
+ public void set_list_size0(Monkey[] list1);
234
+ public void set_list_size7(Monkey[] list1);
235
+
236
+ // 0x80..0xbf # one-octet compact int (-x10 to x2f, x90 is 0)
237
+ public int get_int_mx10();
238
+ public int get_int_x3f();
239
+
240
+ public void set_int_mx10(int int1);
241
+ public void set_int_x3f(int int1);
242
+
243
+ // 0xc0..0xcf # two-octet compact int (-x800 to x7ff)
244
+ public int get_int_mx11();
245
+ public int get_int_x40();
246
+ public int get_int_mx800();
247
+ public int get_int_x7ff();
248
+
249
+ public void set_int_mx11(int int1);
250
+ public void set_int_x40(int int1);
251
+ public void set_int_mx800(int int1);
252
+ public void set_int_x7ff(int int1);
253
+
254
+ // 0xd0..0xd7 # three-octet compact int (-x40000 to x3ffff)
255
+ public int get_int_mx801();
256
+ public int get_int_x800();
257
+ public int get_int_mx40000();
258
+ public int get_int_x3ffff();
259
+
260
+ public void set_int_mx801(int int1);
261
+ public void set_int_x800(int int1);
262
+ public void set_int_mx40000(int int1);
263
+ public void set_int_x3ffff(int int1);
264
+
265
+ // 0xd8..0xef # one-octet compact long (-x8 to xf, xe0 is 0)
266
+ public long get_long_mx8();
267
+ public long get_long_xf();
268
+
269
+ public void set_long_mx8(long long1);
270
+ public void set_long_xf(long long1);
271
+
272
+ // 0xf0..0xff # two-octet compact long (-x800 to x7ff, xf8 is 0)
273
+ public long get_long_mx9();
274
+ public long get_long_x10();
275
+ public long get_long_mx800();
276
+ public long get_long_x7ff();
277
+
278
+ public void set_long_mx9(long long1);
279
+ public void set_long_x10(long long1);
280
+ public void set_long_mx800(long long1);
281
+ public void set_long_x7ff(long long1);
282
+
283
+ }