rubyjedi-actionwebservice 2.3.5.20100615120735
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +335 -0
- data/MIT-LICENSE +21 -0
- data/README +381 -0
- data/Rakefile +180 -0
- data/TODO +32 -0
- data/examples/googlesearch/README +143 -0
- data/examples/googlesearch/autoloading/google_search_api.rb +50 -0
- data/examples/googlesearch/autoloading/google_search_controller.rb +57 -0
- data/examples/googlesearch/delegated/google_search_service.rb +108 -0
- data/examples/googlesearch/delegated/search_controller.rb +7 -0
- data/examples/googlesearch/direct/google_search_api.rb +50 -0
- data/examples/googlesearch/direct/search_controller.rb +58 -0
- data/examples/metaWeblog/README +17 -0
- data/examples/metaWeblog/apis/blogger_api.rb +60 -0
- data/examples/metaWeblog/apis/blogger_service.rb +34 -0
- data/examples/metaWeblog/apis/meta_weblog_api.rb +67 -0
- data/examples/metaWeblog/apis/meta_weblog_service.rb +48 -0
- data/examples/metaWeblog/controllers/xmlrpc_controller.rb +16 -0
- data/generators/web_service/USAGE +28 -0
- data/generators/web_service/templates/api_definition.rb +5 -0
- data/generators/web_service/templates/controller.rb +8 -0
- data/generators/web_service/templates/functional_test.rb +19 -0
- data/generators/web_service/web_service_generator.rb +29 -0
- data/lib/action_web_service/acts_as_web_service.rb +24 -0
- data/lib/action_web_service/api.rb +297 -0
- data/lib/action_web_service/base.rb +38 -0
- data/lib/action_web_service/casting.rb +151 -0
- data/lib/action_web_service/client/base.rb +28 -0
- data/lib/action_web_service/client/soap_client.rb +113 -0
- data/lib/action_web_service/client/xmlrpc_client.rb +58 -0
- data/lib/action_web_service/client.rb +3 -0
- data/lib/action_web_service/container/action_controller_container.rb +93 -0
- data/lib/action_web_service/container/delegated_container.rb +86 -0
- data/lib/action_web_service/container/direct_container.rb +69 -0
- data/lib/action_web_service/container.rb +3 -0
- data/lib/action_web_service/dispatcher/abstract.rb +208 -0
- data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +396 -0
- data/lib/action_web_service/dispatcher.rb +2 -0
- data/lib/action_web_service/invocation.rb +202 -0
- data/lib/action_web_service/protocol/abstract.rb +112 -0
- data/lib/action_web_service/protocol/discovery.rb +37 -0
- data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +242 -0
- data/lib/action_web_service/protocol/soap_protocol.rb +176 -0
- data/lib/action_web_service/protocol/xmlrpc_protocol.rb +123 -0
- data/lib/action_web_service/protocol.rb +4 -0
- data/lib/action_web_service/scaffolding.rb +281 -0
- data/lib/action_web_service/simple.rb +53 -0
- data/lib/action_web_service/string_to_datetime_for_soap.rb +16 -0
- data/lib/action_web_service/struct.rb +68 -0
- data/lib/action_web_service/support/class_inheritable_options.rb +26 -0
- data/lib/action_web_service/support/signature_types.rb +261 -0
- data/lib/action_web_service/templates/scaffolds/layout.html.erb +65 -0
- data/lib/action_web_service/templates/scaffolds/methods.html.erb +6 -0
- data/lib/action_web_service/templates/scaffolds/parameters.html.erb +29 -0
- data/lib/action_web_service/templates/scaffolds/result.html.erb +30 -0
- data/lib/action_web_service/test_invoke.rb +110 -0
- data/lib/action_web_service/version.rb +9 -0
- data/lib/action_web_service.rb +60 -0
- data/lib/actionwebservice.rb +1 -0
- data/setup.rb +1379 -0
- data/test/abstract_client.rb +184 -0
- data/test/abstract_dispatcher.rb +549 -0
- data/test/abstract_unit.rb +43 -0
- data/test/actionwebservice_unittest.db +0 -0
- data/test/api_test.rb +102 -0
- data/test/apis/auto_load_api.rb +3 -0
- data/test/apis/broken_auto_load_api.rb +2 -0
- data/test/base_test.rb +42 -0
- data/test/casting_test.rb +95 -0
- data/test/client_soap_test.rb +156 -0
- data/test/client_xmlrpc_test.rb +154 -0
- data/test/container_test.rb +75 -0
- data/test/debug.log +12305 -0
- data/test/dispatcher_action_controller_soap_test.rb +139 -0
- data/test/dispatcher_action_controller_xmlrpc_test.rb +59 -0
- data/test/fixtures/db_definitions/mysql.sql +8 -0
- data/test/fixtures/db_definitions/sqlite3.sql +8 -0
- data/test/fixtures/users.yml +12 -0
- data/test/gencov +3 -0
- data/test/invocation_test.rb +186 -0
- data/test/run +6 -0
- data/test/scaffolded_controller_test.rb +147 -0
- data/test/struct_test.rb +84 -0
- data/test/test_invoke_test.rb +113 -0
- metadata +182 -0
@@ -0,0 +1,261 @@
|
|
1
|
+
module ActionWebService # :nodoc:
|
2
|
+
# Action Web Service supports the following base types in a signature:
|
3
|
+
#
|
4
|
+
# [<tt>:int</tt>] Represents an integer value, will be cast to an integer using <tt>Integer(value)</tt>
|
5
|
+
# [<tt>:string</tt>] Represents a string value, will be cast to an string using the <tt>to_s</tt> method on an object
|
6
|
+
# [<tt>:base64</tt>] Represents a Base 64 value, will contain the binary bytes of a Base 64 value sent by the caller
|
7
|
+
# [<tt>:bool</tt>] Represents a boolean value, whatever is passed will be cast to boolean (<tt>true</tt>, '1', 'true', 'y', 'yes' are taken to represent true; <tt>false</tt>, '0', 'false', 'n', 'no' and <tt>nil</tt> represent false)
|
8
|
+
# [<tt>:float</tt>] Represents a floating point value, will be cast to a float using <tt>Float(value)</tt>
|
9
|
+
# [<tt>:time</tt>] Represents a timestamp, will be cast to a <tt>Time</tt> object
|
10
|
+
# [<tt>:datetime</tt>] Represents a timestamp, will be cast to a <tt>DateTime</tt> object
|
11
|
+
# [<tt>:date</tt>] Represents a date, will be cast to a <tt>Date</tt> object
|
12
|
+
#
|
13
|
+
# For structured types, you'll need to pass in the Class objects of
|
14
|
+
# ActionWebService::Struct and ActiveRecord::Base derivatives.
|
15
|
+
module SignatureTypes
|
16
|
+
def canonical_signature(signature) # :nodoc:
|
17
|
+
return nil if signature.nil?
|
18
|
+
unless signature.is_a?(Array)
|
19
|
+
raise(ActionWebServiceError, "Expected signature to be an Array")
|
20
|
+
end
|
21
|
+
i = -1
|
22
|
+
signature.map{ |spec| canonical_signature_entry(spec, i += 1) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def canonical_signature_entry(spec, i) # :nodoc:
|
26
|
+
orig_spec = spec
|
27
|
+
name = "param#{i}"
|
28
|
+
if spec.is_a?(Hash)
|
29
|
+
name, spec = spec.keys.first, spec.values.first
|
30
|
+
end
|
31
|
+
type = spec
|
32
|
+
if spec.is_a?(Array)
|
33
|
+
ArrayType.new(orig_spec, canonical_signature_entry(spec[0], 0), name)
|
34
|
+
else
|
35
|
+
type = canonical_type(type)
|
36
|
+
if type.is_a?(Symbol)
|
37
|
+
BaseType.new(orig_spec, type, name)
|
38
|
+
else
|
39
|
+
if type.is_a?(Hash)
|
40
|
+
complexity, type = type.keys.first.to_sym, type.values.first
|
41
|
+
end
|
42
|
+
element = complexity || :complex
|
43
|
+
element == :simple ? SimpleType.new(orig_spec, type, name) : StructuredType.new(orig_spec, type, name)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def canonical_type(type) # :nodoc:
|
49
|
+
type_name = symbol_name(type) || class_to_type_name(type)
|
50
|
+
type = type_name || type
|
51
|
+
return canonical_type_name(type) if type.is_a?(Symbol)
|
52
|
+
type
|
53
|
+
end
|
54
|
+
|
55
|
+
def canonical_type_name(name) # :nodoc:
|
56
|
+
name = name.to_sym
|
57
|
+
case name
|
58
|
+
when :int, :integer, :fixnum, :bignum
|
59
|
+
:int
|
60
|
+
when :string, :text
|
61
|
+
:string
|
62
|
+
when :base64, :binary
|
63
|
+
:base64
|
64
|
+
when :bool, :boolean
|
65
|
+
:bool
|
66
|
+
when :float, :double
|
67
|
+
:float
|
68
|
+
when :decimal
|
69
|
+
:decimal
|
70
|
+
when :time, :timestamp
|
71
|
+
:time
|
72
|
+
when :datetime
|
73
|
+
:datetime
|
74
|
+
when :date
|
75
|
+
:date
|
76
|
+
else
|
77
|
+
raise(TypeError, "#{name} is not a valid base type")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def canonical_type_class(type) # :nodoc:
|
82
|
+
type = canonical_type(type)
|
83
|
+
type.is_a?(Symbol) ? type_name_to_class(type) : type
|
84
|
+
end
|
85
|
+
|
86
|
+
def symbol_name(name) # :nodoc:
|
87
|
+
return name.to_sym if name.is_a?(Symbol) || name.is_a?(String)
|
88
|
+
nil
|
89
|
+
end
|
90
|
+
|
91
|
+
def class_to_type_name(klass) # :nodoc:
|
92
|
+
klass = klass.class unless klass.is_a?(Class)
|
93
|
+
if derived_from?(Integer, klass) || derived_from?(Fixnum, klass) || derived_from?(Bignum, klass)
|
94
|
+
:int
|
95
|
+
elsif klass == String
|
96
|
+
:string
|
97
|
+
elsif klass == Base64
|
98
|
+
:base64
|
99
|
+
elsif klass == TrueClass || klass == FalseClass
|
100
|
+
:bool
|
101
|
+
elsif derived_from?(Float, klass)
|
102
|
+
:float
|
103
|
+
elsif RUBY_VERSION < '1.9' && derived_from?(Precision, klass)
|
104
|
+
:float
|
105
|
+
elsif derived_from?(Numeric, klass)
|
106
|
+
:float
|
107
|
+
elsif klass == Time
|
108
|
+
:time
|
109
|
+
elsif klass == DateTime
|
110
|
+
:datetime
|
111
|
+
elsif klass == Date
|
112
|
+
:date
|
113
|
+
else
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def type_name_to_class(name) # :nodoc:
|
119
|
+
case canonical_type_name(name)
|
120
|
+
when :int
|
121
|
+
Integer
|
122
|
+
when :string
|
123
|
+
String
|
124
|
+
when :base64
|
125
|
+
Base64
|
126
|
+
when :bool
|
127
|
+
TrueClass
|
128
|
+
when :float
|
129
|
+
Float
|
130
|
+
when :decimal
|
131
|
+
BigDecimal
|
132
|
+
when :time
|
133
|
+
Time
|
134
|
+
when :date
|
135
|
+
Date
|
136
|
+
when :datetime
|
137
|
+
DateTime
|
138
|
+
else
|
139
|
+
nil
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def derived_from?(ancestor, child) # :nodoc:
|
144
|
+
child.ancestors.include?(ancestor)
|
145
|
+
end
|
146
|
+
|
147
|
+
module_function :type_name_to_class
|
148
|
+
module_function :class_to_type_name
|
149
|
+
module_function :symbol_name
|
150
|
+
module_function :canonical_type_class
|
151
|
+
module_function :canonical_type_name
|
152
|
+
module_function :canonical_type
|
153
|
+
module_function :canonical_signature_entry
|
154
|
+
module_function :canonical_signature
|
155
|
+
module_function :derived_from?
|
156
|
+
end
|
157
|
+
|
158
|
+
class BaseType # :nodoc:
|
159
|
+
include SignatureTypes
|
160
|
+
|
161
|
+
attr :spec
|
162
|
+
attr :type
|
163
|
+
attr :type_class
|
164
|
+
attr :name
|
165
|
+
|
166
|
+
def initialize(spec, type, name)
|
167
|
+
@spec = spec
|
168
|
+
@type = canonical_type(type)
|
169
|
+
@type_class = canonical_type_class(@type)
|
170
|
+
@name = name
|
171
|
+
end
|
172
|
+
|
173
|
+
def custom?
|
174
|
+
false
|
175
|
+
end
|
176
|
+
|
177
|
+
def array?
|
178
|
+
false
|
179
|
+
end
|
180
|
+
|
181
|
+
def structured?
|
182
|
+
false
|
183
|
+
end
|
184
|
+
|
185
|
+
def simple?
|
186
|
+
false
|
187
|
+
end
|
188
|
+
|
189
|
+
def human_name(show_name=true)
|
190
|
+
type_type = array? ? element_type.type.to_s : self.type.to_s
|
191
|
+
str = array? ? (type_type + '[]') : type_type
|
192
|
+
show_name ? (str + " " + name.to_s) : str
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
class ArrayType < BaseType # :nodoc:
|
197
|
+
attr :element_type
|
198
|
+
|
199
|
+
def initialize(spec, element_type, name)
|
200
|
+
super(spec, Array, name)
|
201
|
+
@element_type = element_type
|
202
|
+
end
|
203
|
+
|
204
|
+
def custom?
|
205
|
+
true
|
206
|
+
end
|
207
|
+
|
208
|
+
def array?
|
209
|
+
true
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
class StructuredType < BaseType # :nodoc:
|
214
|
+
def each_member
|
215
|
+
if @type_class.respond_to?(:members)
|
216
|
+
@type_class.members.each do |name, type_options|
|
217
|
+
type, options = type_options
|
218
|
+
yield name, type, options
|
219
|
+
end
|
220
|
+
elsif @type_class.respond_to?(:columns)
|
221
|
+
i = -1
|
222
|
+
@type_class.columns.each do |column|
|
223
|
+
yield column.name, canonical_signature_entry(column.type, i += 1)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def custom?
|
229
|
+
true
|
230
|
+
end
|
231
|
+
|
232
|
+
def structured?
|
233
|
+
true
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
class SimpleType < BaseType # :nodoc:
|
238
|
+
def base
|
239
|
+
@type_class.restriction_base if @type_class.respond_to?(:restriction_base)
|
240
|
+
end
|
241
|
+
|
242
|
+
def restrictions
|
243
|
+
if @type_class.respond_to?(:restrictions)
|
244
|
+
@type_class.restrictions.each do |name, value|
|
245
|
+
yield name, value
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def custom?
|
251
|
+
true
|
252
|
+
end
|
253
|
+
|
254
|
+
def simple?
|
255
|
+
true
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
class Base64 < String # :nodoc:
|
260
|
+
end
|
261
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title><%= @scaffold_class.wsdl_service_name %> Web Service</title>
|
4
|
+
<style>
|
5
|
+
body { background-color: #fff; color: #333; }
|
6
|
+
|
7
|
+
body, p, ol, ul, td {
|
8
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
9
|
+
font-size: 13px;
|
10
|
+
line-height: 18px;
|
11
|
+
}
|
12
|
+
|
13
|
+
pre {
|
14
|
+
background-color: #eee;
|
15
|
+
padding: 10px;
|
16
|
+
font-size: 11px;
|
17
|
+
}
|
18
|
+
|
19
|
+
a { color: #000; }
|
20
|
+
a:visited { color: #666; }
|
21
|
+
a:hover { color: #fff; background-color:#000; }
|
22
|
+
|
23
|
+
.fieldWithErrors {
|
24
|
+
padding: 2px;
|
25
|
+
background-color: red;
|
26
|
+
display: table;
|
27
|
+
}
|
28
|
+
|
29
|
+
#errorExplanation {
|
30
|
+
width: 400px;
|
31
|
+
border: 2px solid red;
|
32
|
+
padding: 7px;
|
33
|
+
padding-bottom: 12px;
|
34
|
+
margin-bottom: 20px;
|
35
|
+
background-color: #f0f0f0;
|
36
|
+
}
|
37
|
+
|
38
|
+
#errorExplanation h2 {
|
39
|
+
text-align: left;
|
40
|
+
font-weight: bold;
|
41
|
+
padding: 5px 5px 5px 15px;
|
42
|
+
font-size: 12px;
|
43
|
+
margin: -7px;
|
44
|
+
background-color: #c00;
|
45
|
+
color: #fff;
|
46
|
+
}
|
47
|
+
|
48
|
+
#errorExplanation p {
|
49
|
+
color: #333;
|
50
|
+
margin-bottom: 0;
|
51
|
+
padding: 5px;
|
52
|
+
}
|
53
|
+
|
54
|
+
#errorExplanation ul li {
|
55
|
+
font-size: 12px;
|
56
|
+
list-style: square;
|
57
|
+
}
|
58
|
+
</style>
|
59
|
+
</head>
|
60
|
+
<body>
|
61
|
+
|
62
|
+
<%= @content_for_layout %>
|
63
|
+
|
64
|
+
</body>
|
65
|
+
</html>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<h4>Method Invocation Details for <em><%= @scaffold_service %>#<%= @scaffold_method.public_name %></em></h4>
|
2
|
+
|
3
|
+
<% form_tag(:action => @scaffold_action_name + '_submit') do -%>
|
4
|
+
<%= hidden_field_tag "service", @scaffold_service.name %>
|
5
|
+
<%= hidden_field_tag "method", @scaffold_method.public_name %>
|
6
|
+
|
7
|
+
<p>
|
8
|
+
<label for="protocol">Protocol:</label><br />
|
9
|
+
<%= select_tag 'protocol', options_for_select([['SOAP', 'soap'], ['XML-RPC', 'xmlrpc']], params['protocol']) %>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
<% if @scaffold_method.expects %>
|
13
|
+
|
14
|
+
<strong>Method Parameters:</strong><br />
|
15
|
+
<% @scaffold_method.expects.each_with_index do |type, i| %>
|
16
|
+
<p>
|
17
|
+
<label for="method_params[<%= i %>]"><%= method_parameter_label(type.name, type) %> </label><br />
|
18
|
+
<%= method_parameter_input_fields(@scaffold_method, type, "method_params", i) %>
|
19
|
+
</p>
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<% end %>
|
23
|
+
|
24
|
+
<%= submit_tag "Invoke" %>
|
25
|
+
<% end -%>
|
26
|
+
|
27
|
+
<p>
|
28
|
+
<%= link_to "Back", :action => @scaffold_action_name %>
|
29
|
+
</p>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<h4>Method Invocation Result for <em><%= @scaffold_service %>#<%= @scaffold_method.public_name %></em></h4>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
Invocation took <tt><%= '%f' % @method_elapsed %></tt> seconds
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<p>
|
8
|
+
<strong>Return Value:</strong><br />
|
9
|
+
<pre>
|
10
|
+
<%= h @method_return_value.inspect %>
|
11
|
+
</pre>
|
12
|
+
</p>
|
13
|
+
|
14
|
+
<p>
|
15
|
+
<strong>Request XML:</strong><br />
|
16
|
+
<pre>
|
17
|
+
<%= h @method_request_xml %>
|
18
|
+
</pre>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<p>
|
22
|
+
<strong>Response XML:</strong><br />
|
23
|
+
<pre>
|
24
|
+
<%= h @method_response_xml %>
|
25
|
+
</pre>
|
26
|
+
</p>
|
27
|
+
|
28
|
+
<p>
|
29
|
+
<%= link_to "Back", :action => @scaffold_action_name + '_method_params', :method => @scaffold_method.public_name, :service => @scaffold_service.name %>
|
30
|
+
</p>
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
module Test # :nodoc:
|
4
|
+
module Unit # :nodoc:
|
5
|
+
class TestCase # :nodoc:
|
6
|
+
private
|
7
|
+
# invoke the specified API method
|
8
|
+
def invoke_direct(method_name, *args)
|
9
|
+
prepare_request('api', 'api', method_name, *args)
|
10
|
+
@controller.process(@request, @response)
|
11
|
+
decode_rpc_response
|
12
|
+
end
|
13
|
+
alias_method :invoke, :invoke_direct
|
14
|
+
|
15
|
+
# invoke the specified API method on the specified service
|
16
|
+
def invoke_delegated(service_name, method_name, *args)
|
17
|
+
prepare_request(service_name.to_s, service_name, method_name, *args)
|
18
|
+
@controller.process(@request, @response)
|
19
|
+
decode_rpc_response
|
20
|
+
end
|
21
|
+
|
22
|
+
# invoke the specified layered API method on the correct service
|
23
|
+
def invoke_layered(service_name, method_name, *args)
|
24
|
+
prepare_request('api', service_name, method_name, *args)
|
25
|
+
@controller.process(@request, @response)
|
26
|
+
decode_rpc_response
|
27
|
+
end
|
28
|
+
|
29
|
+
# ---------------------- internal ---------------------------
|
30
|
+
|
31
|
+
def prepare_request(action, service_name, api_method_name, *args)
|
32
|
+
@request.recycle!
|
33
|
+
@request.request_parameters['action'] = action
|
34
|
+
@request.env['REQUEST_METHOD'] = 'POST'
|
35
|
+
@request.env['HTTP_CONTENT_TYPE'] = 'text/xml'
|
36
|
+
@request.env['RAW_POST_DATA'] = encode_rpc_call(service_name, api_method_name, *args)
|
37
|
+
case protocol
|
38
|
+
when ActionWebService::Protocol::Soap::SoapProtocol
|
39
|
+
soap_action = "/#{@controller.controller_name}/#{service_name}/#{public_method_name(service_name, api_method_name)}"
|
40
|
+
@request.env['HTTP_SOAPACTION'] = soap_action
|
41
|
+
when ActionWebService::Protocol::XmlRpc::XmlRpcProtocol
|
42
|
+
@request.env.delete('HTTP_SOAPACTION')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def encode_rpc_call(service_name, api_method_name, *args)
|
47
|
+
case @controller.web_service_dispatching_mode
|
48
|
+
when :direct
|
49
|
+
api = @controller.class.web_service_api
|
50
|
+
when :delegated, :layered
|
51
|
+
api = @controller.web_service_object(service_name.to_sym).class.web_service_api
|
52
|
+
end
|
53
|
+
protocol.register_api(api)
|
54
|
+
method = api.api_methods[api_method_name.to_sym]
|
55
|
+
raise ArgumentError, "wrong number of arguments for rpc call (#{args.length} for #{method.expects.length})" if method && method.expects && args.length != method.expects.length
|
56
|
+
protocol.encode_request(public_method_name(service_name, api_method_name), args.dup, method.expects)
|
57
|
+
end
|
58
|
+
|
59
|
+
def decode_rpc_response
|
60
|
+
public_method_name, return_value = protocol.decode_response(@response.body)
|
61
|
+
exception = is_exception?(return_value)
|
62
|
+
raise exception if exception
|
63
|
+
return_value
|
64
|
+
end
|
65
|
+
|
66
|
+
def public_method_name(service_name, api_method_name)
|
67
|
+
public_name = service_api(service_name).public_api_method_name(api_method_name)
|
68
|
+
if @controller.web_service_dispatching_mode == :layered && protocol.is_a?(ActionWebService::Protocol::XmlRpc::XmlRpcProtocol)
|
69
|
+
'%s.%s' % [service_name.to_s, public_name]
|
70
|
+
else
|
71
|
+
public_name
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def service_api(service_name)
|
76
|
+
case @controller.web_service_dispatching_mode
|
77
|
+
when :direct
|
78
|
+
@controller.class.web_service_api
|
79
|
+
when :delegated, :layered
|
80
|
+
@controller.web_service_object(service_name.to_sym).class.web_service_api
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def protocol
|
85
|
+
if @protocol.nil?
|
86
|
+
@protocol ||= ActionWebService::Protocol::Soap::SoapProtocol.create(@controller)
|
87
|
+
else
|
88
|
+
case @protocol
|
89
|
+
when :xmlrpc
|
90
|
+
@protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.create(@controller)
|
91
|
+
when :soap
|
92
|
+
@protocol = ActionWebService::Protocol::Soap::SoapProtocol.create(@controller)
|
93
|
+
else
|
94
|
+
@protocol
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def is_exception?(obj)
|
100
|
+
case protocol
|
101
|
+
when :soap, ActionWebService::Protocol::Soap::SoapProtocol
|
102
|
+
(obj.respond_to?(:detail) && obj.detail.respond_to?(:cause) && \
|
103
|
+
obj.detail.cause.is_a?(Exception)) ? obj.detail.cause : nil
|
104
|
+
when :xmlrpc, ActionWebService::Protocol::XmlRpc::XmlRpcProtocol
|
105
|
+
obj.is_a?(XMLRPC::FaultException) ? obj : nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2005 Leon Breedt
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'active_support'
|
26
|
+
require 'action_controller'
|
27
|
+
require 'active_record'
|
28
|
+
rescue LoadError
|
29
|
+
require 'rubygems'
|
30
|
+
gem 'activesupport', '~> 2.3.0'
|
31
|
+
gem 'actionpack', '~> 2.3.0'
|
32
|
+
gem 'activerecord', '~> 2.3.0'
|
33
|
+
end
|
34
|
+
|
35
|
+
$:.unshift(File.dirname(__FILE__) + "/action_web_service/vendor/")
|
36
|
+
|
37
|
+
require 'action_web_service/string_to_datetime_for_soap'
|
38
|
+
require 'action_web_service/support/class_inheritable_options'
|
39
|
+
require 'action_web_service/support/signature_types'
|
40
|
+
require 'action_web_service/base'
|
41
|
+
require 'action_web_service/client'
|
42
|
+
require 'action_web_service/invocation'
|
43
|
+
require 'action_web_service/api'
|
44
|
+
require 'action_web_service/casting'
|
45
|
+
require 'action_web_service/simple'
|
46
|
+
require 'action_web_service/struct'
|
47
|
+
require 'action_web_service/container'
|
48
|
+
require 'action_web_service/protocol'
|
49
|
+
require 'action_web_service/dispatcher'
|
50
|
+
require 'action_web_service/scaffolding'
|
51
|
+
require 'action_web_service/acts_as_web_service'
|
52
|
+
|
53
|
+
ActionWebService::Base.class_eval do
|
54
|
+
include ActionWebService::Container::Direct
|
55
|
+
include ActionWebService::Invocation
|
56
|
+
end
|
57
|
+
|
58
|
+
ActionController::Base.class_eval do
|
59
|
+
include ActionWebService::ActsAsWebService
|
60
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'action_web_service'
|