diff options
author | Leon Breedt <bitserf@gmail.com> | 2005-03-28 03:20:13 +0000 |
---|---|---|
committer | Leon Breedt <bitserf@gmail.com> | 2005-03-28 03:20:13 +0000 |
commit | 594063f23cf8e7cecd24329e801992784f420b55 (patch) | |
tree | d52e9a6fc0521d51fcc3875162adf0411ee6caa0 /actionwebservice/lib/action_web_service/client | |
parent | 439a216dcb65ac83d86ca04bb898e1797a87ce70 (diff) | |
download | rails-594063f23cf8e7cecd24329e801992784f420b55.tar.gz rails-594063f23cf8e7cecd24329e801992784f420b55.tar.bz2 rails-594063f23cf8e7cecd24329e801992784f420b55.zip |
generalize casting code to be used by both SOAP and XML-RPC (previously only XML-RPC). switch
to better model for API methods, and improve the ability to generate protocol requests/response,
will be required by upcoming scaffolding.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1030 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionwebservice/lib/action_web_service/client')
-rw-r--r-- | actionwebservice/lib/action_web_service/client/soap_client.rb | 40 | ||||
-rw-r--r-- | actionwebservice/lib/action_web_service/client/xmlrpc_client.rb | 40 |
2 files changed, 21 insertions, 59 deletions
diff --git a/actionwebservice/lib/action_web_service/client/soap_client.rb b/actionwebservice/lib/action_web_service/client/soap_client.rb index b8a20bb40e..b9eb0d11ad 100644 --- a/actionwebservice/lib/action_web_service/client/soap_client.rb +++ b/actionwebservice/lib/action_web_service/client/soap_client.rb @@ -58,7 +58,10 @@ module ActionWebService # :nodoc: protected def perform_invocation(method_name, args) - @driver.send(method_name, *args) + method = @api.api_methods[method_name.to_sym] + args = method.cast_expects(@marshaler, args) + return_value = @driver.send(method_name, *args) + method.cast_returns(@marshaler, return_value) end def soap_action(method_name) @@ -67,48 +70,33 @@ module ActionWebService # :nodoc: private def create_soap_rpc_driver(api, endpoint_uri) - register_api(@marshaler, api) + api.api_methods.each{ |name, method| method.register_types(@marshaler) } driver = SoapDriver.new(endpoint_uri, nil) driver.mapping_registry = @marshaler.registry - api.api_methods.each do |name, info| - public_name = api.public_api_method_name(name) - qname = XSD::QName.new(@method_namespace, public_name) - action = soap_action(public_name) - expects = info[:expects] - returns = info[:returns] + api.api_methods.each do |name, method| + qname = XSD::QName.new(@method_namespace, method.public_name) + action = soap_action(method.public_name) + expects = method.expects + returns = method.returns param_def = [] i = 0 if expects expects.each do |spec| - param_name = spec.is_a?(Hash) ? spec.keys[0].to_s : "param#{i}" - type_binding = @marshaler.register_type(spec) + param_name = method.param_name(spec, i) + type_binding = @marshaler.lookup_type(spec) param_def << ['in', param_name, type_binding.mapping] i += 1 end end if returns - type_binding = @marshaler.register_type(returns[0]) + type_binding = @marshaler.lookup_type(returns[0]) param_def << ['retval', 'return', type_binding.mapping] end - driver.add_method(qname, action, name.to_s, param_def) + driver.add_method(qname, action, method.name.to_s, param_def) end driver end - def register_api(marshaler, api) - type_bindings = [] - api.api_methods.each do |name, info| - expects, returns = info[:expects], info[:returns] - if expects - expects.each{|type| type_bindings << marshaler.register_type(type)} - end - if returns - returns.each{|type| type_bindings << marshaler.register_type(type)} - end - end - type_bindings - end - class SoapDriver < SOAP::RPC::Driver # :nodoc: def add_method(qname, soapaction, name, param_def) @proxy.add_rpc_method(qname, soapaction, name, param_def) diff --git a/actionwebservice/lib/action_web_service/client/xmlrpc_client.rb b/actionwebservice/lib/action_web_service/client/xmlrpc_client.rb index 27fe537404..e0b7efc864 100644 --- a/actionwebservice/lib/action_web_service/client/xmlrpc_client.rb +++ b/actionwebservice/lib/action_web_service/client/xmlrpc_client.rb @@ -36,43 +36,17 @@ module ActionWebService # :nodoc: protected def perform_invocation(method_name, args) - args = transform_outgoing_method_params(method_name, args) + method = @api.api_methods[method_name.to_sym] + method.register_types(@marshaler) + if method.expects && method.expects.length != args.length + raise(ArgumentError, "#{method.public_name}: wrong number of arguments (#{args.length} for #{method.expects.length})") + end + args = method.cast_expects(@marshaler, args) ok, return_value = @client.call2(public_name(method_name), *args) - return transform_return_value(method_name, return_value) if ok + return method.cast_returns(@marshaler, return_value) if ok raise(ClientError, "#{return_value.faultCode}: #{return_value.faultString}") end - def transform_outgoing_method_params(method_name, params) - info = @api.api_methods[method_name.to_sym] - expects = info[:expects] - expects_length = expects.nil?? 0 : expects.length - if expects_length != params.length - raise(ClientError, "API declares #{public_name(method_name)} to accept " + - "#{expects_length} parameters, but #{params.length} parameters " + - "were supplied") - end - params = params.dup - if expects_length > 0 - i = 0 - expects.each do |spec| - type_binding = @marshaler.register_type(spec) - info = WS::ParamInfo.create(spec, type_binding, i) - params[i] = @marshaler.marshal(WS::Param.new(params[i], info)) - i += 1 - end - end - params - end - - def transform_return_value(method_name, return_value) - info = @api.api_methods[method_name.to_sym] - return true unless returns = info[:returns] - type_binding = @marshaler.register_type(returns[0]) - info = WS::ParamInfo.create(returns[0], type_binding, 0) - info.name = 'return' - @marshaler.transform_inbound(WS::Param.new(return_value, info)) - end - def public_name(method_name) public_name = @api.public_api_method_name(method_name) @handler_name ? "#{@handler_name}.#{public_name}" : public_name |