diff options
author | Leon Breedt <bitserf@gmail.com> | 2005-04-02 21:03:36 +0000 |
---|---|---|
committer | Leon Breedt <bitserf@gmail.com> | 2005-04-02 21:03:36 +0000 |
commit | aaea48fe9826b9e5d2d5b92795a297b8f238c58d (patch) | |
tree | e7c01c7f95d467f837c1f96d58dac74c3c902610 /actionwebservice/lib/action_web_service/dispatcher/abstract.rb | |
parent | aa09c770e9b5400683be11952673017295246de7 (diff) | |
download | rails-aaea48fe9826b9e5d2d5b92795a297b8f238c58d.tar.gz rails-aaea48fe9826b9e5d2d5b92795a297b8f238c58d.tar.bz2 rails-aaea48fe9826b9e5d2d5b92795a297b8f238c58d.zip |
* collapse 'ws' back into protocols, it just added complexity and indirection, and was hard to extend.
* extract casting into seperate support file
* ensure casting always does the right thing for return values, should fix interoperability issues with Ecto and possibly other XML-RPC clients
* add functional unit tests for scaffolding
* represent signature items with classes instead of symbols/Class objects, much more flexible
* tweak logging to always show casted versions of parameters and return values, if possible.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1072 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionwebservice/lib/action_web_service/dispatcher/abstract.rb')
-rw-r--r-- | actionwebservice/lib/action_web_service/dispatcher/abstract.rb | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/actionwebservice/lib/action_web_service/dispatcher/abstract.rb b/actionwebservice/lib/action_web_service/dispatcher/abstract.rb index 69c3b9de3b..975120212f 100644 --- a/actionwebservice/lib/action_web_service/dispatcher/abstract.rb +++ b/actionwebservice/lib/action_web_service/dispatcher/abstract.rb @@ -12,14 +12,6 @@ module ActionWebService # :nodoc: base.send(:include, ActionWebService::Dispatcher::InstanceMethods) end - def self.layered_service_name(public_method_name) # :nodoc: - if public_method_name =~ /^([^\.]+)\.(.*)$/ - $1 - else - nil - end - end - module InstanceMethods # :nodoc: private def invoke_web_service_request(protocol_request) @@ -40,13 +32,7 @@ module ActionWebService # :nodoc: else return_value = self.__send__(invocation.api_method.name) end - if invocation.api.has_api_method?(invocation.api_method.name) - api_method = invocation.api_method - else - api_method = invocation.api_method.dup - api_method.instance_eval{ @returns = [ return_value.class ] } - end - invocation.protocol.marshal_response(api_method, return_value) + web_service_create_response(invocation.protocol, invocation.api, invocation.api_method, return_value) end def web_service_delegated_invoke(invocation) @@ -57,7 +43,7 @@ module ActionWebService # :nodoc: if cancellation_reason raise(DispatcherError, "request canceled: #{cancellation_reason}") end - invocation.protocol.marshal_response(invocation.api_method, return_value) + web_service_create_response(invocation.protocol, invocation.api, invocation.api_method, return_value) end def web_service_invocation(request) @@ -79,6 +65,7 @@ module ActionWebService # :nodoc: invocation.service = web_service_object(invocation.service_name) invocation.api = invocation.service.class.web_service_api end + invocation.protocol.register_api(invocation.api) request.api = invocation.api if invocation.api.has_public_api_method?(public_method_name) invocation.api_method = invocation.api.public_api_method_instance(public_method_name) @@ -89,15 +76,20 @@ module ActionWebService # :nodoc: invocation.api_method = invocation.api.default_api_method_instance end end + if invocation.service.nil? + raise(DispatcherError, "no service available for service name #{invocation.service_name}") + end unless invocation.service.respond_to?(invocation.api_method.name) - raise(DispatcherError, "no such method '#{public_method_name}' on API #{invocation.api} (#{invocation.api_method.name})") + raise(DispatcherError, "no such method '#{public_method_name}' on API #{invocation.api} (#{invocation.api_method.name})") end request.api_method = invocation.api_method begin - invocation.method_ordered_params = invocation.api_method.cast_expects_ws2ruby(request.protocol.marshaler, request.method_params) + invocation.method_ordered_params = invocation.api_method.cast_expects(request.method_params.dup) rescue - invocation.method_ordered_params = request.method_params.map{ |x| x.value } + logger.warn "Casting of method parameters failed" unless logger.nil? + invocation.method_ordered_params = request.method_params end + request.method_params = invocation.method_ordered_params invocation.method_named_params = {} invocation.api_method.param_names.inject(0) do |m, n| invocation.method_named_params[n] = invocation.method_ordered_params[m] @@ -106,6 +98,16 @@ module ActionWebService # :nodoc: invocation end + def web_service_create_response(protocol, api, api_method, return_value) + if api.has_api_method?(api_method.name) + return_type = api_method.returns ? api_method.returns[0] : nil + return_value = api_method.cast_returns(return_value) + else + return_type = ActionWebService::SignatureTypes.canonical_signature_entry(return_value.class, 0) + end + protocol.encode_response(api_method.public_name + 'Response', return_value, return_type) + end + class Invocation # :nodoc: attr_accessor :protocol attr_accessor :service_name |