actionwebservice 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/ChangeLog +47 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +238 -0
  4. data/Rakefile +144 -0
  5. data/TODO +13 -0
  6. data/examples/googlesearch/README +143 -0
  7. data/examples/googlesearch/autoloading/google_search_api.rb +50 -0
  8. data/examples/googlesearch/autoloading/google_search_controller.rb +57 -0
  9. data/examples/googlesearch/delegated/google_search_service.rb +108 -0
  10. data/examples/googlesearch/delegated/search_controller.rb +7 -0
  11. data/examples/googlesearch/direct/google_search_api.rb +50 -0
  12. data/examples/googlesearch/direct/search_controller.rb +58 -0
  13. data/examples/metaWeblog/README +16 -0
  14. data/examples/metaWeblog/blog_controller.rb +127 -0
  15. data/lib/action_web_service.rb +60 -0
  16. data/lib/action_web_service/api.rb +2 -0
  17. data/lib/action_web_service/api/abstract.rb +192 -0
  18. data/lib/action_web_service/api/action_controller.rb +92 -0
  19. data/lib/action_web_service/base.rb +41 -0
  20. data/lib/action_web_service/client.rb +3 -0
  21. data/lib/action_web_service/client/base.rb +39 -0
  22. data/lib/action_web_service/client/soap_client.rb +88 -0
  23. data/lib/action_web_service/client/xmlrpc_client.rb +77 -0
  24. data/lib/action_web_service/container.rb +85 -0
  25. data/lib/action_web_service/dispatcher.rb +2 -0
  26. data/lib/action_web_service/dispatcher/abstract.rb +150 -0
  27. data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +299 -0
  28. data/lib/action_web_service/invocation.rb +205 -0
  29. data/lib/action_web_service/protocol.rb +4 -0
  30. data/lib/action_web_service/protocol/abstract.rb +128 -0
  31. data/lib/action_web_service/protocol/registry.rb +55 -0
  32. data/lib/action_web_service/protocol/soap_protocol.rb +484 -0
  33. data/lib/action_web_service/protocol/xmlrpc_protocol.rb +168 -0
  34. data/lib/action_web_service/struct.rb +55 -0
  35. data/lib/action_web_service/support/class_inheritable_options.rb +26 -0
  36. data/lib/action_web_service/support/signature.rb +100 -0
  37. data/setup.rb +1360 -0
  38. data/test/abstract_client.rb +131 -0
  39. data/test/abstract_soap.rb +58 -0
  40. data/test/abstract_unit.rb +9 -0
  41. data/test/api_test.rb +52 -0
  42. data/test/base_test.rb +42 -0
  43. data/test/client_soap_test.rb +93 -0
  44. data/test/client_xmlrpc_test.rb +92 -0
  45. data/test/container_test.rb +53 -0
  46. data/test/dispatcher_action_controller_test.rb +186 -0
  47. data/test/gencov +3 -0
  48. data/test/invocation_test.rb +149 -0
  49. data/test/protocol_registry_test.rb +53 -0
  50. data/test/protocol_soap_test.rb +252 -0
  51. data/test/protocol_xmlrpc_test.rb +147 -0
  52. data/test/run +5 -0
  53. data/test/struct_test.rb +40 -0
  54. metadata +131 -0
