msgpack-rpc-over-http 0.0.7-java → 0.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/msgpack/rpc_over_http/client.rb +6 -3
- data/lib/msgpack/rpc_over_http/server.rb +3 -3
- data/lib/msgpack/rpc_over_http/server/request_unpacker.rb +4 -2
- data/lib/msgpack/rpc_over_http/server/response_packer.rb +14 -7
- data/lib/msgpack/rpc_over_http/version.rb +1 -1
- data/msgpack-rpc-over-http.gemspec +1 -1
- data/test/helper.rb +1 -1
- data/test/mock_server.ru +13 -1
- data/test/test_client.rb +23 -4
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85d40d76b5281cdd8e9d8ab72777a45a7b74282f
|
4
|
+
data.tar.gz: 04c22506a3afb8656ee57ee105b67b334c520a33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9e40e0650b8cc7c405518de396c7a9758e1843866e6a79aef9831e0e776da9f097f9edfec1e79f63d3e514fd4f8009e935b3c3554d2012713ea8eb6ccc3ae98
|
7
|
+
data.tar.gz: 4530584bf09ded104e6517e0a3272f4c7651c7c5be000c10b7fd1fe20f22aca7f04b0e3c2ee71f939ba7e4f62813f93b0f61260a74066355e4a8096e1ec5237d
|
@@ -11,11 +11,12 @@ module MessagePack
|
|
11
11
|
|
12
12
|
HEADER = {"Content-Type" => 'application/x-msgpack'}
|
13
13
|
|
14
|
-
def initialize(url,
|
14
|
+
def initialize(url, factory: nil)
|
15
15
|
@url = url
|
16
16
|
@client = HTTPClient.new
|
17
17
|
@reqtable = {}
|
18
18
|
@seqid = 0
|
19
|
+
@factory = factory || MessagePack::Factory.new
|
19
20
|
end
|
20
21
|
|
21
22
|
def_delegators(:@client,
|
@@ -98,11 +99,13 @@ module MessagePack
|
|
98
99
|
msgid = @seqid
|
99
100
|
@seqid += 1
|
100
101
|
@seqid = 0 if @seqid >= (1 << 31)
|
101
|
-
|
102
|
+
packer = @factory.packer
|
103
|
+
data = packer.write([REQUEST, msgid, method, param]).to_s
|
102
104
|
end
|
103
105
|
|
104
106
|
def get_result(body)
|
105
|
-
|
107
|
+
unpacker = @factory.unpacker
|
108
|
+
type, msgid, err, res = unpacker.feed(body).read
|
106
109
|
raise "Unknown message type #{type}" if type != RESPONSE
|
107
110
|
|
108
111
|
if err.nil?
|
@@ -11,11 +11,11 @@ module MessagePack
|
|
11
11
|
|
12
12
|
# Retruns the application for MessagePack-RPC.
|
13
13
|
# It's create with Rack::Builder
|
14
|
-
def self.app(handler)
|
14
|
+
def self.app(handler, factory = nil)
|
15
15
|
return Rack::Builder.app do
|
16
16
|
use Rack::Chunked
|
17
|
-
use RequestUnpacker
|
18
|
-
use ResponsePacker
|
17
|
+
use RequestUnpacker, factory
|
18
|
+
use ResponsePacker, factory
|
19
19
|
use Dispatcher
|
20
20
|
run handler
|
21
21
|
end
|
@@ -5,8 +5,9 @@ module MessagePack
|
|
5
5
|
# Rack Middleware that unpacks a serialized string in a HTTP
|
6
6
|
# request.
|
7
7
|
class RequestUnpacker
|
8
|
-
def initialize(app)
|
8
|
+
def initialize(app, factory = nil)
|
9
9
|
@app = app
|
10
|
+
@factory = factory || MessagePack::Factory.new
|
10
11
|
end
|
11
12
|
|
12
13
|
def call(env)
|
@@ -49,7 +50,8 @@ module MessagePack
|
|
49
50
|
end
|
50
51
|
|
51
52
|
def unpack(env, body)
|
52
|
-
|
53
|
+
unpacker = @factory.unpacker
|
54
|
+
msg = unpacker.feed(body).read
|
53
55
|
env['msgpack-rpc.type'] = msg[0]
|
54
56
|
case msg[0]
|
55
57
|
when REQUEST
|
@@ -5,8 +5,9 @@ module MessagePack
|
|
5
5
|
# Rack Middleware that packs a result of a handler method and
|
6
6
|
# create a HTTP Responce.
|
7
7
|
class ResponsePacker
|
8
|
-
def initialize(dispatcher)
|
8
|
+
def initialize(dispatcher, factory = nil)
|
9
9
|
@dispatcher = dispatcher
|
10
|
+
@factory = factory || MessagePack::Factory.new
|
10
11
|
end
|
11
12
|
|
12
13
|
def call(env)
|
@@ -20,20 +21,26 @@ module MessagePack
|
|
20
21
|
res.body = body
|
21
22
|
return [res.status.to_i, res.header, body]
|
22
23
|
else
|
23
|
-
res.write
|
24
|
+
res.write pack(msgid, nil, body)
|
24
25
|
return res.finish
|
25
26
|
end
|
26
27
|
rescue RPCOverHTTP::RemoteError => ex
|
27
|
-
res.write
|
28
|
+
res.write pack(msgid, ex.class.name, ex.message)
|
28
29
|
return res.finish
|
29
30
|
rescue ::RuntimeError => ex
|
30
|
-
res.write(
|
31
|
-
msgid, RPCOverHTTP::RuntimeError.name, ex.message))
|
31
|
+
res.write(pack(msgid, RPCOverHTTP::RuntimeError.name, ex.message))
|
32
32
|
return res.finish
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
|
35
|
+
def pack(msgid, error, result)
|
36
|
+
packer = @factory.packer
|
37
|
+
packer.write([RESPONSE, msgid, error, result]).to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.pack(msgid, error, result, factory: nil)
|
41
|
+
factory ||= MessagePack::DefaultFactory
|
42
|
+
packer = factory.packer
|
43
|
+
packer.write([RESPONSE, msgid, error, result]).to_s
|
37
44
|
end
|
38
45
|
end
|
39
46
|
end
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
end
|
21
21
|
|
22
22
|
gem.add_runtime_dependency "rack"
|
23
|
-
gem.add_runtime_dependency "msgpack", "~> 0
|
23
|
+
gem.add_runtime_dependency "msgpack", "~> 1.0"
|
24
24
|
gem.add_runtime_dependency "celluloid", "~> 0.16.0"
|
25
25
|
gem.add_runtime_dependency "httpclient"
|
26
26
|
|
data/test/helper.rb
CHANGED
data/test/mock_server.ru
CHANGED
@@ -8,4 +8,16 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
8
8
|
require 'msgpack-rpc-over-http'
|
9
9
|
require 'helper'
|
10
10
|
|
11
|
-
|
11
|
+
class Time
|
12
|
+
def self.from_msgpack_ext(data)
|
13
|
+
sec, usec = MessagePack.unpack(data)
|
14
|
+
Time.at(sec, usec)
|
15
|
+
end
|
16
|
+
def to_msgpack_ext
|
17
|
+
[to_i, usec].to_msgpack
|
18
|
+
end
|
19
|
+
end
|
20
|
+
msgpack_factory = MessagePack::Factory.new
|
21
|
+
msgpack_factory.register_type(0x01, Time)
|
22
|
+
|
23
|
+
run MessagePack::RPCOverHTTP::Server.app(MockHandler.new, msgpack_factory)
|
data/test/test_client.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
require 'rack'
|
2
2
|
|
3
|
+
class Time
|
4
|
+
def self.from_msgpack_ext(data)
|
5
|
+
sec, usec = MessagePack.unpack(data)
|
6
|
+
Time.at(sec, usec)
|
7
|
+
end
|
8
|
+
def to_msgpack_ext
|
9
|
+
[to_i, usec].to_msgpack
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
3
13
|
module MessagePack::RPCOverHTTP
|
4
14
|
class TestClient < Test::Unit::TestCase
|
5
15
|
def self.unused_port
|
@@ -13,7 +23,9 @@ module MessagePack::RPCOverHTTP
|
|
13
23
|
@@is_stopped_test_app_server = true
|
14
24
|
|
15
25
|
def setup
|
16
|
-
|
26
|
+
msgpack_factory = MessagePack::Factory.new
|
27
|
+
msgpack_factory.register_type(0x01, Time)
|
28
|
+
@client = Client.new("http://0.0.0.0:#{@@server_port}/", factory: msgpack_factory)
|
17
29
|
if @@is_stopped_test_app_server
|
18
30
|
if /java/ =~ RUBY_PLATFORM
|
19
31
|
mizuno = nil
|
@@ -22,7 +34,7 @@ module MessagePack::RPCOverHTTP
|
|
22
34
|
require 'mizuno/server'
|
23
35
|
app = Rack::Builder.new {
|
24
36
|
# MockHandler is in helper.rb
|
25
|
-
run MessagePack::RPCOverHTTP::Server.app(MockHandler.new)
|
37
|
+
run MessagePack::RPCOverHTTP::Server.app(MockHandler.new, msgpack_factory)
|
26
38
|
}
|
27
39
|
mizuno = Mizuno::Server.new
|
28
40
|
mizuno.run(app, embedded: true, threads: 1, port: @@server_port, host: '0.0.0.0')
|
@@ -34,7 +46,7 @@ module MessagePack::RPCOverHTTP
|
|
34
46
|
end
|
35
47
|
else
|
36
48
|
pid = fork {
|
37
|
-
Rack::Server.start(config: "test/mock_server.ru", Port: @@server_port)
|
49
|
+
Rack::Server.start(config: "test/mock_server.ru", Port: @@server_port, Host: '0.0.0.0')
|
38
50
|
exit 0
|
39
51
|
}
|
40
52
|
at_exit do
|
@@ -42,7 +54,7 @@ module MessagePack::RPCOverHTTP
|
|
42
54
|
Process.waitpid(pid)
|
43
55
|
end
|
44
56
|
end
|
45
|
-
sleep_until_http_server_is_started("
|
57
|
+
sleep_until_http_server_is_started("127.0.0.1", @@server_port)
|
46
58
|
@@is_stopped_test_app_server = false
|
47
59
|
end
|
48
60
|
end
|
@@ -57,6 +69,13 @@ module MessagePack::RPCOverHTTP
|
|
57
69
|
end
|
58
70
|
end
|
59
71
|
|
72
|
+
def test_call_with_ext_type
|
73
|
+
require 'time'
|
74
|
+
t1 = Time.parse('2017-03-08 13:59:00')
|
75
|
+
t2 = Time.now
|
76
|
+
assert_equal [t1, t2], @client.call(:test, t1, t2)
|
77
|
+
end
|
78
|
+
|
60
79
|
def test_call_async
|
61
80
|
pend "msgpack-rpc-over-http does not support Client#async for jruby" if jruby?
|
62
81
|
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgpack-rpc-over-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Narihiro Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
|
-
- -
|
16
|
+
- - ">="
|
17
17
|
- !ruby/object:Gem::Version
|
18
18
|
version: '0'
|
19
19
|
name: rack
|
@@ -21,27 +21,27 @@ dependencies:
|
|
21
21
|
type: :runtime
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
|
-
- - ~>
|
30
|
+
- - "~>"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0
|
32
|
+
version: '1.0'
|
33
33
|
name: msgpack
|
34
34
|
prerelease: false
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - ~>
|
44
|
+
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 0.16.0
|
47
47
|
name: celluloid
|
@@ -49,13 +49,13 @@ dependencies:
|
|
49
49
|
type: :runtime
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.16.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
name: httpclient
|
@@ -63,13 +63,13 @@ dependencies:
|
|
63
63
|
type: :runtime
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
name: rake
|
@@ -77,13 +77,13 @@ dependencies:
|
|
77
77
|
type: :development
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- - ~>
|
86
|
+
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '3.0'
|
89
89
|
name: test-unit
|
@@ -91,7 +91,7 @@ dependencies:
|
|
91
91
|
type: :development
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.0'
|
97
97
|
description: This library provides MessagePack-RPC via HTTP
|
@@ -101,7 +101,7 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- .gitignore
|
104
|
+
- ".gitignore"
|
105
105
|
- Gemfile
|
106
106
|
- LICENSE
|
107
107
|
- README.md
|
@@ -129,17 +129,17 @@ require_paths:
|
|
129
129
|
- lib
|
130
130
|
required_ruby_version: !ruby/object:Gem::Requirement
|
131
131
|
requirements:
|
132
|
-
- -
|
132
|
+
- - ">="
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: '0'
|
135
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
|
-
- -
|
137
|
+
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.6.8
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: This library provides MessagePack-RPC via HTTP
|