From ebb6fb09280f828258432223fd543de9dfda6370 Mon Sep 17 00:00:00 2001 From: Leon Breedt Date: Sat, 25 Jun 2005 06:27:39 +0000 Subject: fix WSDL generation, change the way protocols are instantiated, and add the ability to override the namespace used in WSDL instead of always forcing 'urn:ActionWebService' git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1501 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_web_service/client/soap_client.rb | 15 +++++++-------- .../dispatcher/action_controller_dispatcher.rb | 7 ++++--- .../lib/action_web_service/protocol/abstract.rb | 3 +++ .../lib/action_web_service/protocol/discovery.rb | 4 ++-- .../lib/action_web_service/protocol/soap_protocol.rb | 16 ++++++++++++---- .../protocol/soap_protocol/marshaler.rb | 12 ++++++------ .../lib/action_web_service/protocol/xmlrpc_protocol.rb | 4 ++++ actionwebservice/lib/action_web_service/scaffolding.rb | 4 ++-- actionwebservice/lib/action_web_service/test_invoke.rb | 6 +++--- 9 files changed, 43 insertions(+), 28 deletions(-) (limited to 'actionwebservice/lib/action_web_service') diff --git a/actionwebservice/lib/action_web_service/client/soap_client.rb b/actionwebservice/lib/action_web_service/client/soap_client.rb index 79edac0b71..f5ebe1629c 100644 --- a/actionwebservice/lib/action_web_service/client/soap_client.rb +++ b/actionwebservice/lib/action_web_service/client/soap_client.rb @@ -24,10 +24,10 @@ module ActionWebService # :nodoc: # will be sent with HTTP POST. # # Valid options: - # [:type_namespace] If the remote server has used a custom namespace to - # declare its custom types, you can specify it here - # [:method_namespace] If the remote server has used a custom namespace to - # declare its methods, you can specify it here + # [:namespace] If the remote server has used a custom namespace to + # declare its custom types, you can specify it here. This would + # be the namespace declared with a [WebService(Namespace = "http://namespace")] attribute + # in .NET, for example. # [:driver_options] If you want to supply any custom SOAP RPC driver # options, you can provide them as a Hash here # @@ -43,10 +43,9 @@ module ActionWebService # :nodoc: # client = ActionWebService::Client::Soap.new(api, 'https://some/service', :driver_options => opts) def initialize(api, endpoint_uri, options={}) super(api, endpoint_uri) - @type_namespace = options[:type_namespace] || 'urn:ActionWebService' - @method_namespace = options[:method_namespace] || 'urn:ActionWebService' + @namespace = options[:namespace] || 'urn:ActionWebService' @driver_options = options[:driver_options] || {} - @protocol = ActionWebService::Protocol::Soap::SoapProtocol.new + @protocol = ActionWebService::Protocol::Soap::SoapProtocol.new @namespace @soap_action_base = options[:soap_action_base] @soap_action_base ||= URI.parse(endpoint_uri).path @driver = create_soap_rpc_driver(api, endpoint_uri) @@ -73,7 +72,7 @@ module ActionWebService # :nodoc: driver = SoapDriver.new(endpoint_uri, nil) driver.mapping_registry = @protocol.marshaler.registry api.api_methods.each do |name, method| - qname = XSD::QName.new(@method_namespace, method.public_name) + qname = XSD::QName.new(@namespace, method.public_name) action = soap_action(method.public_name) expects = method.expects returns = method.returns diff --git a/actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb b/actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb index 21e3ccedbf..d3d74be289 100644 --- a/actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +++ b/actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb @@ -6,9 +6,11 @@ module ActionWebService # :nodoc: module ActionController # :nodoc: def self.append_features(base) # :nodoc: super + base.extend(ClassMethods) base.class_eval do class << self alias_method :inherited_without_action_controller, :inherited + alias_method :inherited, :inherited_with_action_controller end alias_method :web_service_direct_invoke_without_controller, :web_service_direct_invoke end @@ -24,12 +26,11 @@ module ActionWebService # :nodoc: klass.class_eval 'def api; dispatch_web_service_request; end' end end - base.extend(ClassMethods) base.send(:include, ActionWebService::Dispatcher::ActionController::InstanceMethods) end module ClassMethods # :nodoc: - def inherited(child) + def inherited_with_action_controller(child) inherited_without_action_controller(child) child.send(:include, ActionWebService::Dispatcher::ActionController::WsdlAction) end @@ -174,7 +175,7 @@ module ActionWebService # :nodoc: xml = '' dispatching_mode = web_service_dispatching_mode global_service_name = wsdl_service_name - namespace = 'urn:ActionWebService' + namespace = wsdl_namespace || 'urn:ActionWebService' soap_action_base = "/#{controller_name}" marshaler = ActionWebService::Protocol::Soap::SoapMarshaler.new(namespace) diff --git a/actionwebservice/lib/action_web_service/protocol/abstract.rb b/actionwebservice/lib/action_web_service/protocol/abstract.rb index 3819aa2ade..be5bda2d41 100644 --- a/actionwebservice/lib/action_web_service/protocol/abstract.rb +++ b/actionwebservice/lib/action_web_service/protocol/abstract.rb @@ -4,6 +4,9 @@ module ActionWebService # :nodoc: end class AbstractProtocol # :nodoc: + def setup(controller) + end + def decode_action_pack_request(action_pack_request) end diff --git a/actionwebservice/lib/action_web_service/protocol/discovery.rb b/actionwebservice/lib/action_web_service/protocol/discovery.rb index a911c7d017..3d4e0818da 100644 --- a/actionwebservice/lib/action_web_service/protocol/discovery.rb +++ b/actionwebservice/lib/action_web_service/protocol/discovery.rb @@ -16,7 +16,7 @@ module ActionWebService # :nodoc: private def discover_web_service_request(action_pack_request) (self.class.read_inheritable_attribute("web_service_protocols") || []).each do |protocol| - protocol = protocol.new + protocol = protocol.create(self) request = protocol.decode_action_pack_request(action_pack_request) return request unless request.nil? end @@ -25,7 +25,7 @@ module ActionWebService # :nodoc: def create_web_service_client(api, protocol_name, endpoint_uri, options) (self.class.read_inheritable_attribute("web_service_protocols") || []).each do |protocol| - protocol = protocol.new + protocol = protocol.create(self) client = protocol.protocol_client(api, protocol_name, endpoint_uri, options) return client unless client.nil? end diff --git a/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb b/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb index 3e5bad0086..e6bb5488ab 100644 --- a/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb +++ b/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb @@ -7,13 +7,21 @@ module ActionWebService # :nodoc: def self.included(base) base.register_protocol(SoapProtocol) base.class_inheritable_option(:wsdl_service_name) + base.class_inheritable_option(:wsdl_namespace) end class SoapProtocol < AbstractProtocol # :nodoc: DefaultEncoding = 'utf-8' - def marshaler - @marshaler ||= SoapMarshaler.new + attr :marshaler + + def initialize(namespace=nil) + namespace ||= 'urn:ActionWebService' + @marshaler = SoapMarshaler.new namespace + end + + def self.create(controller) + SoapProtocol.new(controller.wsdl_namespace) end def decode_action_pack_request(action_pack_request) @@ -47,7 +55,7 @@ module ActionWebService # :nodoc: def encode_request(method_name, params, param_types) param_types.each{ |type| marshaler.register_type(type) } if param_types - qname = XSD::QName.new(marshaler.type_namespace, method_name) + qname = XSD::QName.new(marshaler.namespace, method_name) param_def = [] if param_types params = param_types.zip(params).map do |type, param| @@ -79,7 +87,7 @@ module ActionWebService # :nodoc: return_binding = marshaler.register_type(return_type) marshaler.annotate_arrays(return_binding, return_value) end - qname = XSD::QName.new(marshaler.type_namespace, method_name) + qname = XSD::QName.new(marshaler.namespace, method_name) if return_value.nil? response = SOAP::RPC::SOAPMethodResponse.new(qname, nil) else diff --git a/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb b/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb index 78eee620eb..b36e029669 100644 --- a/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb +++ b/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb @@ -17,11 +17,11 @@ module ActionWebService end class SoapMarshaler - attr :type_namespace + attr :namespace attr :registry - def initialize(type_namespace=nil) - @type_namespace = type_namespace || 'urn:ActionWebService' + def initialize(namespace=nil) + @namespace = namespace || 'urn:ActionWebService' @registry = Registry.new @type2binding = {} register_static_factories @@ -46,7 +46,7 @@ module ActionWebService qname ||= soap_base_type_name(mapping[0]) type_binding = SoapBinding.new(self, qname, type_type, mapping) else - qname = XSD::QName.new(@type_namespace, soap_type_name(type_class.name)) + qname = XSD::QName.new(@namespace, soap_type_name(type_class.name)) @registry.add(type_class, SOAP::SOAPStruct, typed_struct_factory(type_class), @@ -58,7 +58,7 @@ module ActionWebService array_binding = nil if type.array? array_mapping = @registry.find_mapped_soap_class(Array) - qname = XSD::QName.new(@type_namespace, soap_type_name(type.element_type.type_class.name) + 'Array') + qname = XSD::QName.new(@namespace, soap_type_name(type.element_type.type_class.name) + 'Array') array_binding = SoapBinding.new(self, qname, type, array_mapping, type_binding) end @@ -88,7 +88,7 @@ module ActionWebService def typed_struct_factory(type_class) if Object.const_defined?('ActiveRecord') if type_class.ancestors.include?(ActiveRecord::Base) - qname = XSD::QName.new(@type_namespace, soap_type_name(type_class.name)) + qname = XSD::QName.new(@namespace, soap_type_name(type_class.name)) type_class.instance_variable_set('@qname', qname) return SoapActiveRecordStructFactory.new end diff --git a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb index dec94ccad0..f09f89142a 100644 --- a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb +++ b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb @@ -12,6 +12,10 @@ module ActionWebService # :nodoc: end class XmlRpcProtocol < AbstractProtocol # :nodoc: + def self.create(controller) + XmlRpcProtocol.new + end + def decode_action_pack_request(action_pack_request) service_name = action_pack_request.parameters['action'] decode_request(action_pack_request.raw_post, service_name) diff --git a/actionwebservice/lib/action_web_service/scaffolding.rb b/actionwebservice/lib/action_web_service/scaffolding.rb index ff9a23b1e8..da3d6c137c 100644 --- a/actionwebservice/lib/action_web_service/scaffolding.rb +++ b/actionwebservice/lib/action_web_service/scaffolding.rb @@ -61,9 +61,9 @@ module ActionWebService protocol_name = params['protocol'] ? params['protocol'].to_sym : :soap case protocol_name when :soap - @protocol = Protocol::Soap::SoapProtocol.new + @protocol = Protocol::Soap::SoapProtocol.create(self) when :xmlrpc - @protocol = Protocol::XmlRpc::XmlRpcProtocol.new + @protocol = Protocol::XmlRpc::XmlRpcProtocol.create(self) end @invocation_cgi = request.respond_to?(:cgi) ? request.cgi : nil bm = Benchmark.measure do diff --git a/actionwebservice/lib/action_web_service/test_invoke.rb b/actionwebservice/lib/action_web_service/test_invoke.rb index 02ed9ea586..cd9cb115ff 100644 --- a/actionwebservice/lib/action_web_service/test_invoke.rb +++ b/actionwebservice/lib/action_web_service/test_invoke.rb @@ -81,13 +81,13 @@ module Test # :nodoc: def protocol if @protocol.nil? - @protocol ||= ActionWebService::Protocol::Soap::SoapProtocol.new + @protocol ||= ActionWebService::Protocol::Soap::SoapProtocol.new(@controller) else case @protocol when :xmlrpc - @protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.new + @protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.create(@controller) when :soap - @protocol = ActionWebService::Protocol::Soap::SoapProtocol.new + @protocol = ActionWebService::Protocol::Soap::SoapProtocol.create(@controller) else @protocol end -- cgit v1.2.3