diff options
author | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-15 15:07:34 +0000 |
---|---|---|
committer | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-15 15:07:34 +0000 |
commit | 2ebdcae4ba2e053a1e9e7c6d456178c05b9baf51 (patch) | |
tree | 97d1034e837e5cdf7d5e74183560d6e0461b2016 /lib | |
parent | ceb3f04cb15af292a30b65803035b092e642260b (diff) | |
download | ruby-2ebdcae4ba2e053a1e9e7c6d456178c05b9baf51.tar.gz ruby-2ebdcae4ba2e053a1e9e7c6d456178c05b9baf51.tar.xz ruby-2ebdcae4ba2e053a1e9e7c6d456178c05b9baf51.zip |
forgot to update some files in the previous soap4r-1.5.5 import.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@9173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/soap/mapping/mapping.rb | 120 | ||||
-rw-r--r-- | lib/soap/wsdlDriver.rb | 52 |
2 files changed, 112 insertions, 60 deletions
diff --git a/lib/soap/mapping/mapping.rb b/lib/soap/mapping/mapping.rb index cc0e6ff9d..65d6bb4d5 100644 --- a/lib/soap/mapping/mapping.rb +++ b/lib/soap/mapping/mapping.rb @@ -20,7 +20,8 @@ module Mapping ApacheSOAPTypeNamespace = 'http://xml.apache.org/xml-soap' - # TraverseSupport breaks Thread.current[:SOAPMarshalDataKey]. + # TraverseSupport breaks following thread variables. + # Thread.current[:SOAPMarshalDataKey] module TraverseSupport def mark_marshalled_obj(obj, soap_obj) raise if obj.nil? @@ -35,41 +36,56 @@ module Mapping end - def self.obj2soap(obj, registry = nil, type = nil) + EMPTY_OPT = {} + def self.obj2soap(obj, registry = nil, type = nil, opt = EMPTY_OPT) registry ||= Mapping::DefaultRegistry - Thread.current[:SOAPMarshalDataKey] = {} - soap_obj = _obj2soap(obj, registry, type) - Thread.current[:SOAPMarshalDataKey] = nil + soap_obj = nil + protect_threadvars(:SOAPMarshalDataKey, :SOAPExternalCES, :SOAPMarshalNoReference) do + Thread.current[:SOAPMarshalDataKey] = {} + Thread.current[:SOAPExternalCES] = opt[:external_ces] || $KCODE + Thread.current[:SOAPMarshalNoReference] = opt[:no_reference] + soap_obj = _obj2soap(obj, registry, type) + end soap_obj end - def self.soap2obj(node, registry = nil, klass = nil) + def self.soap2obj(node, registry = nil, klass = nil, opt = EMPTY_OPT) registry ||= Mapping::DefaultRegistry - Thread.current[:SOAPMarshalDataKey] = {} - obj = _soap2obj(node, registry, klass) - Thread.current[:SOAPMarshalDataKey] = nil + obj = nil + protect_threadvars(:SOAPMarshalDataKey, :SOAPExternalCES, :SOAPMarshalNoReference) do + Thread.current[:SOAPMarshalDataKey] = {} + Thread.current[:SOAPExternalCES] = opt[:external_ces] || $KCODE + Thread.current[:SOAPMarshalNoReference] = opt[:no_reference] + obj = _soap2obj(node, registry, klass) + end obj end - def self.ary2soap(ary, type_ns = XSD::Namespace, typename = XSD::AnyTypeLiteral, registry = nil) + def self.ary2soap(ary, type_ns = XSD::Namespace, typename = XSD::AnyTypeLiteral, registry = nil, opt = EMPTY_OPT) registry ||= Mapping::DefaultRegistry type = XSD::QName.new(type_ns, typename) soap_ary = SOAPArray.new(ValueArrayName, 1, type) - Thread.current[:SOAPMarshalDataKey] = {} - ary.each do |ele| - soap_ary.add(_obj2soap(ele, registry, type)) + protect_threadvars(:SOAPMarshalDataKey, :SOAPExternalCES, :SOAPMarshalNoReference) do + Thread.current[:SOAPMarshalDataKey] = {} + Thread.current[:SOAPExternalCES] = opt[:external_ces] || $KCODE + Thread.current[:SOAPMarshalNoReference] = opt[:no_reference] + ary.each do |ele| + soap_ary.add(_obj2soap(ele, registry, type)) + end end - Thread.current[:SOAPMarshalDataKey] = nil soap_ary end - def self.ary2md(ary, rank, type_ns = XSD::Namespace, typename = XSD::AnyTypeLiteral, registry = nil) + def self.ary2md(ary, rank, type_ns = XSD::Namespace, typename = XSD::AnyTypeLiteral, registry = nil, opt = EMPTY_OPT) registry ||= Mapping::DefaultRegistry type = XSD::QName.new(type_ns, typename) md_ary = SOAPArray.new(ValueArrayName, rank, type) - Thread.current[:SOAPMarshalDataKey] = {} - add_md_ary(md_ary, ary, [], registry) - Thread.current[:SOAPMarshalDataKey] = nil + protect_threadvars(:SOAPMarshalDataKey, :SOAPExternalCES, :SOAPMarshalNoReference) do + Thread.current[:SOAPMarshalDataKey] = {} + Thread.current[:SOAPExternalCES] = opt[:external_ces] || $KCODE + Thread.current[:SOAPMarshalNoReference] = opt[:no_reference] + add_md_ary(md_ary, ary, [], registry) + end md_ary end @@ -104,7 +120,8 @@ module Mapping end def self._obj2soap(obj, registry, type = nil) - if referent = Thread.current[:SOAPMarshalDataKey][obj.__id__] + if referent = Thread.current[:SOAPMarshalDataKey][obj.__id__] and + !Thread.current[:SOAPMarshalNoReference] SOAPReference.new(referent) elsif registry registry.obj2soap(obj, type) @@ -114,10 +131,13 @@ module Mapping end def self._soap2obj(node, registry, klass = nil) - if node.is_a?(SOAPReference) + if node.nil? + return nil + elsif node.is_a?(SOAPReference) target = node.__getobj__ # target.id is not Object#id but SOAPReference#id - if referent = Thread.current[:SOAPMarshalDataKey][target.id] + if referent = Thread.current[:SOAPMarshalDataKey][target.id] and + !Thread.current[:SOAPMarshalNoReference] return referent else return _soap2obj(target, registry, klass) @@ -216,16 +236,8 @@ module Mapping end def self.class2qname(klass) - name = if klass.class_variables.include?('@@schema_type') - klass.class_eval('@@schema_type') - else - nil - end - namespace = if klass.class_variables.include?('@@schema_ns') - klass.class_eval('@@schema_ns') - else - nil - end + name = schema_type_definition(klass) + namespace = schema_ns_definition(klass) XSD::QName.new(namespace, name) end @@ -254,7 +266,9 @@ module Mapping def self.define_singleton_method(obj, name, &block) sclass = (class << obj; self; end) - sclass.class_eval {define_method(name, &block)} + sclass.class_eval { + define_method(name, &block) + } end def self.get_attribute(obj, attr_name) @@ -301,28 +315,56 @@ module Mapping define_singleton_method(obj, name + '=', &setterproc) if setterproc end + def self.schema_type_definition(klass) + class_schema_variable(:schema_type, klass) + end + + def self.schema_ns_definition(klass) + class_schema_variable(:schema_ns, klass) + end + def self.schema_element_definition(klass) - return nil unless klass.class_variables.include?('@@schema_element') - elements = {} + schema_element = class_schema_variable(:schema_element, klass) or return nil + schema_ns = schema_ns_definition(klass) + elements = [] as_array = [] - klass.class_eval('@@schema_element').each do |varname, definition| + schema_element.each do |varname, definition| class_name, name = definition if /\[\]$/ =~ class_name class_name = class_name.sub(/\[\]$/, '') - as_array << class_name + as_array << (name ? name.name : varname) end - elements[name ? name.name : varname] = class_name + elements << [name || XSD::QName.new(schema_ns, varname), class_name] end [elements, as_array] end def self.schema_attribute_definition(klass) - return nil unless klass.class_variables.include?('@@schema_attribute') - klass.class_eval('@@schema_attribute') + class_schema_variable(:schema_attribute, klass) end class << Mapping private + + def class_schema_variable(sym, klass) + var = "@@#{sym}" + klass.class_variables.include?(var) ? klass.class_eval(var) : nil + end + + def protect_threadvars(*symbols) + backup = {} + begin + symbols.each do |sym| + backup[sym] = Thread.current[sym] + end + yield + ensure + symbols.each do |sym| + Thread.current[sym] = backup[sym] + end + end + end + def add_md_ary(md_ary, ary, indices, registry) for idx in 0..(ary.size - 1) if ary[idx].is_a?(Array) diff --git a/lib/soap/wsdlDriver.rb b/lib/soap/wsdlDriver.rb index edd069e4f..eba9608df 100644 --- a/lib/soap/wsdlDriver.rb +++ b/lib/soap/wsdlDriver.rb @@ -45,7 +45,7 @@ class WSDLDriverFactory def create_driver(servicename = nil, portname = nil) warn("WSDLDriverFactory#create_driver is depricated. Use create_rpc_driver instead.") port = find_port(servicename, portname) - WSDLDriver.new(@wsdl, port, @logdev) + WSDLDriver.new(@wsdl, port, nil) end # Backward compatibility. @@ -66,11 +66,14 @@ private end if portname port = service.ports[XSD::QName.new(@wsdl.targetnamespace, portname)] + if port.nil? + raise FactoryError.new("port #{portname} not found in WSDL") + end else - port = service.ports[0] - end - if port.nil? - raise FactoryError.new("port #{portname} not found in WSDL") + port = service.ports.find { |port| !port.soap_address.nil? } + if port.nil? + raise FactoryError.new("no ports have soap:address") + end end if port.soap_address.nil? raise FactoryError.new("soap:address element not found in WSDL") @@ -96,10 +99,14 @@ private orgname = op_name.name name = XSD::CodeGen::GenSupport.safemethodname(orgname) param_def = create_param_def(op_bind) - opt = {} - opt[:request_style] = opt[:response_style] = op_bind.soapoperation_style - opt[:request_use] = (op_bind.input.soapbody.use || 'literal').intern - opt[:response_use] = (op_bind.output.soapbody.use || 'literal').intern + opt = { + :request_style => op_bind.soapoperation_style, + :response_style => op_bind.soapoperation_style, + :request_use => op_bind.input.soapbody_use, + :response_use => op_bind.output.soapbody_use, + :elementformdefault => false, + :attributeformdefault => false + } if op_bind.soapoperation_style == :rpc drv.add_rpc_operation(op_name, soapaction, name, param_def, opt) else @@ -126,7 +133,7 @@ private end # the first element of typedef in param_def is a String like # "::SOAP::SOAPStruct". turn this String to a class. - param_def.collect { |io, typedef, name| + param_def.collect { |io, name, typedef| typedef[0] = Mapping.class_from_name(typedef[0]) [io, name, typedef] } @@ -153,9 +160,6 @@ end class WSDLDriver class << self - def __attr_proxy(symbol, assignable = false) - end - if RUBY_VERSION >= "1.7.0" def __attr_proxy(symbol, assignable = false) name = symbol.to_s @@ -285,7 +289,9 @@ class WSDLDriver # Convert a map which key is QName, to a Hash which key is String. @operation = {} @port.inputoperation_map.each do |op_name, op_info| - @operation[op_name.name] = op_info + orgname = op_name.name + name = XSD::CodeGen::GenSupport.safemethodname(orgname) + @operation[name] = @operation[orgname] = op_info add_method_interface(op_info) end @proxy = ::SOAP::RPC::Proxy.new(endpoint_url, @soapaction, @options) @@ -354,8 +360,10 @@ class WSDLDriver # req_body: SOAPBasetype/SOAPCompoundtype def document_send(name, header_obj, body_obj) set_wiredump_file_base(name) - op_info = @operation[name] - req_header = header_from_obj(header_obj, op_info) + unless op_info = @operation[name] + raise RuntimeError, "method: #{name} not defined" + end + req_header = header_obj ? header_from_obj(header_obj, op_info) : nil req_body = body_from_obj(body_obj, op_info) opt = create_options({ :soapaction => op_info.soapaction || @soapaction, @@ -429,8 +437,10 @@ class WSDLDriver def create_method_obj(names, params) o = Object.new - for idx in 0 ... params.length + idx = 0 + while idx < params.length o.instance_variable_set('@' + names[idx], params[idx]) + idx += 1 end o end @@ -466,7 +476,7 @@ class WSDLDriver elsif obj.is_a?(SOAPHeaderItem) obj else - @doc_mapper.obj2soap(obj, name) + Mapping.obj2soap(obj, @doc_mapper, name) end end @@ -500,7 +510,7 @@ class WSDLDriver elsif obj.is_a?(SOAPElement) obj else - @doc_mapper.obj2soap(obj, name) + Mapping.obj2soap(obj, @doc_mapper, name) end end @@ -536,7 +546,7 @@ class WSDLDriver end def add_document_method_interface(name, parts_names) - ::SOAP::Mapping.define_singleton_method(@host, name) do |*arg| + ::SOAP::Mapping.define_singleton_method(@host, name) do |h, b| @servant.document_send(name, h, b) end @host.method(name) @@ -553,7 +563,7 @@ class WSDLDriver opt.add_hook("protocol.wiredump_file_base") do |key, value| @wiredump_file_base = value end - opt["protocol.http.charset"] ||= XSD::Charset.encoding_label + opt["protocol.http.charset"] ||= XSD::Charset.xml_encoding_label opt["protocol.http.proxy"] ||= Env::HTTP_PROXY opt["protocol.http.no_proxy"] ||= Env::NO_PROXY opt |