* 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
This commit is contained in:
nahi 2003-11-30 04:33:02 +00:00
Родитель 165d101eed
Коммит d268bf305e
15 изменённых файлов: 498 добавлений и 63 удалений

Просмотреть файл

@ -1,3 +1,16 @@
Sun Nov 30 13:02:00 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* 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 <nobu@ruby-lang.org>
* string.c (rb_str_update): get rid of SEGV at just allocated String.

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -15,14 +15,66 @@ 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
def self.array_complextype
type = XMLSchema::ComplexType.new(::SOAP::ValueArrayName)
type.complexcontent = XMLSchema::ComplexContent.new
type.complexcontent.base = ::SOAP::ValueArrayName
attr = XMLSchema::Attribute.new
attr.ref = ::SOAP::AttrArrayTypeName
anytype = XSD::AnyTypeName.dup
anytype.name += '[]'
attr.arytype = anytype
type.complexcontent.attributes << attr
type
end
=begin
<xs:complexType name="Fault" final="extension">
<xs:sequence>
<xs:element name="faultcode" type="xs:QName" />
<xs:element name="faultstring" type="xs:string" />
<xs:element name="faultactor" type="xs:anyURI" minOccurs="0" />
<xs:element name="detail" type="tns:detail" minOccurs="0" />
</xs:sequence>
</xs:complexType>
=end
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)
faultactor = XMLSchema::Element.new(::SOAP::EleFaultActorName, XSD::XSDAnyURI::Type)
faultactor.minoccurs = 0
detail = XMLSchema::Element.new(::SOAP::EleFaultDetailName, XSD::AnyTypeName)
detail.minoccurs = 0
type.all_elements = [faultcode, faultstring, faultactor, detail]
type.final = 'extension'
type
end
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)
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)
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)
@ -66,53 +118,6 @@ private
XMLSchema::Element.new(qname, part.type)
}
end
def array_complextype
type = XMLSchema::ComplexType.new(::SOAP::ValueArrayName)
type.complexcontent = XMLSchema::ComplexContent.new
type.complexcontent.base = ::SOAP::ValueArrayName
attr = XMLSchema::Attribute.new
attr.ref = ::SOAP::AttrArrayTypeName
anytype = XSD::AnyTypeName.dup
anytype.name += '[]'
attr.arytype = anytype
type.complexcontent.attributes << attr
type
end
=begin
<xs:complexType name="Fault" final="extension">
<xs:sequence>
<xs:element name="faultcode" type="xs:QName" />
<xs:element name="faultstring" type="xs:string" />
<xs:element name="faultactor" type="xs:anyURI" minOccurs="0" />
<xs:element name="detail" type="tns:detail" minOccurs="0" />
</xs:sequence>
</xs:complexType>
=end
def 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)
faultactor = XMLSchema::Element.new(::SOAP::EleFaultActorName, XSD::XSDAnyURI::Type)
faultactor.minoccurs = 0
detail = XMLSchema::Element.new(::SOAP::EleFaultDetailName, XSD::AnyTypeName)
detail.minoccurs = 0
type.all_elements = [faultcode, faultstring, faultactor, detail]
type.final = 'extension'
type
end
def 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)
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)
type.all_elements = [excn_name, cause, backtrace, message]
type
end
end

Просмотреть файл

@ -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

Просмотреть файл

Просмотреть файл

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name = "datetime"
targetNamespace="urn:jp.gr.jin.rrr.example.datetime"
xmlns:tns="urn:jp.gr.jin.rrr.example.datetime"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:message name="nowRequest">
<wsdl:part name="now" type="xsd:dateTime"/>
</wsdl:message>
<wsdl:message name="nowResponse">
<wsdl:part name="now" type="xsd:dateTime"/>
</wsdl:message>
<wsdl:portType name="DatetimePortType">
<wsdl:operation name="now">
<wsdl:input message="tns:nowRequest" name="nowRequest"/>
<wsdl:output message="tns:nowResponse" name="nowResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="DatetimeBinding" type="tns:DatetimePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="now">
<soap:operation soapAction=""/>
<wsdl:input name="nowRequest">
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:jp.gr.jin.rrr.example.datetime" use="encoded"/>
</wsdl:input>
<wsdl:output name="nowResponse">
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:jp.gr.jin.rrr.example.datetime" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="DatetimeService">
<wsdl:port binding="tns:DatetimeBinding" name="DatetimePort">
<soap:address location="http://localhost:10080/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Просмотреть файл

