From d268bf305e926b5418d843098e35462cf97df662 Mon Sep 17 00:00:00 2001 From: nahi Date: Sun, 30 Nov 2003 04:33:02 +0000 Subject: * lib/soap/encodingstyle/soapHandler.rb: refactoring - Simplifying Conditional Expressions. * lib/wsdl/soap/definitions.rb: refactoring - Move Method. * test/xsd/{test_noencoding.rb,noencoding.xml}: new files. test for encoding unspecified XML file parsing. * test/wsdl/{test_fault.rb,map,datetime}: new files. test of SOAPFault, dateTime and Apache's Map. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 13 +++++ MANIFEST | 10 ++++ lib/soap/encodingstyle/soapHandler.rb | 28 ++++----- lib/wsdl/soap/definitions.rb | 103 ++++++++++++++++++---------------- test/wsdl/datetime/DatetimeService.rb | 38 +++++++++++++ test/wsdl/datetime/datetime.rb | 0 test/wsdl/datetime/datetime.wsdl | 45 +++++++++++++++ test/wsdl/datetime/datetimeServant.rb | 21 +++++++ test/wsdl/datetime/test_datetime.rb | 81 ++++++++++++++++++++++++++ test/wsdl/map/map.wsdl | 66 ++++++++++++++++++++++ test/wsdl/map/map.xml | 43 ++++++++++++++ test/wsdl/map/test_map.rb | 37 ++++++++++++ test/wsdl/test_fault.rb | 51 +++++++++++++++++ test/xsd/noencoding.xml | 4 ++ test/xsd/test_noencoding.rb | 21 +++++++ 15 files changed, 498 insertions(+), 63 deletions(-) create mode 100644 test/wsdl/datetime/DatetimeService.rb create mode 100644 test/wsdl/datetime/datetime.rb create mode 100644 test/wsdl/datetime/datetime.wsdl create mode 100644 test/wsdl/datetime/datetimeServant.rb create mode 100644 test/wsdl/datetime/test_datetime.rb create mode 100644 test/wsdl/map/map.wsdl create mode 100644 test/wsdl/map/map.xml create mode 100644 test/wsdl/map/test_map.rb create mode 100644 test/wsdl/test_fault.rb create mode 100644 test/xsd/noencoding.xml create mode 100644 test/xsd/test_noencoding.rb diff --git a/ChangeLog b/ChangeLog index c7143225d4..4ddff16533 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Sun Nov 30 13:02:00 2003 NAKAMURA, Hiroshi + + * lib/soap/encodingstyle/soapHandler.rb: refactoring - Simplifying + Conditional Expressions. + + * lib/wsdl/soap/definitions.rb: refactoring - Move Method. + + * test/xsd/{test_noencoding.rb,noencoding.xml}: new files. test for + encoding unspecified XML file parsing. + + * test/wsdl/{test_fault.rb,map,datetime}: new files. test of + SOAPFault, dateTime and Apache's Map. + Sun Nov 30 09:35:14 2003 Nobuyoshi Nakada * string.c (rb_str_update): get rid of SEGV at just allocated String. diff --git a/MANIFEST b/MANIFEST index cb8d44dd2a..e31f2f6b24 100644 --- a/MANIFEST +++ b/MANIFEST @@ -729,7 +729,15 @@ test/uri/test_mailto.rb test/wsdl/axisArray/axisArray.wsdl test/wsdl/axisArray/itemList.rb test/wsdl/axisArray/test_axisarray.rb +test/wsdl/datetime/DatetimeService.rb +test/wsdl/datetime/datetime.rb +test/wsdl/datetime/datetime.wsdl +test/wsdl/datetime/datetimeServant.rb +test/wsdl/datetime/test_datetime.rb test/wsdl/emptycomplextype.wsdl +test/wsdl/map/map.wsdl +test/wsdl/map/map.xml +test/wsdl/map/test_map.rb test/wsdl/raa/RAA.rb test/wsdl/raa/README.txt test/wsdl/raa/RAAServant.rb @@ -737,6 +745,8 @@ test/wsdl/raa/RAAService.rb test/wsdl/raa/raa.wsdl test/wsdl/raa/test_raa.rb test/wsdl/test_emptycomplextype.rb +test/xsd/noencoding.xml +test/xsd/test_noencoding.rb test/xsd/test_xmlschemaparser.rb test/xsd/test_xsd.rb test/xsd/xmlschema.xml diff --git a/lib/soap/encodingstyle/soapHandler.rb b/lib/soap/encodingstyle/soapHandler.rb index 1f359bef4e..9aa732535e 100644 --- a/lib/soap/encodingstyle/soapHandler.rb +++ b/lib/soap/encodingstyle/soapHandler.rb @@ -331,30 +331,30 @@ private def decode_tag_by_wsdl(ns, elename, typestr, parent, arytypestr, extraattr) o = nil - # should branch by root attribute? if parent.class == SOAPBody + # root element: should branch by root attribute? if @is_first_top_ele # Unqualified name is allowed here. @is_first_top_ele = false type = @decode_typemap[elename] || @decode_typemap.find_name(elename.name) - unless type - raise EncodingStyleError.new("Unknown operation '#{ elename }'.") + if type + o = SOAPStruct.new(elename) + o.definedtype = type + return o end - o = SOAPStruct.new(elename) - o.definedtype = type - return o - elsif !typestr - # typeless multi-ref element. - return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, - extraattr) - else - # typed multi-ref element. + end + # multi-ref element. + if typestr typename = ns.parse(typestr) typedef = @decode_typemap[typename] - return decode_defined_compoundtype(elename, typename, typedef, - arytypestr) + if typedef + return decode_defined_compoundtype(elename, typename, typedef, + arytypestr) + end end + return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, + extraattr) end if parent.type == XSD::AnyTypeName diff --git a/lib/wsdl/soap/definitions.rb b/lib/wsdl/soap/definitions.rb index 1a152ee693..7a62242204 100644 --- a/lib/wsdl/soap/definitions.rb +++ b/lib/wsdl/soap/definitions.rb @@ -15,59 +15,15 @@ module WSDL class Definitions < Info - def soap_rpc_complextypes(binding) - types = rpc_operation_complextypes(binding) + def self.soap_rpc_complextypes + types = XSD::NamedElements.new types << array_complextype types << fault_complextype types << exception_complextype types end -private - - def rpc_operation_complextypes(binding) - types = XSD::NamedElements.new - binding.operations.each do |op_bind| - if op_bind_rpc?(op_bind) - operation = op_bind.find_operation - if op_bind.input - type = XMLSchema::ComplexType.new(operation_input_name(operation)) - message = messages[operation.input.message] - type.sequence_elements = elements_from_message(message) - types << type - end - if op_bind.output - type = XMLSchema::ComplexType.new(operation_output_name(operation)) - message = messages[operation.output.message] - type.sequence_elements = elements_from_message(message) - types << type - end - end - end - types - end - - def operation_input_name(operation) - operation.input.name || operation.name - end - - def operation_output_name(operation) - operation.output.name || - XSD::QName.new(operation.name.namespace, operation.name.name + "Response") - end - - def op_bind_rpc?(op_bind) - op_bind.soapoperation and op_bind.soapoperation.operation_style == :rpc - end - - def elements_from_message(message) - message.parts.collect { |part| - qname = XSD::QName.new(nil, part.name) - XMLSchema::Element.new(qname, part.type) - } - end - - def array_complextype + def self.array_complextype type = XMLSchema::ComplexType.new(::SOAP::ValueArrayName) type.complexcontent = XMLSchema::ComplexContent.new type.complexcontent.base = ::SOAP::ValueArrayName @@ -90,7 +46,7 @@ private =end - def fault_complextype + def self.fault_complextype type = XMLSchema::ComplexType.new(::SOAP::EleFaultName) faultcode = XMLSchema::Element.new(::SOAP::EleFaultCodeName, XSD::XSDQName::Type) faultstring = XMLSchema::Element.new(::SOAP::EleFaultStringName, XSD::XSDString::Type) @@ -103,7 +59,7 @@ private type end - def exception_complextype + def self.exception_complextype type = XMLSchema::ComplexType.new(XSD::QName.new( ::SOAP::Mapping::RubyCustomTypeNamespace, 'SOAPException')) excn_name = XMLSchema::Element.new(XSD::QName.new(nil, 'excn_type_name'), XSD::XSDString::Type) @@ -113,6 +69,55 @@ private type.all_elements = [excn_name, cause, backtrace, message] type end + + def soap_rpc_complextypes(binding) + types = rpc_operation_complextypes(binding) + types + self.class.soap_rpc_complextypes + end + +private + + def rpc_operation_complextypes(binding) + types = XSD::NamedElements.new + binding.operations.each do |op_bind| + if op_bind_rpc?(op_bind) + operation = op_bind.find_operation + if op_bind.input + type = XMLSchema::ComplexType.new(operation_input_name(operation)) + message = messages[operation.input.message] + type.sequence_elements = elements_from_message(message) + types << type + end + if op_bind.output + type = XMLSchema::ComplexType.new(operation_output_name(operation)) + message = messages[operation.output.message] + type.sequence_elements = elements_from_message(message) + types << type + end + end + end + types + end + + def operation_input_name(operation) + operation.input.name || operation.name + end + + def operation_output_name(operation) + operation.output.name || + XSD::QName.new(operation.name.namespace, operation.name.name + "Response") + end + + def op_bind_rpc?(op_bind) + op_bind.soapoperation and op_bind.soapoperation.operation_style == :rpc + end + + def elements_from_message(message) + message.parts.collect { |part| + qname = XSD::QName.new(nil, part.name) + XMLSchema::Element.new(qname, part.type) + } + end end diff --git a/test/wsdl/datetime/DatetimeService.rb b/test/wsdl/datetime/DatetimeService.rb new file mode 100644 index 0000000000..91c006005d --- /dev/null +++ b/test/wsdl/datetime/DatetimeService.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby +require 'datetimeServant.rb' + +require 'soap/rpc/standaloneServer' + +class DatetimePortType + MappingRegistry = SOAP::Mapping::Registry.new + + # No mapping definition + + Methods = [ + ["now", "now", [ + ["in", "now", + [SOAP::SOAPDateTime]], + ["retval", "now", + [SOAP::SOAPDateTime]]], "", "urn:jp.gr.jin.rrr.example.datetime"] + ] +end + +class DatetimePortTypeApp < SOAP::RPC::StandaloneServer + def initialize(*arg) + super + + servant = DatetimePortType.new + DatetimePortType::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 = DatetimePortType::MappingRegistry + end +end + +# Change listen port. +if $0 == __FILE__ + DatetimePortTypeApp.new('app', nil, '0.0.0.0', 10080).start +end diff --git a/test/wsdl/datetime/datetime.rb b/test/wsdl/datetime/datetime.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/wsdl/datetime/datetime.wsdl b/test/wsdl/datetime/datetime.wsdl new file mode 100644 index 0000000000..4998dc48d6 --- /dev/null +++ b/test/wsdl/datetime/datetime.wsdl @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/wsdl/datetime/datetimeServant.rb b/test/wsdl/datetime/datetimeServant.rb new file mode 100644 index 0000000000..14145c42e5 --- /dev/null +++ b/test/wsdl/datetime/datetimeServant.rb @@ -0,0 +1,21 @@ +require 'datetime.rb' + +class DatetimePortType + # SYNOPSIS + # now(now) + # + # ARGS + # now - {http://www.w3.org/2001/XMLSchema}dateTime + # + # RETURNS + # now - {http://www.w3.org/2001/XMLSchema}dateTime + # + # RAISES + # (undefined) + # + def now(now) + #raise NotImplementedError.new + now + 1 + end +end + diff --git a/test/wsdl/datetime/test_datetime.rb b/test/wsdl/datetime/test_datetime.rb new file mode 100644 index 0000000000..a60d9b70a0 --- /dev/null +++ b/test/wsdl/datetime/test_datetime.rb @@ -0,0 +1,81 @@ +require 'test/unit' +require 'soap/wsdlDriver' + + +module WSDL +module Datetime + + +class TestDatetime < 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, 'DatetimeService.rb') + $:.delete(DIR) + @server = DatetimePortTypeApp.new('Datetime 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, 'datetime.wsdl') + @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_driver + @client.endpoint_url = "http://localhost:#{Port}/" + @client.generate_explicit_type = true + end + + def teardown + teardown_server + teardown_client + end + + def teardown_server + @server.server.shutdown + @t.kill + @t.join + end + + def teardown_client + @client.reset_stream + end + + def test_datetime + d = DateTime.now + assert_equal(d + 1, @client.now(d)) + end + + def test_time + d = DateTime.now + t = Time.gm(d.year, d.month, d.day, d.hour, d.min, d.sec) + d2 = d + 1 + t2 = @client.now(t) + assert_equal(d2.year, t2.year) + assert_equal(d2.month, t2.month) + assert_equal(d2.day, t2.day) + assert_equal(d2.hour, t2.hour) + assert_equal(d2.min, t2.min) + assert_equal(d2.sec, t2.sec) + end +end + + +end +end diff --git a/test/wsdl/map/map.wsdl b/test/wsdl/map/map.wsdl new file mode 100644 index 0000000000..7b1a140827 --- /dev/null +++ b/test/wsdl/map/map.wsdl @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/wsdl/map/map.xml b/test/wsdl/map/map.xml new file mode 100644 index 0000000000..7106735ffc --- /dev/null +++ b/test/wsdl/map/map.xml @@ -0,0 +1,43 @@ + + + + + + + a + + + a1 + + a1 + + + + a2 + + a2 + + + + + + b + + + b1 + + b1 + + + + b2 + + b2 + + + + + + + + diff --git a/test/wsdl/map/test_map.rb b/test/wsdl/map/test_map.rb new file mode 100644 index 0000000000..b0f2fb5a53 --- /dev/null +++ b/test/wsdl/map/test_map.rb @@ -0,0 +1,37 @@ +require 'test/unit' +require 'soap/processor' +require 'soap/mapping' +require 'soap/rpc/element' +require 'wsdl/importer' + + +module WSDL + + +class TestMap < Test::Unit::TestCase + def setup + end + + def test_by_wsdl + dir = File.dirname(File.expand_path(__FILE__)) + wsdlfile = File.join(dir, 'map.wsdl') + xml = File.open(File.join(dir, 'map.xml')) { |f| f.read } + wsdl = WSDL::Importer.import(wsdlfile) + service = wsdl.services[0] + port = service.ports[0] + wsdl_types = wsdl.collect_complextypes + rpc_decode_typemap = wsdl_types + wsdl.soap_rpc_complextypes(port.find_binding) + opt = {} + opt[:default_encodingstyle] = ::SOAP::EncodingNamespace + opt[:decode_typemap] = rpc_decode_typemap + header, body = ::SOAP::Processor.unmarshal(xml, opt) + map = ::SOAP::Mapping.soap2obj(body.response) + assert_equal(["a1"], map["a"]["a1"]) + assert_equal(["a2"], map["a"]["a2"]) + assert_equal(["b1"], map["b"]["b1"]) + assert_equal(["b2"], map["b"]["b2"]) + end +end + + +end diff --git a/test/wsdl/test_fault.rb b/test/wsdl/test_fault.rb new file mode 100644 index 0000000000..ec414528ee --- /dev/null +++ b/test/wsdl/test_fault.rb @@ -0,0 +1,51 @@ +require 'test/unit' +require 'soap/processor' +require 'soap/mapping' +require 'soap/rpc/element' +require 'wsdl/parser' + + +module WSDL + + +class TestFault < Test::Unit::TestCase + def setup + @xml =<<__EOX__ + + + + + Server + faultstring + faultactor + + type + + + + 5 + + +__EOX__ + end + + def test_by_wsdl + rpc_decode_typemap = WSDL::Definitions.soap_rpc_complextypes + opt = {} + opt[:default_encodingstyle] = ::SOAP::EncodingNamespace + opt[:decode_typemap] = rpc_decode_typemap + header, body = ::SOAP::Processor.unmarshal(@xml, opt) + fault = ::SOAP::Mapping.soap2obj(body.response) + assert_equal("Server", fault.faultcode) + assert_equal("faultstring", fault.faultstring) + assert_equal(URI.parse("faultactor"), fault.faultactor) + assert_equal(5, fault.detail.cause) + end +end + + +end diff --git a/test/xsd/noencoding.xml b/test/xsd/noencoding.xml new file mode 100644 index 0000000000..614ffa34ad --- /dev/null +++ b/test/xsd/noencoding.xml @@ -0,0 +1,4 @@ + + + + diff --git a/test/xsd/test_noencoding.rb b/test/xsd/test_noencoding.rb new file mode 100644 index 0000000000..0f2daae05f --- /dev/null +++ b/test/xsd/test_noencoding.rb @@ -0,0 +1,21 @@ +require 'test/unit' +require 'wsdl/xmlSchema/parser' + + +module XSD + + +class TestEmptyCharset < Test::Unit::TestCase + def setup + @file = File.join(File.dirname(File.expand_path(__FILE__)), 'noencoding.xml') + end + + def test_wsdl + xml = WSDL::XMLSchema::Parser.new.parse(File.open(@file) { |f| f.read }) + assert_equal(WSDL::XMLSchema::Schema, xml.class) + assert_equal(0, xml.collect_elements.size) + end +end + + +end -- cgit v1.2.3