From aaea48fe9826b9e5d2d5b92795a297b8f238c58d Mon Sep 17 00:00:00 2001 From: Leon Breedt Date: Sat, 2 Apr 2005 21:03:36 +0000 Subject: * 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 --- .../lib/action_web_service/client/soap_client.rb | 20 +++++++++----------- .../lib/action_web_service/client/xmlrpc_client.rb | 10 ++++++---- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'actionwebservice/lib/action_web_service/client') diff --git a/actionwebservice/lib/action_web_service/client/soap_client.rb b/actionwebservice/lib/action_web_service/client/soap_client.rb index b9eb0d11ad..c906a71331 100644 --- a/actionwebservice/lib/action_web_service/client/soap_client.rb +++ b/actionwebservice/lib/action_web_service/client/soap_client.rb @@ -46,8 +46,7 @@ module ActionWebService # :nodoc: @type_namespace = options[:type_namespace] || 'urn:ActionWebService' @method_namespace = options[:method_namespace] || 'urn:ActionWebService' @driver_options = options[:driver_options] || {} - @marshaler = WS::Marshaling::SoapMarshaler.new @type_namespace - @encoder = WS::Encoding::SoapRpcEncoding.new @method_namespace + @protocol = ActionWebService::Protocol::Soap::SoapProtocol.new @soap_action_base = options[:soap_action_base] @soap_action_base ||= URI.parse(endpoint_uri).path @driver = create_soap_rpc_driver(api, endpoint_uri) @@ -59,9 +58,9 @@ module ActionWebService # :nodoc: protected def perform_invocation(method_name, args) method = @api.api_methods[method_name.to_sym] - args = method.cast_expects(@marshaler, args) + args = method.cast_expects(args.dup) rescue args return_value = @driver.send(method_name, *args) - method.cast_returns(@marshaler, return_value) + method.cast_returns(return_value.dup) rescue return_value end def soap_action(method_name) @@ -70,9 +69,9 @@ module ActionWebService # :nodoc: private def create_soap_rpc_driver(api, endpoint_uri) - api.api_methods.each{ |name, method| method.register_types(@marshaler) } + @protocol.register_api(api) driver = SoapDriver.new(endpoint_uri, nil) - driver.mapping_registry = @marshaler.registry + driver.mapping_registry = @protocol.marshaler.registry api.api_methods.each do |name, method| qname = XSD::QName.new(@method_namespace, method.public_name) action = soap_action(method.public_name) @@ -81,15 +80,14 @@ module ActionWebService # :nodoc: param_def = [] i = 0 if expects - expects.each do |spec| - param_name = method.param_name(spec, i) - type_binding = @marshaler.lookup_type(spec) - param_def << ['in', param_name, type_binding.mapping] + expects.each do |type| + type_binding = @protocol.marshaler.lookup_type(type) + param_def << ['in', type.name, type_binding.mapping] i += 1 end end if returns - type_binding = @marshaler.lookup_type(returns[0]) + type_binding = @protocol.marshaler.lookup_type(returns[0]) param_def << ['retval', 'return', type_binding.mapping] end driver.add_method(qname, action, method.name.to_s, 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 e0b7efc864..42b5c5d4f9 100644 --- a/actionwebservice/lib/action_web_service/client/xmlrpc_client.rb +++ b/actionwebservice/lib/action_web_service/client/xmlrpc_client.rb @@ -30,20 +30,22 @@ module ActionWebService # :nodoc: def initialize(api, endpoint_uri, options={}) @api = api @handler_name = options[:handler_name] + @protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.new @client = XMLRPC::Client.new2(endpoint_uri, options[:proxy], options[:timeout]) - @marshaler = WS::Marshaling::XmlRpcMarshaler.new end protected def perform_invocation(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) + args = method.cast_expects(args.dup) rescue args + if method.expects + method.expects.each_with_index{ |type, i| args[i] = @protocol.value_to_xmlrpc_wire_format(args[i], type) } + end ok, return_value = @client.call2(public_name(method_name), *args) - return method.cast_returns(@marshaler, return_value) if ok + return (method.cast_returns(return_value.dup) rescue return_value) if ok raise(ClientError, "#{return_value.faultCode}: #{return_value.faultString}") end -- cgit v1.2.3