From b7931c40fee8ec76c2ef0398f228e034d7ff64e4 Mon Sep 17 00:00:00 2001 From: nahi Date: Sat, 8 Nov 2003 09:52:42 +0000 Subject: [PATCH] * test/wsdl/raa/*: add new testcase for WSDL loading, parsing and reading. * test/soap/marshal/*: backport from soap4r/1.5.1. all differences are for ruby/1.6. * lib/soap/*: backport from soap4r/1.5.1. all differences are for ruby/1.6. * lib/wsdl/data.rb, lib/wsdl/xmlSchema/data.rb: move definition of ArrayTypeAttrName from ::WSDL::XMLSchema::* to ::WSDL::*. [ruby-talk:84813] * lib/wsdl/soap/definitions.rb: element name typo in custom exception struct definition which is needed for wsdlDriver; camelCase -> underscore_name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 19 +++ lib/soap/mapping/factory.rb | 23 ++- lib/soap/mapping/registry.rb | 19 ++- lib/soap/soap.rb | 2 +- lib/wsdl/data.rb | 1 + lib/wsdl/soap/definitions.rb | 2 +- lib/wsdl/xmlSchema/data.rb | 1 - test/soap/marshal/test_digraph.rb | 4 +- test/soap/marshal/test_marshal.rb | 59 ++++++- test/wsdl/raa/RAA.rb | 254 ++++++++++++++++++++++++++++ test/wsdl/raa/README.txt | 5 + test/wsdl/raa/raa.wsdl | 264 ++++++++++++++++++++++++++++++ test/wsdl/raa/server.rb | 104 ++++++++++++ test/wsdl/raa/test_raa.rb | 78 +++++++++ 14 files changed, 816 insertions(+), 19 deletions(-) create mode 100644 test/wsdl/raa/RAA.rb create mode 100644 test/wsdl/raa/README.txt create mode 100644 test/wsdl/raa/raa.wsdl create mode 100644 test/wsdl/raa/server.rb create mode 100644 test/wsdl/raa/test_raa.rb diff --git a/ChangeLog b/ChangeLog index e31192f4af..79a8677eb3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +Sat Nov 8 18:50:20 2003 NAKAMURA, Hiroshi + + * test/wsdl/raa/*: add new testcase for WSDL loading, parsing and + reading. + + * test/soap/marshal/*: backport from soap4r/1.5.1. all differences are + for ruby/1.6. + + * lib/soap/*: backport from soap4r/1.5.1. all differences are for + ruby/1.6. + + * lib/wsdl/data.rb, lib/wsdl/xmlSchema/data.rb: move definition of + ArrayTypeAttrName from ::WSDL::XMLSchema::* to ::WSDL::*. + [ruby-talk:84813] + + * lib/wsdl/soap/definitions.rb: element name typo in custom exception + struct definition which is needed for wsdlDriver; camelCase -> + underscore_name. + Sat Nov 8 13:49:50 2003 Hidetoshi NAGAI * configure.in: improvement of pthread check diff --git a/lib/soap/mapping/factory.rb b/lib/soap/mapping/factory.rb index 92ed194a42..631c161134 100644 --- a/lib/soap/mapping/factory.rb +++ b/lib/soap/mapping/factory.rb @@ -44,10 +44,29 @@ class Factory klass.allocate end else + MARSHAL_TAG = { + String => ['"', 1], + Regexp => ['/', 2], + Array => ['[', 1], + Hash => ['{', 1] + } def 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 - # Below line is from TANAKA, Akira's amarshal.rb. - # See http://cvs.m17n.org/cgi-bin/viewcvs/amarshal/?cvsroot=ruby ::Marshal.load(sprintf("\004\006o:%c%s\000", name.length + 5, name)) end end diff --git a/lib/soap/mapping/registry.rb b/lib/soap/mapping/registry.rb index bdf14d4fc6..e98c98a6d4 100644 --- a/lib/soap/mapping/registry.rb +++ b/lib/soap/mapping/registry.rb @@ -426,10 +426,21 @@ private Mapping.set_instance_vars(obj, vars) end - def addextend2obj(obj, attr) - return unless attr - attr.split(/ /).reverse_each do |mstr| - obj.extend(Mapping.class_from_name(mstr)) + if RUBY_VERSION >= '1.8.0' + def addextend2obj(obj, attr) + return unless attr + attr.split(/ /).reverse_each do |mstr| + obj.extend(Mapping.class_from_name(mstr)) + end + end + else + # (class < false; self; end).ancestors includes "TrueClass" under 1.6... + def addextend2obj(obj, attr) + return unless attr + attr.split(/ /).reverse_each do |mstr| + m = Mapping.class_from_name(mstr) + obj.extend(m) if m.class == Module + end end end diff --git a/lib/soap/soap.rb b/lib/soap/soap.rb index 313af3a059..2543ec3612 100644 --- a/lib/soap/soap.rb +++ b/lib/soap/soap.rb @@ -24,7 +24,7 @@ require 'xsd/charset' module SOAP -Version = '1.5.0' +Version = '1.5.1' EnvelopeNamespace = 'http://schemas.xmlsoap.org/soap/envelope/' EncodingNamespace = 'http://schemas.xmlsoap.org/soap/encoding/' diff --git a/lib/wsdl/data.rb b/lib/wsdl/data.rb index 4f3b845316..3361dac1f4 100644 --- a/lib/wsdl/data.rb +++ b/lib/wsdl/data.rb @@ -35,6 +35,7 @@ require 'wsdl/import' module WSDL +ArrayTypeAttrName = XSD::QName.new(Namespace, 'arrayType') BindingName = XSD::QName.new(Namespace, 'binding') DefinitionsName = XSD::QName.new(Namespace, 'definitions') DocumentationName = XSD::QName.new(Namespace, 'documentation') diff --git a/lib/wsdl/soap/definitions.rb b/lib/wsdl/soap/definitions.rb index 08df0dcc68..1bd8e8a664 100644 --- a/lib/wsdl/soap/definitions.rb +++ b/lib/wsdl/soap/definitions.rb @@ -117,7 +117,7 @@ private def exception_complextype type = XMLSchema::ComplexType.new(XSD::QName.new( ::SOAP::Mapping::RubyCustomTypeNamespace, 'SOAPException')) - excn_name = XMLSchema::Element.new(XSD::QName.new(nil, 'exceptionTypeName'), XSD::XSDString::Type) + excn_name = XMLSchema::Element.new(XSD::QName.new(nil, 'excn_type_name'), XSD::XSDString::Type) cause = XMLSchema::Element.new(XSD::QName.new(nil, 'cause'), XSD::AnyTypeName) backtrace = XMLSchema::Element.new(XSD::QName.new(nil, 'backtrace'), ::SOAP::ValueArrayName) message = XMLSchema::Element.new(XSD::QName.new(nil, 'message'), XSD::XSDString::Type) diff --git a/lib/wsdl/xmlSchema/data.rb b/lib/wsdl/xmlSchema/data.rb index 539cf357c6..57d2f527c0 100644 --- a/lib/wsdl/xmlSchema/data.rb +++ b/lib/wsdl/xmlSchema/data.rb @@ -36,7 +36,6 @@ module XMLSchema AllName = XSD::QName.new(XSD::Namespace, 'all') AnyName = XSD::QName.new(XSD::Namespace, 'any') -ArrayTypeAttrName = XSD::QName.new(XSD::Namespace, 'arrayType') AttributeName = XSD::QName.new(XSD::Namespace, 'attribute') ChoiceName = XSD::QName.new(XSD::Namespace, 'choice') ComplexContentName = XSD::QName.new(XSD::Namespace, 'complexContent') diff --git a/test/soap/marshal/test_digraph.rb b/test/soap/marshal/test_digraph.rb index c83238748a..d7f30654f8 100644 --- a/test/soap/marshal/test_digraph.rb +++ b/test/soap/marshal/test_digraph.rb @@ -36,7 +36,9 @@ class TestDigraph < Test::Unit::TestCase f = File.open("digraph_marshalled_string.soap", "wb") SOAP::Marshal.dump(@n1, f) f.close - str = File.read("digraph_marshalled_string.soap") + f = File.open("digraph_marshalled_string.soap") + str = f.read + f.close newnode = SOAP::Marshal.unmarshal(str) assert_equal(newnode.first.first.__id__, newnode.second.first.__id__) assert_equal(newnode.first.first.first.first.__id__, newnode.second.first.second.first.__id__) diff --git a/test/soap/marshal/test_marshal.rb b/test/soap/marshal/test_marshal.rb index 2763fa8bcf..9ae08c68d8 100644 --- a/test/soap/marshal/test_marshal.rb +++ b/test/soap/marshal/test_marshal.rb @@ -78,13 +78,18 @@ module MarshalTestLib } end - class MyArray < Array; def initialize(v, *args) super args; @v = v; end end + class MyArray < Array + def initialize(v, args) + super(args) + @v = v + end + end def test_array - marshal_equal([1,2,3]) + marshal_equal(5) end def test_array_subclass - marshal_equal(MyArray.new(0, 1,2,3)) + marshal_equal(MyArray.new(0, 3)) end def test_array_ivar @@ -166,7 +171,8 @@ module MarshalTestLib end def test_fixnum - marshal_equal(-0x4000_0000) + #marshal_equal(-0x4000_0000) # not fixnum under 1.6... + marshal_equal(-0x3fff_ffff) marshal_equal(-1) marshal_equal(0) marshal_equal(1) @@ -253,7 +259,7 @@ module MarshalTestLib end def test_string_ivar - o1 = String.new + o1 = "" o1.instance_eval { @iv = 1 } marshal_equal(o1) {|o| o.instance_eval { @iv }} end @@ -281,12 +287,31 @@ module MarshalTestLib end MyStruct = Struct.new("MyStruct", :a, :b) + if RUBY_VERSION < "1.8.0" + # Struct#== is not defined in ruby/1.6 + class MyStruct + def ==(rhs) + return true if __id__ == rhs.__id__ + return false unless rhs.is_a?(::Struct) + return false if self.class != rhs.class + members.each do |member| + return false if self.__send__(member) != rhs.__send__(member) + end + return true + end + end + end class MySubStruct < MyStruct; def initialize(v, *args) super(*args); @v = v; end end def test_struct marshal_equal(MyStruct.new(1,2)) end def test_struct_subclass + if RUBY_VERSION < "1.8.0" + # Substruct instance cannot be dumped in ruby/1.6 + # ::Marshal.dump(MySubStruct.new(10, 1, 2)) #=> uninitialized struct + return false + end marshal_equal(MySubStruct.new(10,1,2)) end @@ -379,6 +404,7 @@ module MarshalTestLib def <=>(other); true; end end def test_range_cyclic + return unless CyclicRange.respond_to?(:allocate) # test for 1.8 o1 = CyclicRange.allocate o1.instance_eval { initialize(o1, o1) } o2 = marshaltest(o1) @@ -413,14 +439,14 @@ module MarshalTestLib end def test_extend_string - o = String.new + o = "" o.extend Mod1 marshal_equal(o) { |obj| obj.kind_of? Mod1 } - o = String.new + o = "" o.extend Mod1 o.extend Mod2 marshal_equal(o) {|obj| class << obj; ancestors end} - o = String.new + o = "" o.extend Module.new assert_raises(TypeError) { marshaltest(o) } end @@ -447,8 +473,23 @@ module MarshalTestLib end MyStruct2 = Struct.new(:a, :b) + if RUBY_VERSION < "1.8.0" + # Struct#== is not defined in ruby/1.6 + class MyStruct2 + def ==(rhs) + return true if __id__ == rhs.__id__ + return false unless rhs.is_a?(::Struct) + return false if self.class != rhs.class + members.each do |member| + return false if self.__send__(member) != rhs.__send__(member) + end + return true + end + end + end def test_struct_toplevel - marshal_equal(MyStruct2.new(1,2)) + o = MyStruct2.new(1,2) + marshal_equal(o) end end diff --git a/test/wsdl/raa/RAA.rb b/test/wsdl/raa/RAA.rb new file mode 100644 index 0000000000..32b88bd26a --- /dev/null +++ b/test/wsdl/raa/RAA.rb @@ -0,0 +1,254 @@ +# http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/ +class Category + @@schema_type = "Category" + @@schema_ns = "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/" + + def major + @major + end + + def major=(value) + @major = value + end + + def minor + @minor + end + + def minor=(value) + @minor = value + end + + def initialize(major = nil, + minor = nil) + @major = major + @minor = minor + end +end + +# http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/ +class Product + @@schema_type = "Product" + @@schema_ns = "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/" + + def id + @id + end + + def id=(value) + @id = value + end + + def name + @name + end + + def name=(value) + @name = value + end + + def short_description + @short_description + end + + def short_description=(value) + @short_description = value + end + + def version + @version + end + + def version=(value) + @version = value + end + + def status + @status + end + + def status=(value) + @status = value + end + + def homepage + @homepage + end + + def homepage=(value) + @homepage = value + end + + def download + @download + end + + def download=(value) + @download = value + end + + def license + @license + end + + def license=(value) + @license = value + end + + def description + @description + end + + def description=(value) + @description = value + end + + def initialize(id = nil, + name = nil, + short_description = nil, + version = nil, + status = nil, + homepage = nil, + download = nil, + license = nil, + description = nil) + @id = id + @name = name + @short_description = short_description + @version = version + @status = status + @homepage = homepage + @download = download + @license = license + @description = description + end +end + +# http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/ +class Owner + @@schema_type = "Owner" + @@schema_ns = "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/" + + def id + @id + end + + def id=(value) + @id = value + end + + def email + @email + end + + def email=(value) + @email = value + end + + def name + @name + end + + def name=(value) + @name = value + end + + def initialize(id = nil, + email = nil, + name = nil) + @id = id + @email = email + @name = name + end +end + +# http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/ +class Info + @@schema_type = "Info" + @@schema_ns = "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/" + + def category + @category + end + + def category=(value) + @category = value + end + + def product + @product + end + + def product=(value) + @product = value + end + + def owner + @owner + end + + def owner=(value) + @owner = value + end + + def created + @created + end + + def created=(value) + @created = value + end + + def updated + @updated + end + + def updated=(value) + @updated = value + end + + def initialize(category = nil, + product = nil, + owner = nil, + created = nil, + updated = nil) + @category = category + @product = product + @owner = owner + @created = created + @updated = updated + end +end + +# http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/ +class InfoArray < Array + # Contents type should be dumped here... + @@schema_type = "InfoArray" + @@schema_ns = "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/" +end + +# http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/ +class StringArray < Array + # Contents type should be dumped here... + @@schema_type = "StringArray" + @@schema_ns = "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/" +end + +# http://xml.apache.org/xml-soap +class Map + @@schema_type = "Map" + @@schema_ns = "http://xml.apache.org/xml-soap" + + def item + @item + end + + def item=(value) + @item = value + end + + def initialize(item = nil) + @item = item + end +end + diff --git a/test/wsdl/raa/README.txt b/test/wsdl/raa/README.txt new file mode 100644 index 0000000000..e884db9bb4 --- /dev/null +++ b/test/wsdl/raa/README.txt @@ -0,0 +1,5 @@ +server.rb: based on RAAService.rb which is generated with the following command; + bin/wsdl2ruby.rb --wsdl raa.wsdl --standalone_server_stub --force + +RAA.rb: generated with the following command; + bin/wsdl2ruby.rb --wsdl raa.wsdl --classdef --force diff --git a/test/wsdl/raa/raa.wsdl b/test/wsdl/raa/raa.wsdl new file mode 100644 index 0000000000..78376893dd --- /dev/null +++ b/test/wsdl/raa/raa.wsdl @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/wsdl/raa/server.rb b/test/wsdl/raa/server.rb new file mode 100644 index 0000000000..95e63dcd31 --- /dev/null +++ b/test/wsdl/raa/server.rb @@ -0,0 +1,104 @@ +#!/usr/bin/env ruby +require 'soap/rpc/standaloneServer' +require 'RAA.rb' + +class RAABaseServicePortType + MappingRegistry = SOAP::Mapping::Registry.new + + MappingRegistry.set( + StringArray, + ::SOAP::SOAPArray, + ::SOAP::Mapping::Registry::TypedArrayFactory, + { :type => XSD::QName.new("http://www.w3.org/2001/XMLSchema", "string") } + ) + MappingRegistry.set( + Map, + ::SOAP::SOAPStruct, + ::SOAP::Mapping::Registry::TypedStructFactory, + { :type => XSD::QName.new("http://xml.apache.org/xml-soap", "Map") } + ) + MappingRegistry.set( + Category, + ::SOAP::SOAPStruct, + ::SOAP::Mapping::Registry::TypedStructFactory, + { :type => XSD::QName.new("http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/", "Category") } + ) + MappingRegistry.set( + InfoArray, + ::SOAP::SOAPArray, + ::SOAP::Mapping::Registry::TypedArrayFactory, + { :type => XSD::QName.new("http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/", "Info") } + ) + MappingRegistry.set( + Info, + ::SOAP::SOAPStruct, + ::SOAP::Mapping::Registry::TypedStructFactory, + { :type => XSD::QName.new("http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/", "Info") } + ) + MappingRegistry.set( + Product, + ::SOAP::SOAPStruct, + ::SOAP::Mapping::Registry::TypedStructFactory, + { :type => XSD::QName.new("http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/", "Product") } + ) + MappingRegistry.set( + Owner, + ::SOAP::SOAPStruct, + ::SOAP::Mapping::Registry::TypedStructFactory, + { :type => XSD::QName.new("http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/", "Owner") } + ) + + Methods = [ + ["getAllListings", "getAllListings", [ + ["retval", "return", + [::SOAP::SOAPArray, "http://www.w3.org/2001/XMLSchema", "string"]]], + "", "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"], + ["getProductTree", "getProductTree", [ + ["retval", "return", + [::SOAP::SOAPStruct, "http://xml.apache.org/xml-soap", "Map"]]], + "", "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"], + ["getInfoFromCategory", "getInfoFromCategory", [ + ["in", "category", + [::SOAP::SOAPStruct, "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/", "Category"]], + ["retval", "return", + [::SOAP::SOAPArray, "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/", "Info"]]], + "", "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"], + ["getModifiedInfoSince", "getModifiedInfoSince", [ + ["in", "timeInstant", + [SOAP::SOAPDateTime]], + ["retval", "return", + [::SOAP::SOAPArray, "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/", "Info"]]], + "", "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"], + ["getInfoFromName", "getInfoFromName", [ + ["in", "productName", + [SOAP::SOAPString]], + ["retval", "return", + [::SOAP::SOAPStruct, "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/", "Info"]]], + "", "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"], + ["getInfoFromOwnerId", "getInfoFromOwnerId", [ + ["in", "ownerId", + [SOAP::SOAPInt]], + ["retval", "return", + [::SOAP::SOAPArray, "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/", "Info"]]], + "", "http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"] + ] + + def getAllListings + ["ruby", "soap4r"] + end +end + +class RAABaseServiceServer < SOAP::RPC::StandaloneServer + def initialize(*arg) + super + + servant = RAABaseServicePortType.new + RAABaseServicePortType::Methods.each do |name_as, name, params, soapaction, namespace| + qname = XSD::QName.new(namespace, name_as) + @soaplet.app_scope_router.add_method(servant, qname, soapaction, + name, params) + end + + self.mapping_registry = RAABaseServicePortType::MappingRegistry + end +end diff --git a/test/wsdl/raa/test_raa.rb b/test/wsdl/raa/test_raa.rb new file mode 100644 index 0000000000..f90c6222f4 --- /dev/null +++ b/test/wsdl/raa/test_raa.rb @@ -0,0 +1,78 @@ +require 'test/unit' +require 'soap/wsdlDriver' + + +module WSDL +module RAA + + +class TestRAA < Test::Unit::TestCase + DIR = File.dirname(File.expand_path(__FILE__)) + + Port = 17171 + + def setup + setup_server + setup_client + end + + def setup_server + $:.push(DIR) + require File.join(DIR, 'server.rb') + $:.delete(DIR) + @server = RAABaseServiceServer.new('RAA server', nil, '0.0.0.0', Port) + @server.level = Logger::Severity::ERROR + @t = Thread.new { + Thread.current.abort_on_exception = true + @server.start + } + while @server.server.nil? or @server.server.status != :Running + sleep 0.1 + unless @t.alive? + @t.join + raise + end + end + end + + def setup_client + wsdl = File.join(DIR, 'raa.wsdl') + @raa = ::SOAP::WSDLDriverFactory.new(wsdl).create_driver + @raa.endpoint_url = "http://localhost:#{Port}/" + end + + def teardown + teardown_server + teardown_client + end + + def teardown_server + @server.server.shutdown + @t.kill + @t.join + end + + def teardown_client + @raa.reset_stream + end + + def test_raa + assert_equal(["ruby", "soap4r"], @raa.getAllListings) + end + + def foo + p @raa.getProductTree() + p @raa.getInfoFromCategory(Category.new("Library", "XML")) + t = Time.at(Time.now.to_i - 24 * 3600) + p @raa.getModifiedInfoSince(t) + p @raa.getModifiedInfoSince(DateTime.new(t.year, t.mon, t.mday, t.hour, t.min, t.sec)) + o = @raa.getInfoFromName("SOAP4R") + p o.type + p o.owner.name + p o + end +end + + +end +end