actionwebservice 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{ChangeLog → CHANGELOG} +20 -0
- data/README +45 -1
- data/Rakefile +12 -10
- data/TODO +8 -9
- data/lib/action_web_service.rb +10 -6
- data/lib/action_web_service/api.rb +1 -2
- data/lib/action_web_service/api/{abstract.rb → base.rb} +14 -71
- data/lib/action_web_service/base.rb +0 -3
- data/lib/action_web_service/client/base.rb +1 -12
- data/lib/action_web_service/client/soap_client.rb +49 -17
- data/lib/action_web_service/client/xmlrpc_client.rb +20 -15
- data/lib/action_web_service/container.rb +3 -85
- data/lib/action_web_service/{api/action_controller.rb → container/action_controller_container.rb} +2 -2
- data/lib/action_web_service/container/delegated_container.rb +87 -0
- data/lib/action_web_service/container/direct_container.rb +70 -0
- data/lib/action_web_service/dispatcher/abstract.rb +100 -102
- data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +199 -137
- data/lib/action_web_service/protocol.rb +1 -1
- data/lib/action_web_service/protocol/abstract.rb +14 -112
- data/lib/action_web_service/protocol/discovery.rb +37 -0
- data/lib/action_web_service/protocol/soap_protocol.rb +32 -458
- data/lib/action_web_service/protocol/xmlrpc_protocol.rb +29 -149
- data/lib/action_web_service/struct.rb +2 -5
- data/lib/action_web_service/test_invoke.rb +130 -0
- data/lib/action_web_service/vendor/ws.rb +4 -0
- data/lib/action_web_service/vendor/ws/common.rb +8 -0
- data/lib/action_web_service/vendor/ws/encoding.rb +3 -0
- data/lib/action_web_service/vendor/ws/encoding/abstract.rb +26 -0
- data/lib/action_web_service/vendor/ws/encoding/soap_rpc_encoding.rb +90 -0
- data/lib/action_web_service/vendor/ws/encoding/xmlrpc_encoding.rb +53 -0
- data/lib/action_web_service/vendor/ws/marshaling.rb +3 -0
- data/lib/action_web_service/vendor/ws/marshaling/abstract.rb +17 -0
- data/lib/action_web_service/vendor/ws/marshaling/soap_marshaling.rb +277 -0
- data/lib/action_web_service/vendor/ws/marshaling/xmlrpc_marshaling.rb +116 -0
- data/lib/action_web_service/vendor/ws/types.rb +162 -0
- data/test/abstract_client.rb +8 -11
- data/test/abstract_dispatcher.rb +370 -0
- data/test/abstract_unit.rb +1 -0
- data/test/api_test.rb +18 -1
- data/test/apis/auto_load_api.rb +3 -0
- data/test/apis/broken_auto_load_api.rb +2 -0
- data/test/client_soap_test.rb +16 -3
- data/test/client_xmlrpc_test.rb +16 -4
- data/test/container_test.rb +28 -8
- data/test/dispatcher_action_controller_soap_test.rb +106 -0
- data/test/dispatcher_action_controller_xmlrpc_test.rb +44 -0
- data/test/gencov +1 -1
- data/test/invocation_test.rb +39 -3
- data/test/run +4 -4
- data/test/test_invoke_test.rb +77 -0
- data/test/ws/abstract_encoding.rb +68 -0
- data/test/ws/abstract_unit.rb +13 -0
- data/test/ws/gencov +3 -0
- data/test/ws/run +5 -0
- data/test/ws/soap_marshaling_test.rb +91 -0
- data/test/ws/soap_rpc_encoding_test.rb +47 -0
- data/test/ws/types_test.rb +41 -0
- data/test/ws/xmlrpc_encoding_test.rb +34 -0
- metadata +48 -19
- data/lib/action_web_service/protocol/registry.rb +0 -55
- data/lib/action_web_service/support/signature.rb +0 -100
- data/test/abstract_soap.rb +0 -58
- data/test/dispatcher_action_controller_test.rb +0 -186
- data/test/protocol_registry_test.rb +0 -53
- data/test/protocol_soap_test.rb +0 -252
- data/test/protocol_xmlrpc_test.rb +0 -147
data/test/protocol_soap_test.rb
DELETED
@@ -1,252 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/abstract_soap'
|
2
|
-
|
3
|
-
module ProtocolSoapTest
|
4
|
-
class Person < ActionWebService::Struct
|
5
|
-
member :id, Integer
|
6
|
-
member :names, [String]
|
7
|
-
member :lastname, String
|
8
|
-
member :deleted, TrueClass
|
9
|
-
|
10
|
-
def ==(other)
|
11
|
-
id == other.id && names == other.names && lastname == other.lastname && deleted == other.deleted
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class EmptyAPI < ActionWebService::API::Base
|
16
|
-
end
|
17
|
-
|
18
|
-
class EmptyService < ActionWebService::Base
|
19
|
-
web_service_api EmptyAPI
|
20
|
-
end
|
21
|
-
|
22
|
-
class API < ActionWebService::API::Base
|
23
|
-
api_method :argument_passing, :expects => [{:int=>:int}, {:string=>:string}, {:array=>[:int]}], :returns => [:bool]
|
24
|
-
api_method :array_returner, :returns => [[:int]]
|
25
|
-
api_method :nil_returner
|
26
|
-
api_method :struct_array_returner, :returns => [[Person]]
|
27
|
-
api_method :exception_thrower
|
28
|
-
|
29
|
-
default_api_method :default
|
30
|
-
end
|
31
|
-
|
32
|
-
class Service < ActionWebService::Base
|
33
|
-
web_service_api API
|
34
|
-
|
35
|
-
attr :int
|
36
|
-
attr :string
|
37
|
-
attr :array
|
38
|
-
attr :values
|
39
|
-
attr :person
|
40
|
-
attr :default_args
|
41
|
-
|
42
|
-
def initialize
|
43
|
-
@int = 20
|
44
|
-
@string = "wrong string value"
|
45
|
-
@default_args = nil
|
46
|
-
end
|
47
|
-
|
48
|
-
def argument_passing(int, string, array)
|
49
|
-
@int = int
|
50
|
-
@string = string
|
51
|
-
@array = array
|
52
|
-
true
|
53
|
-
end
|
54
|
-
|
55
|
-
def array_returner
|
56
|
-
@values = [1, 2, 3]
|
57
|
-
end
|
58
|
-
|
59
|
-
def nil_returner
|
60
|
-
nil
|
61
|
-
end
|
62
|
-
|
63
|
-
def struct_array_returner
|
64
|
-
@person = Person.new
|
65
|
-
@person.id = 5
|
66
|
-
@person.names = ["one", "two"]
|
67
|
-
@person.lastname = "test"
|
68
|
-
@person.deleted = false
|
69
|
-
[@person]
|
70
|
-
end
|
71
|
-
|
72
|
-
def exception_thrower
|
73
|
-
raise "Hi, I'm a SOAP error"
|
74
|
-
end
|
75
|
-
|
76
|
-
def default(*args)
|
77
|
-
@default_args = args
|
78
|
-
nil
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class AbstractContainer < ActionController::Base
|
83
|
-
wsdl_service_name 'Test'
|
84
|
-
|
85
|
-
def dispatch_request(request)
|
86
|
-
protocol_request = probe_request_protocol(request)
|
87
|
-
dispatch_protocol_request(protocol_request)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
class DelegatedContainer < AbstractContainer
|
92
|
-
web_service_dispatching_mode :delegated
|
93
|
-
web_service :protocol_soap_service, Service.new
|
94
|
-
web_service :empty_service, EmptyService.new
|
95
|
-
end
|
96
|
-
|
97
|
-
class DirectContainer < AbstractContainer
|
98
|
-
web_service_api API
|
99
|
-
web_service_dispatching_mode :direct
|
100
|
-
|
101
|
-
attr :int
|
102
|
-
attr :string
|
103
|
-
attr :array
|
104
|
-
attr :values
|
105
|
-
attr :person
|
106
|
-
attr :default_args
|
107
|
-
|
108
|
-
def initialize
|
109
|
-
@int = 20
|
110
|
-
@string = "wrong string value"
|
111
|
-
@default_args = nil
|
112
|
-
end
|
113
|
-
|
114
|
-
def argument_passing
|
115
|
-
@int = @params['int']
|
116
|
-
@string = @params['string']
|
117
|
-
@array = @params['array']
|
118
|
-
true
|
119
|
-
end
|
120
|
-
|
121
|
-
def array_returner
|
122
|
-
@values = [1, 2, 3]
|
123
|
-
end
|
124
|
-
|
125
|
-
def nil_returner
|
126
|
-
nil
|
127
|
-
end
|
128
|
-
|
129
|
-
def struct_array_returner
|
130
|
-
@person = Person.new
|
131
|
-
@person.id = 5
|
132
|
-
@person.names = ["one", "two"]
|
133
|
-
@person.lastname = "test"
|
134
|
-
@person.deleted = false
|
135
|
-
[@person]
|
136
|
-
end
|
137
|
-
|
138
|
-
def exception_thrower
|
139
|
-
raise "Hi, I'm a SOAP error"
|
140
|
-
end
|
141
|
-
|
142
|
-
def default
|
143
|
-
@default_args = @method_params
|
144
|
-
nil
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
class EmptyContainer < AbstractContainer
|
149
|
-
web_service_dispatching_mode :delegated
|
150
|
-
web_service :empty_service, EmptyService.new
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
class TC_ProtocolSoap < AbstractSoapTest
|
155
|
-
def setup
|
156
|
-
@delegated_container = ProtocolSoapTest::DelegatedContainer.new
|
157
|
-
@direct_container = ProtocolSoapTest::DirectContainer.new
|
158
|
-
@empty_container = ProtocolSoapTest::EmptyContainer.new
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_argument_passing
|
162
|
-
in_all_containers do
|
163
|
-
assert(do_soap_call('ArgumentPassing', 5, "test string", [true, false]) == true)
|
164
|
-
assert(service.int == 5)
|
165
|
-
assert(service.string == "test string")
|
166
|
-
assert(service.array == [true, false])
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_array_returner
|
171
|
-
in_all_containers do
|
172
|
-
assert(do_soap_call('ArrayReturner') == [1, 2, 3])
|
173
|
-
assert(service.values == [1, 2, 3])
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
def test_nil_returner
|
178
|
-
in_all_containers do
|
179
|
-
assert(do_soap_call('NilReturner') == nil)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_struct_array_returner
|
184
|
-
in_all_containers do
|
185
|
-
assert(do_soap_call('StructArrayReturner') == [service.person])
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_nonexistent_method
|
190
|
-
@container = @empty_container
|
191
|
-
assert_raises(ActionWebService::Dispatcher::DispatcherError) do
|
192
|
-
do_soap_call('NonexistentMethod')
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_exception_thrower
|
197
|
-
in_all_containers do
|
198
|
-
assert_raises(RuntimeError) do
|
199
|
-
do_soap_call('ExceptionThrower')
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_default_api_method
|
205
|
-
in_all_containers do
|
206
|
-
assert(do_soap_call('NonExistentMethodName', 50, false).nil?)
|
207
|
-
assert(service.default_args == [50, false])
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_service_name_setting
|
212
|
-
in_all_containers do
|
213
|
-
assert(ProtocolSoapTest::DelegatedContainer.soap_mapper.custom_namespace == 'urn:Test')
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
protected
|
218
|
-
def service_name
|
219
|
-
case
|
220
|
-
when @container == @direct_container
|
221
|
-
'api'
|
222
|
-
when @container == @delegated_container
|
223
|
-
'protocol_soap_service'
|
224
|
-
when @container == @empty_container
|
225
|
-
'empty_service'
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
def service
|
230
|
-
case
|
231
|
-
when @container == @direct_container
|
232
|
-
@container
|
233
|
-
when @container == @delegated_container
|
234
|
-
@container.web_service_object(:protocol_soap_service)
|
235
|
-
when @container == @empty_container
|
236
|
-
@container.web_service_object(:empty_service)
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def in_all_containers(&block)
|
241
|
-
[@direct_container, @delegated_container].each do |container|
|
242
|
-
@container = container
|
243
|
-
block.call
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
def do_soap_call(public_method_name, *args)
|
248
|
-
super(public_method_name, *args) do |test_request, test_response|
|
249
|
-
@container.dispatch_request(test_request)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/abstract_unit'
|
2
|
-
require 'xmlrpc/parser'
|
3
|
-
require 'xmlrpc/create'
|
4
|
-
require 'xmlrpc/config'
|
5
|
-
|
6
|
-
module XMLRPC
|
7
|
-
class XmlRpcTestHelper
|
8
|
-
include ParserWriterChooseMixin
|
9
|
-
|
10
|
-
def create_request(methodName, *args)
|
11
|
-
create().methodCall(methodName, *args)
|
12
|
-
end
|
13
|
-
|
14
|
-
def parse_response(response)
|
15
|
-
parser().parseMethodResponse(response)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
module ProtocolXmlRpcTest
|
21
|
-
class Person < ActionWebService::Struct
|
22
|
-
member :firstname, String
|
23
|
-
member :lastname, String
|
24
|
-
member :active, TrueClass
|
25
|
-
end
|
26
|
-
|
27
|
-
class API < ActionWebService::API::Base
|
28
|
-
api_method :add, :expects => [Integer, Integer], :returns => [Integer]
|
29
|
-
api_method :hash_returner, :returns => [Hash]
|
30
|
-
api_method :array_returner, :returns => [[Integer]]
|
31
|
-
api_method :something_hash, :expects => [Hash]
|
32
|
-
api_method :struct_array_returner, :returns => [[Person]]
|
33
|
-
|
34
|
-
default_api_method :default
|
35
|
-
end
|
36
|
-
|
37
|
-
class Service < ActionWebService::Base
|
38
|
-
web_service_api API
|
39
|
-
|
40
|
-
attr :result
|
41
|
-
attr :hashvalue
|
42
|
-
attr :default_args
|
43
|
-
|
44
|
-
def initialize
|
45
|
-
@result = nil
|
46
|
-
@hashvalue = nil
|
47
|
-
@default_args = nil
|
48
|
-
end
|
49
|
-
|
50
|
-
def add(a, b)
|
51
|
-
@result = a + b
|
52
|
-
end
|
53
|
-
|
54
|
-
def something_hash(hash)
|
55
|
-
@hashvalue = hash
|
56
|
-
end
|
57
|
-
|
58
|
-
def array_returner
|
59
|
-
[1, 2, 3]
|
60
|
-
end
|
61
|
-
|
62
|
-
def hash_returner
|
63
|
-
{'name' => 1, 'value' => 2}
|
64
|
-
end
|
65
|
-
|
66
|
-
def struct_array_returner
|
67
|
-
person = Person.new
|
68
|
-
person.firstname = "John"
|
69
|
-
person.lastname = "Doe"
|
70
|
-
person.active = true
|
71
|
-
[person]
|
72
|
-
end
|
73
|
-
|
74
|
-
def default(*args)
|
75
|
-
@default_args = args
|
76
|
-
nil
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
$service = Service.new
|
81
|
-
|
82
|
-
class Container < ActionController::Base
|
83
|
-
def protocol_request(request)
|
84
|
-
probe_request_protocol(request)
|
85
|
-
end
|
86
|
-
|
87
|
-
def dispatch_request(protocol_request)
|
88
|
-
dispatch_protocol_request(protocol_request)
|
89
|
-
end
|
90
|
-
|
91
|
-
web_service :xmlrpc, $service
|
92
|
-
web_service_dispatching_mode :delegated
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
class TC_ProtocolXmlRpc < Test::Unit::TestCase
|
97
|
-
def setup
|
98
|
-
@helper = XMLRPC::XmlRpcTestHelper.new
|
99
|
-
@container = ProtocolXmlRpcTest::Container.new
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_xmlrpc_request_dispatching
|
103
|
-
retval = do_xmlrpc_call('Add', 50, 30)
|
104
|
-
assert(retval == [true, 80])
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_array_returning
|
108
|
-
retval = do_xmlrpc_call('ArrayReturner')
|
109
|
-
assert(retval == [true, [1, 2, 3]])
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_hash_returning
|
113
|
-
retval = do_xmlrpc_call('HashReturner')
|
114
|
-
assert(retval == [true, {'name' => 1, 'value' => 2}])
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_struct_array_returning
|
118
|
-
retval = do_xmlrpc_call('StructArrayReturner')
|
119
|
-
assert(retval == [true, [{"firstname"=>"John", "lastname"=>"Doe", "active"=>true}]])
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_hash_parameter
|
123
|
-
retval = do_xmlrpc_call('SomethingHash', {'name' => 1, 'value' => 2})
|
124
|
-
assert(retval == [true, true])
|
125
|
-
assert($service.hashvalue == {'name' => 1, 'value' => 2})
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_default_api_method
|
129
|
-
retval = do_xmlrpc_call('SomeNonexistentMethod', 'test', [1, 2], {'name'=>'value'})
|
130
|
-
assert(retval == [true, true])
|
131
|
-
assert($service.default_args == ['test', [1, 2], {'name'=>'value'}])
|
132
|
-
end
|
133
|
-
|
134
|
-
private
|
135
|
-
def do_xmlrpc_call(public_method_name, *args)
|
136
|
-
service_name = 'xmlrpc'
|
137
|
-
raw_request = @helper.create_request(public_method_name, *args)
|
138
|
-
test_request = ActionController::TestRequest.new
|
139
|
-
test_request.request_parameters['action'] = service_name
|
140
|
-
test_request.env['REQUEST_METHOD'] = "POST"
|
141
|
-
test_request.env['HTTP_CONTENTTYPE'] = 'text/xml'
|
142
|
-
test_request.env['RAW_POST_DATA'] = raw_request
|
143
|
-
protocol_request = @container.protocol_request(test_request)
|
144
|
-
response = @container.dispatch_request(protocol_request)
|
145
|
-
@helper.parse_response(response.raw_body)
|
146
|
-
end
|
147
|
-
end
|