* lib/soap/**/*.rb, lib/wsdl/**/*.rb, lib/xsd/**/*.rb: changed license; GPL2 -> Ruby's.
* lib/soap/rpc/driver.rb, lib/soap/wsdlDriver.rb, lib/soap/streamHandler.rb: add interface to streamhandler.
* lib/soap/marshal.rb: raise error if parse fails.
* lib/soap/netHttpClient.rb: add https support. Patched by Oliver M. Bolzer.
* lib/soap/netHttpClient.rb: dump HTTP response message body by itself.
* lib/soap/rpc/driver.rb, lib/soap/rpc/proxy.rb, lib/soap/wsdlDriver.rb: add driver#mandatorycharset interface to foce using charset for parsing response from buggy server.
* lib/soap/encodingstyle/soapHandler.rb: support Apache Axis's half typed multi-ref array.
* lib/soap/mapping/factory.rb, lib/soap/mapping/registry.rb: map SOAPStruct which has multi-accessors which name are the same, to an array.
* lib/soap/rpc/element.rb: fixed illegal parameter order.
* lib/soap/rpc/element.rb: element name of response message could have the name other than 'return'.
* lib/wsdl/operation.rb, lib/wsdl/operationBinding.rb, lib/wsdl/soap/classDefCreator.rb, lib/wsdl/soap/methodDefCreator.rb, lib/wsdl/soap/methodDefCreatorSupport.rb: WSDL/1.1 allows plural fault definition in a operation. [ruby-talk:84948]
* test/wsdl/multiplefault.wsdl, test/wsdl/test_multiplefault.rb: add test for above fix.
* lib/wsdl/soap/complexType.rb: support WSDL array definition with maxOccures="unbound".
* lib/xsd/charset.rb: use cp932 under emx. Patched by Siena. / SHINAGAWA, Norihide in [ruby-dev:21972]
* lib/xsd/xmlparser/parser.rb: set @charset nil by default. Nil means 'follow encoding declaration in XML'.
* sample/soap/digraph.rb, sample/wsdl/amazon/wsdlDriver.rb, sample/wsdl/googleSearch/sampleClient.rb, sample/wsdl/googleSearch/wsdlDriver.rb, test/wsdl/test_emptycomplextype.rb, test/wsdl/marshal/test_wsdlmarshal.rb, test/xsd/test_xmlschemaparser.rb: use File.open(...) { |f| f.read } instead of File.open(...).read. [ruby-dev:21964]
* test/wsdl/emptycomplextype.wsdl, test/wsdl/test_emptycomplextype.rb: simplify the test case.
* test/wsdl/axisArray/*: add tests for axis's array encoding.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-25 02:31:33 -05:00
|
|
|
# SOAP4R - Ruby type mapping utility.
|
2004-12-20 08:50:15 -05:00
|
|
|
# Copyright (C) 2000, 2001, 2003, 2004 NAKAMURA Hiroshi <nahi@ruby-lang.org>.
|
2003-09-24 11:18:44 -04:00
|
|
|
|
* lib/soap/**/*.rb, lib/wsdl/**/*.rb, lib/xsd/**/*.rb: changed license; GPL2 -> Ruby's.
* lib/soap/rpc/driver.rb, lib/soap/wsdlDriver.rb, lib/soap/streamHandler.rb: add interface to streamhandler.
* lib/soap/marshal.rb: raise error if parse fails.
* lib/soap/netHttpClient.rb: add https support. Patched by Oliver M. Bolzer.
* lib/soap/netHttpClient.rb: dump HTTP response message body by itself.
* lib/soap/rpc/driver.rb, lib/soap/rpc/proxy.rb, lib/soap/wsdlDriver.rb: add driver#mandatorycharset interface to foce using charset for parsing response from buggy server.
* lib/soap/encodingstyle/soapHandler.rb: support Apache Axis's half typed multi-ref array.
* lib/soap/mapping/factory.rb, lib/soap/mapping/registry.rb: map SOAPStruct which has multi-accessors which name are the same, to an array.
* lib/soap/rpc/element.rb: fixed illegal parameter order.
* lib/soap/rpc/element.rb: element name of response message could have the name other than 'return'.
* lib/wsdl/operation.rb, lib/wsdl/operationBinding.rb, lib/wsdl/soap/classDefCreator.rb, lib/wsdl/soap/methodDefCreator.rb, lib/wsdl/soap/methodDefCreatorSupport.rb: WSDL/1.1 allows plural fault definition in a operation. [ruby-talk:84948]
* test/wsdl/multiplefault.wsdl, test/wsdl/test_multiplefault.rb: add test for above fix.
* lib/wsdl/soap/complexType.rb: support WSDL array definition with maxOccures="unbound".
* lib/xsd/charset.rb: use cp932 under emx. Patched by Siena. / SHINAGAWA, Norihide in [ruby-dev:21972]
* lib/xsd/xmlparser/parser.rb: set @charset nil by default. Nil means 'follow encoding declaration in XML'.
* sample/soap/digraph.rb, sample/wsdl/amazon/wsdlDriver.rb, sample/wsdl/googleSearch/sampleClient.rb, sample/wsdl/googleSearch/wsdlDriver.rb, test/wsdl/test_emptycomplextype.rb, test/wsdl/marshal/test_wsdlmarshal.rb, test/xsd/test_xmlschemaparser.rb: use File.open(...) { |f| f.read } instead of File.open(...).read. [ruby-dev:21964]
* test/wsdl/emptycomplextype.wsdl, test/wsdl/test_emptycomplextype.rb: simplify the test case.
* test/wsdl/axisArray/*: add tests for axis's array encoding.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-25 02:31:33 -05:00
|
|
|
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
|
|
|
# redistribute it and/or modify it under the same terms of Ruby's license;
|
|
|
|
# either the dual license version in 2003, or any later version.
|
2003-09-24 11:18:44 -04:00
|
|
|
|
|
|
|
|
2004-12-20 08:50:15 -05:00
|
|
|
require 'xsd/codegen/gensupport'
|
|
|
|
|
|
|
|
|
2003-09-24 11:18:44 -04:00
|
|
|
module SOAP
|
|
|
|
|
|
|
|
|
|
|
|
module Mapping
|
|
|
|
RubyTypeNamespace = 'http://www.ruby-lang.org/xmlns/ruby/type/1.6'
|
|
|
|
RubyTypeInstanceNamespace =
|
|
|
|
'http://www.ruby-lang.org/xmlns/ruby/type-instance'
|
|
|
|
RubyCustomTypeNamespace = 'http://www.ruby-lang.org/xmlns/ruby/type/custom'
|
|
|
|
ApacheSOAPTypeNamespace = 'http://xml.apache.org/xml-soap'
|
|
|
|
|
|
|
|
|
|
|
|
# TraverseSupport breaks Thread.current[:SOAPMarshalDataKey].
|
|
|
|
module TraverseSupport
|
|
|
|
def mark_marshalled_obj(obj, soap_obj)
|
|
|
|
Thread.current[:SOAPMarshalDataKey][obj.__id__] = soap_obj
|
|
|
|
end
|
|
|
|
|
|
|
|
def mark_unmarshalled_obj(node, obj)
|
|
|
|
# node.id is not Object#id but SOAPReference#id
|
|
|
|
Thread.current[:SOAPMarshalDataKey][node.id] = obj
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.obj2soap(obj, registry = nil, type = nil)
|
|
|
|
registry ||= Mapping::DefaultRegistry
|
|
|
|
Thread.current[:SOAPMarshalDataKey] = {}
|
|
|
|
soap_obj = _obj2soap(obj, registry, type)
|
|
|
|
Thread.current[:SOAPMarshalDataKey] = nil
|
|
|
|
soap_obj
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.soap2obj(node, registry = nil)
|
|
|
|
registry ||= Mapping::DefaultRegistry
|
|
|
|
Thread.current[:SOAPMarshalDataKey] = {}
|
|
|
|
obj = _soap2obj(node, registry)
|
|
|
|
Thread.current[:SOAPMarshalDataKey] = nil
|
|
|
|
obj
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.ary2soap(ary, type_ns = XSD::Namespace, typename = XSD::AnyTypeLiteral, registry = nil)
|
|
|
|
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))
|
|
|
|
end
|
|
|
|
Thread.current[:SOAPMarshalDataKey] = nil
|
|
|
|
soap_ary
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.ary2md(ary, rank, type_ns = XSD::Namespace, typename = XSD::AnyTypeLiteral, registry = nil)
|
|
|
|
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
|
|
|
|
md_ary
|
|
|
|
end
|
|
|
|
|
2004-07-03 09:33:20 -04:00
|
|
|
def self.fault2exception(fault, registry = nil)
|
2003-09-24 11:18:44 -04:00
|
|
|
registry ||= Mapping::DefaultRegistry
|
2004-07-03 09:33:20 -04:00
|
|
|
detail = if fault.detail
|
|
|
|
soap2obj(fault.detail, registry) || ""
|
2003-09-24 11:18:44 -04:00
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
|
|
|
if detail.is_a?(Mapping::SOAPException)
|
|
|
|
begin
|
2004-07-03 09:33:20 -04:00
|
|
|
e = detail.to_e
|
|
|
|
remote_backtrace = e.backtrace
|
|
|
|
e.set_backtrace(nil)
|
|
|
|
raise e # ruby sets current caller as local backtrace of e => e2.
|
|
|
|
rescue Exception => e
|
|
|
|
e.set_backtrace(remote_backtrace + e.backtrace[1..-1])
|
2003-09-24 11:18:44 -04:00
|
|
|
raise
|
|
|
|
end
|
|
|
|
else
|
2004-07-03 09:33:20 -04:00
|
|
|
fault.detail = detail
|
|
|
|
fault.set_backtrace(
|
2003-09-24 11:18:44 -04:00
|
|
|
if detail.is_a?(Array)
|
|
|
|
detail
|
|
|
|
else
|
|
|
|
[detail.to_s]
|
|
|
|
end
|
|
|
|
)
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self._obj2soap(obj, registry, type = nil)
|
|
|
|
if referent = Thread.current[:SOAPMarshalDataKey][obj.__id__]
|
* import soap4r/1.5.2;
* lib/soap/{attachment.rb,baseData.rb,encodingstyle/soapHandler.rb}:
introduce SOAPExternalReference class as a referenct to SOAPEnvelope
external content.
* lib/soap/{attachment.rb,mimemessage.rb}: great SwA (SOAP messages
with Attachments) support code by Jamie Herre.
* lib/soap/{element.rb,marshal.rb,parser.rb,processor.rb,
streamHandler.rb,wsdlDriver.rb}: SwA support.
* lib/soap/rpc/{cgistub.rb,driver.rb,element.rb,proxy.rb,router.rb,
soaplet.rb}: SwA support and refactoring.
* lib/soap/generator.rb, lib/soap/mapping/mapping.rb: follow
SOAPReference#initialize signature change.
* lib/soap/mapping/factory.rb: deleted unused methods.
* lib/soap/mapping/rubytypeFactory.rb: do no ignore case while xsi:type
string <-> Ruby class name matching.
* lib/xsd/datatypes.rb: check the smallest positive non-zero
single-precision float exactly instead of packing with "f".
[ruby-talk:88822]
* test/soap/test_basetype.rb, test/xsd/test_xsd.rb: use 1.402e-45, not
1.4e-45. 1.4e-45 is smaller than 2 ** -149...
* test/soap/test_basetype.rb, test/soap/marshal/test_marshal.rb,
test/xsd/test_xsd.rb: use "(-1.0 / (1.0 / 0.0))" instead of "-0.0".
* test/soap/test_streamhandler.rb: revert to the previous test that
warns "basic_auth unsupported under net/http".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-01-05 21:20:51 -05:00
|
|
|
SOAPReference.new(referent)
|
2004-12-20 08:50:15 -05:00
|
|
|
elsif registry
|
|
|
|
registry.obj2soap(obj, type)
|
2003-09-24 11:18:44 -04:00
|
|
|
else
|
2004-12-20 08:50:15 -05:00
|
|
|
raise MappingError.new("No mapping registry given.")
|
2003-09-24 11:18:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self._soap2obj(node, registry)
|
|
|
|
if node.is_a?(SOAPReference)
|
|
|
|
target = node.__getobj__
|
|
|
|
# target.id is not Object#id but SOAPReference#id
|
|
|
|
if referent = Thread.current[:SOAPMarshalDataKey][target.id]
|
|
|
|
return referent
|
|
|
|
else
|
|
|
|
return _soap2obj(target, registry)
|
|
|
|
end
|
|
|
|
end
|
2004-12-20 08:50:15 -05:00
|
|
|
return registry.soap2obj(node)
|
2003-09-24 11:18:44 -04:00
|
|
|
end
|
|
|
|
|
2004-12-20 08:50:15 -05:00
|
|
|
if Object.respond_to?(:allocate)
|
|
|
|
# ruby/1.7 or later.
|
|
|
|
def self.create_empty_object(klass)
|
|
|
|
klass.allocate
|
|
|
|
end
|
|
|
|
else
|
|
|
|
MARSHAL_TAG = {
|
|
|
|
String => ['"', 1],
|
|
|
|
Regexp => ['/', 2],
|
|
|
|
Array => ['[', 1],
|
|
|
|
Hash => ['{', 1]
|
|
|
|
}
|
|
|
|
def self.create_empty_object(klass)
|
|
|
|
if klass <= Struct
|
|
|
|
name = klass.name
|
|
|
|
return ::Marshal.load(sprintf("\004\006S:%c%s\000", name.length + 5, name))
|
|
|
|
end
|
|
|
|
if MARSHAL_TAG.has_key?(klass)
|
|
|
|
tag, terminate = MARSHAL_TAG[klass]
|
|
|
|
return ::Marshal.load(sprintf("\004\006%s%s", tag, "\000" * terminate))
|
|
|
|
end
|
|
|
|
MARSHAL_TAG.each do |k, v|
|
|
|
|
if klass < k
|
|
|
|
name = klass.name
|
|
|
|
tag, terminate = v
|
|
|
|
return ::Marshal.load(sprintf("\004\006C:%c%s%s%s", name.length + 5, name, tag, "\000" * terminate))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
name = klass.name
|
|
|
|
::Marshal.load(sprintf("\004\006o:%c%s\000", name.length + 5, name))
|
|
|
|
end
|
|
|
|
end
|
2004-12-21 10:08:56 -05:00
|
|
|
|
|
|
|
unless Object.respond_to?(:instance_variable_get)
|
|
|
|
class Object
|
|
|
|
def instance_variable_get(ivarname)
|
|
|
|
instance_eval(ivarname)
|
|
|
|
end
|
|
|
|
|
|
|
|
def instance_variable_set(ivarname, value)
|
|
|
|
instance_eval("#{ivarname} = value")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-10-14 11:14:02 -04:00
|
|
|
def self.set_instance_vars(obj, values)
|
|
|
|
values.each do |name, value|
|
|
|
|
setter = name + "="
|
|
|
|
if obj.respond_to?(setter)
|
|
|
|
obj.__send__(setter, value)
|
|
|
|
else
|
2004-12-21 10:08:56 -05:00
|
|
|
obj.instance_variable_set('@' + name, value)
|
2003-10-14 11:14:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2003-09-24 11:18:44 -04:00
|
|
|
|
|
|
|
# Allow only (Letter | '_') (Letter | Digit | '-' | '_')* here.
|
|
|
|
# Caution: '.' is not allowed here.
|
|
|
|
# To follow XML spec., it should be NCName.
|
|
|
|
# (denied chars) => .[0-F][0-F]
|
|
|
|
# ex. a.b => a.2eb
|
|
|
|
#
|
|
|
|
def self.name2elename(name)
|
|
|
|
name.gsub(/([^a-zA-Z0-9:_\-]+)/n) {
|
|
|
|
'.' << $1.unpack('H2' * $1.size).join('.')
|
|
|
|
}.gsub(/::/n, '..')
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.elename2name(name)
|
|
|
|
name.gsub(/\.\./n, '::').gsub(/((?:\.[0-9a-fA-F]{2})+)/n) {
|
|
|
|
[$1.delete('.')].pack('H*')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.class_from_name(name)
|
|
|
|
if /^[A-Z]/ !~ name
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
klass = ::Object
|
|
|
|
name.split('::').each do |klass_str|
|
|
|
|
if klass.const_defined?(klass_str)
|
|
|
|
klass = klass.const_get(klass_str)
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
klass
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.class2qname(klass)
|
|
|
|
name = if klass.class_variables.include?("@@schema_type")
|
2004-12-21 10:08:56 -05:00
|
|
|
klass.class_eval('@@schema_type')
|
2003-09-24 11:18:44 -04:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
namespace = if klass.class_variables.include?("@@schema_ns")
|
2004-12-21 10:08:56 -05:00
|
|
|
klass.class_eval('@@schema_ns')
|
2003-09-24 11:18:44 -04:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
XSD::QName.new(namespace, name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.class2element(klass)
|
|
|
|
type = Mapping.class2qname(klass)
|
|
|
|
type.name ||= Mapping.name2elename(klass.name)
|
|
|
|
type.namespace ||= RubyCustomTypeNamespace
|
|
|
|
type
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.obj2element(obj)
|
|
|
|
name = namespace = nil
|
|
|
|
ivars = obj.instance_variables
|
2004-12-21 10:08:56 -05:00
|
|
|
if ivars.include?('@schema_type')
|
|
|
|
name = obj.instance_variable_get('@schema_type')
|
2003-09-24 11:18:44 -04:00
|
|
|
end
|
2004-12-21 10:08:56 -05:00
|
|
|
if ivars.include?('@schema_ns')
|
|
|
|
namespace = obj.instance_variable_get('@schema_ns')
|
2003-09-24 11:18:44 -04:00
|
|
|
end
|
|
|
|
if !name or !namespace
|
|
|
|
class2qname(obj.class)
|
|
|
|
else
|
|
|
|
XSD::QName.new(namespace, name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-12-20 08:50:15 -05:00
|
|
|
def self.find_attribute(obj, attr_name)
|
|
|
|
if obj.is_a?(::Hash)
|
|
|
|
obj[attr_name] || obj[attr_name.intern]
|
|
|
|
else
|
|
|
|
name = ::XSD::CodeGen::GenSupport.safevarname(attr_name)
|
|
|
|
if obj.respond_to?(name)
|
|
|
|
obj.__send__(name)
|
|
|
|
else
|
2004-12-21 10:08:56 -05:00
|
|
|
obj.instance_variable_get('@' + name)
|
2004-12-20 08:50:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-09-24 11:18:44 -04:00
|
|
|
class << Mapping
|
|
|
|
private
|
|
|
|
def add_md_ary(md_ary, ary, indices, registry)
|
|
|
|
for idx in 0..(ary.size - 1)
|
|
|
|
if ary[idx].is_a?(Array)
|
|
|
|
add_md_ary(md_ary, ary[idx], indices + [idx], registry)
|
|
|
|
else
|
|
|
|
md_ary[*(indices + [idx])] = _obj2soap(ary[idx], registry)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|