@@ -0,0 +1,252 @@
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
@@ -0,0 +1,147 @@
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
data/test/run ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Dir[File.join(File.dirname(__FILE__), '*_test.rb')].each do |f|
4
+ require f
5
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/abstract_unit'
2
+
3
+ module StructTest
4
+ class Struct < ActionWebService::Struct
5
+ member :id, Integer
6
+ member :name, String
7
+ member :items, [String]
8
+ member :deleted, :bool
9
+ member :emails, [:string]
10
+ end
11
+ end
12
+
13
+ class TC_Struct < Test::Unit::TestCase
14
+ def test_members
15
+ assert_equal(5, StructTest::Struct.members.size)
16
+ assert_equal(Integer, StructTest::Struct.members[:id])
17
+ assert_equal(String, StructTest::Struct.members[:name])
18
+ assert_equal([String], StructTest::Struct.members[:items])
19
+ assert_equal(TrueClass, StructTest::Struct.members[:deleted])
20
+ assert_equal([String], StructTest::Struct.members[:emails])
21
+ end
22
+
23
+ def test_initializer_and_lookup
24
+ s = StructTest::Struct.new(:id => 5,
25
+ :name => 'hello',
26
+ :items => ['one', 'two'],
27
+ :deleted => true,
28
+ :emails => ['test@test.com'])
29
+ assert_equal(5, s.id)
30
+ assert_equal('hello', s.name)
31
+ assert_equal(['one', 'two'], s.items)
32
+ assert_equal(true, s.deleted)
33
+ assert_equal(['test@test.com'], s.emails)
34
+ assert_equal(5, s['id'])
35
+ assert_equal('hello', s['name'])
36
+ assert_equal(['one', 'two'], s['items'])
37
+ assert_equal(true, s['deleted'])
38
+ assert_equal(['test@test.com'], s['emails'])
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.4
3
+ specification_version: 1
4
+ name: actionwebservice
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.5.0
7
+ date: 2005-02-24
8
+ summary: Web service support for Action Pack.
9
+ require_paths:
10
+ - lib
11
+ email: bitserf@gmail.com
12
+ homepage: http://www.rubyonrails.org
13
+ rubyforge_project: aws
14
+ description: Adds WSDL/SOAP and XML-RPC web service support to Action Pack
15
+ autorequire: action_web_service
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ -
22
+ - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ authors:
28
+ - Leon Breedt
29
+ files:
30
+ - Rakefile
31
+ - setup.rb
32
+ - README
33
+ - TODO
34
+ - ChangeLog
35
+ - MIT-LICENSE
36
+ - examples/googlesearch
37
+ - examples/metaWeblog
38
+ - examples/googlesearch/autoloading
39
+ - examples/googlesearch/delegated
40
+ - examples/googlesearch/direct
41
+ - examples/googlesearch/README
42
+ - examples/googlesearch/autoloading/google_search_api.rb
43
+ - examples/googlesearch/autoloading/google_search_controller.rb
44
+ - examples/googlesearch/delegated/google_search_service.rb
45
+ - examples/googlesearch/delegated/search_controller.rb
46
+ - examples/googlesearch/direct/google_search_api.rb
47
+ - examples/googlesearch/direct/search_controller.rb
48
+ - examples/metaWeblog/blog_controller.rb
49
+ - examples/metaWeblog/README
50
+ - lib/action_web_service
51
+ - lib/action_web_service.rb
52
+ - lib/action_web_service/api
53
+ - lib/action_web_service/api.rb
54
+ - lib/action_web_service/base.rb
55
+ - lib/action_web_service/client
56
+ - lib/action_web_service/client.rb
57
+ - lib/action_web_service/container.rb
58
+ - lib/action_web_service/dispatcher
59
+ - lib/action_web_service/dispatcher.rb
60
+ - lib/action_web_service/invocation.rb
61
+ - lib/action_web_service/protocol
62
+ - lib/action_web_service/protocol.rb
63
+ - lib/action_web_service/struct.rb
64
+ - lib/action_web_service/support
65
+ - lib/action_web_service/api/abstract.rb
66
+ - lib/action_web_service/api/action_controller.rb
67
+ - lib/action_web_service/client/base.rb
68
+ - lib/action_web_service/client/soap_client.rb
69
+ - lib/action_web_service/client/xmlrpc_client.rb
70
+ - lib/action_web_service/dispatcher/abstract.rb
71
+ - lib/action_web_service/dispatcher/action_controller_dispatcher.rb
72
+ - lib/action_web_service/protocol/abstract.rb
73
+ - lib/action_web_service/protocol/registry.rb
74
+ - lib/action_web_service/protocol/soap_protocol.rb
75
+ - lib/action_web_service/protocol/xmlrpc_protocol.rb
76
+ - lib/action_web_service/support/class_inheritable_options.rb
77
+ - lib/action_web_service/support/signature.rb
78
+ - test/abstract_client.rb
79
+ - test/abstract_soap.rb
80
+ - test/abstract_unit.rb
81
+ - test/api_test.rb
82
+ - test/base_test.rb
83
+ - test/client_soap_test.rb
84
+ - test/client_xmlrpc_test.rb
85
+ - test/container_test.rb
86
+ - test/dispatcher_action_controller_test.rb
87
+ - test/gencov
88
+ - test/invocation_test.rb
89
+ - test/protocol_registry_test.rb
90
+ - test/protocol_soap_test.rb
91
+ - test/protocol_xmlrpc_test.rb
92
+ - test/run
93
+ - test/struct_test.rb
94
+ test_files: []
95
+ rdoc_options: []
96
+ extra_rdoc_files: []
97
+ executables: []
98
+ extensions: []
99
+ requirements:
100
+ - none
101
+ dependencies:
102
+ - !ruby/object:Gem::Dependency
103
+ name: actionpack
104
+ version_requirement:
105
+ version_requirements: !ruby/object:Gem::Version::Requirement
106
+ requirements:
107
+ -
108
+ - "="
109
+ - !ruby/object:Gem::Version
110
+ version: 1.5.0
111
+ version:
112
+ - !ruby/object:Gem::Dependency
113
+ name: activerecord
114
+ version_requirement:
115
+ version_requirements: !ruby/object:Gem::Version::Requirement
116
+ requirements:
117
+ -
118
+ - "="
119
+ - !ruby/object:Gem::Version
120
+ version: 1.7.0
121
+ version:
122
+ - !ruby/object:Gem::Dependency
123
+ name: activesupport
124
+ version_requirement:
125
+ version_requirements: !ruby/object:Gem::Version::Requirement
126
+ requirements:
127
+ -
128
+ - "="
129
+ - !ruby/object:Gem::Version
130
+ version: 1.0.0
131
+ version: