mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
165d101eed
commit
d268bf305e
15 changed files with 498 additions and 63 deletions
38
test/wsdl/datetime/DatetimeService.rb
Normal file
38
test/wsdl/datetime/DatetimeService.rb
Normal file
|
@ -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
test/wsdl/datetime/datetime.rb
Normal file
0
test/wsdl/datetime/datetime.rb
Normal file
45
test/wsdl/datetime/datetime.wsdl
Normal file
45
test/wsdl/datetime/datetime.wsdl
Normal file
|
@ -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>
|
21
test/wsdl/datetime/datetimeServant.rb
Normal file
21
test/wsdl/datetime/datetimeServant.rb
Normal file
|
@ -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
|
||||
|
81
test/wsdl/datetime/test_datetime.rb
Normal file
81
test/wsdl/datetime/test_datetime.rb
Normal file
|
@ -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
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
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
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
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
|
Loading…
Add table
Add a link
Reference in a new issue