@ -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

Просмотреть файл

@ -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

66
test/wsdl/map/map.wsdl Normal file
Просмотреть файл

@ -0,0 +1,66 @@
<?xml version="1.0"?>
<definitions
name="RAA"
targetNamespace="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"
xmlns:tns="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"
xmlns:txd="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:apachesoap="http://xml.apache.org/xml-soap">
<types>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.apache.org/xml-soap">
<complexType name="Map">
<sequence>
<element name="item" minOccurs="0" maxOccurs="unbounded">
<complexType>
<sequence>
<element name="key" type="anyType" />
<element name="value" type="anyType" />
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</schema>
</types>
<message name="mapRequest"/>
<message name="mapResponse">
<part name="return" type="apachesoap:Map"/>
</message>
<portType name="RAABaseServicePortType">
<operation name="map" parameterOrder="">
<input message="tns:mapRequest"/>
<output message="tns:mapResponse"/>
</operation>
</portType>
<binding name="RAABaseServicePortBinding" type="tns:RAABaseServicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="map">
<soap:operation soapAction=""/>
<input>
<soap:body use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"/>
</input>
<output>
<soap:body use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"/>
</output>
</operation>
</binding>
<service name="RAAService">
<port name="RAABaseServicePort" binding="tns:RAABaseServicePortBinding">
<soap:address location="http://raa.ruby-lang.org/soap/1.0.2/"/>
</port>
</service>
</definitions>

43
test/wsdl/map/map.xml Normal file
Просмотреть файл

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<n2:mapResponse xmlns:n1="http://schemas.xmlsoap.org/soap/encoding/" xmlns:n2="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xmlns:n3="http://xml.apache.org/xml-soap" xsi:type="n3:Map">
<item>
<key xsi:type="xsd:string">a</key>
<value xsi:type="n3:Map">
<item>
<key xsi:type="xsd:string">a1</key>
<value xsi:type="n1:Array" n1:arrayType="xsd:anyType[1]">
<item xsi:type="xsd:string">a1</item>
</value>
</item>
<item>
<key xsi:type="xsd:string">a2</key>
<value xsi:type="n1:Array" n1:arrayType="xsd:anyType[1]">
<item xsi:type="xsd:string">a2</item>
</value>
</item>
</value>
</item>
<item>
<key xsi:type="xsd:string">b</key>
<value xsi:type="n3:Map">
<item>
<key xsi:type="xsd:string">b1</key>
<value xsi:type="n1:Array" n1:arrayType="xsd:anyType[1]">
<item xsi:type="xsd:string">b1</item>
</value>
</item>
<item>
<key xsi:type="xsd:string">b2</key>
<value xsi:type="n1:Array" n1:arrayType="xsd:anyType[1]">
<item xsi:type="xsd:string">b2</item>
</value>
</item>
</value>
</item>
</return>
</n2:mapResponse>
</env:Body>
</env:Envelope>

37
test/wsdl/map/test_map.rb Normal file
Просмотреть файл

@ -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

51
test/wsdl/test_fault.rb Normal file
Просмотреть файл

@ -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__
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<env:Fault xmlns:n1="http://schemas.xmlsoap.org/soap/encoding/"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<faultcode xsi:type="xsd:string">Server</faultcode>
<faultstring xsi:type="xsd:string">faultstring</faultstring>
<faultactor xsi:type="xsd:string">faultactor</faultactor>
<detail xmlns:n2="http://www.ruby-lang.org/xmlns/ruby/type/custom"
xsi:type="n2:SOAPException">
<excn_type_name xsi:type="xsd:string">type</excn_type_name>
<cause href="#id123"/>
</detail>
</env:Fault>
<cause id="id123" xsi:type="xsd:int">5</cause>
</env:Body>
</env:Envelope>
__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

4
test/xsd/noencoding.xml Normal file
Просмотреть файл

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="euc-jp"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<!-- あいう -->
</schema>

Просмотреть файл

@ -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