* 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 - SOAP XML Instance Parser library.
|
|
|
|
# Copyright (C) 2001, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
|
require 'xsd/ns'
|
|
|
|
require 'xsd/xmlparser'
|
|
|
|
require 'soap/soap'
|
|
|
|
require 'soap/baseData'
|
|
|
|
require 'soap/encodingstyle/handler'
|
|
|
|
|
|
|
|
|
|
|
|
module SOAP
|
|
|
|
|
|
|
|
|
|
|
|
class Parser
|
|
|
|
include SOAP
|
|
|
|
|
|
|
|
class ParseError < Error; end
|
|
|
|
class FormatDecodeError < ParseError; end
|
|
|
|
class UnexpectedElementError < ParseError; end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
class ParseFrame
|
|
|
|
attr_reader :node
|
|
|
|
attr_reader :name
|
|
|
|
attr_reader :ns, :encodingstyle
|
|
|
|
|
|
|
|
class NodeContainer
|
|
|
|
def initialize(node)
|
|
|
|
@node = node
|
|
|
|
end
|
|
|
|
|
|
|
|
def node
|
|
|
|
@node
|
|
|
|
end
|
|
|
|
|
|
|
|
def replace_node(node)
|
|
|
|
@node = node
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
public
|
|
|
|
|
|
|
|
def initialize(ns, name, node, encodingstyle)
|
|
|
|
@ns = ns
|
|
|
|
@name = name
|
|
|
|
self.node = node
|
|
|
|
@encodingstyle = encodingstyle
|
|
|
|
end
|
|
|
|
|
|
|
|
def node=(node)
|
|
|
|
@node = NodeContainer.new(node)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
public
|
|
|
|
|
2005-09-15 10:33:53 -04:00
|
|
|
attr_accessor :envelopenamespace
|
2003-09-24 11:18:44 -04:00
|
|
|
attr_accessor :default_encodingstyle
|
|
|
|
attr_accessor :decode_typemap
|
|
|
|
attr_accessor :allow_unqualified_element
|
|
|
|
|
|
|
|
def initialize(opt = {})
|
* 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
|
|
|
@opt = opt
|
2003-09-24 11:18:44 -04:00
|
|
|
@parser = XSD::XMLParser.create_parser(self, opt)
|
|
|
|
@parsestack = nil
|
|
|
|
@lastnode = nil
|
|
|
|
@handlers = {}
|
2005-09-15 10:33:53 -04:00
|
|
|
@envelopenamespace = opt[:envelopenamespace] || EnvelopeNamespace
|
2003-09-24 11:18:44 -04:00
|
|
|
@default_encodingstyle = opt[:default_encodingstyle] || EncodingNamespace
|
|
|
|
@decode_typemap = opt[:decode_typemap] || nil
|
|
|
|
@allow_unqualified_element = opt[:allow_unqualified_element] || false
|
|
|
|
end
|
|
|
|
|
|
|
|
def charset
|
|
|
|
@parser.charset
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse(string_or_readable)
|
|
|
|
@parsestack = []
|
|
|
|
@lastnode = nil
|
|
|
|
|
|
|
|
@handlers.each do |uri, handler|
|
|
|
|
handler.decode_prologue
|
|
|
|
end
|
|
|
|
|
|
|
|
@parser.do_parse(string_or_readable)
|
|
|
|
|
|
|
|
unless @parsestack.empty?
|
|
|
|
raise FormatDecodeError.new("Unbalanced tag in XML.")
|
|
|
|
end
|
|
|
|
|
|
|
|
@handlers.each do |uri, handler|
|
|
|
|
handler.decode_epilogue
|
|
|
|
end
|
|
|
|
|
|
|
|
@lastnode
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_element(name, attrs)
|
|
|
|
lastframe = @parsestack.last
|
|
|
|
ns = parent = parent_encodingstyle = nil
|
|
|
|
if lastframe
|
|
|
|
ns = lastframe.ns.clone_ns
|
|
|
|
parent = lastframe.node
|
|
|
|
parent_encodingstyle = lastframe.encodingstyle
|
|
|
|
else
|
|
|
|
ns = XSD::NS.new
|
|
|
|
parent = ParseFrame::NodeContainer.new(nil)
|
|
|
|
parent_encodingstyle = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
attrs = XSD::XMLParser.filter_ns(ns, attrs)
|
|
|
|
encodingstyle = find_encodingstyle(ns, attrs)
|
|
|
|
|
|
|
|
# Children's encodingstyle is derived from its parent.
|
2004-07-03 09:33:20 -04:00
|
|
|
if encodingstyle.nil?
|
|
|
|
if parent.node.is_a?(SOAPHeader)
|
|
|
|
encodingstyle = LiteralNamespace
|
|
|
|
else
|
|
|
|
encodingstyle = parent_encodingstyle || @default_encodingstyle
|
|
|
|
end
|
|
|
|
end
|
2003-09-24 11:18:44 -04:00
|
|
|
|
|
|
|
node = decode_tag(ns, name, attrs, parent, encodingstyle)
|
|
|
|
|
|
|
|
@parsestack << ParseFrame.new(ns, name, node, encodingstyle)
|
|
|
|
end
|
|
|
|
|
|
|
|
def characters(text)
|
|
|
|
lastframe = @parsestack.last
|
|
|
|
if lastframe
|
|
|
|
# Need not to be cloned because character does not have attr.
|
2005-09-15 10:33:53 -04:00
|
|
|
decode_text(lastframe.ns, text, lastframe.encodingstyle)
|
2003-09-24 11:18:44 -04:00
|
|
|
else
|
|
|
|
# Ignore Text outside of SOAP Envelope.
|
|
|
|
p text if $DEBUG
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_element(name)
|
|
|
|
lastframe = @parsestack.pop
|
|
|
|
unless name == lastframe.name
|
|
|
|
raise UnexpectedElementError.new("Closing element name '#{ name }' does not match with opening element '#{ lastframe.name }'.")
|
|
|
|
end
|
|
|
|
decode_tag_end(lastframe.ns, lastframe.node, lastframe.encodingstyle)
|
|
|
|
@lastnode = lastframe.node.node
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_encodingstyle(ns, attrs)
|
|
|
|
attrs.each do |key, value|
|
2005-09-15 10:33:53 -04:00
|
|
|
if (ns.compare(@envelopenamespace, AttrEncodingStyle, key))
|
2003-09-24 11:18:44 -04:00
|
|
|
return value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def decode_tag(ns, name, attrs, parent, encodingstyle)
|
|
|
|
ele = ns.parse(name)
|
|
|
|
|
|
|
|
# Envelope based parsing.
|
2005-09-15 10:33:53 -04:00
|
|
|
if ((ele.namespace == @envelopenamespace) ||
|
2003-09-24 11:18:44 -04:00
|
|
|
(@allow_unqualified_element && ele.namespace.nil?))
|
|
|
|
o = decode_soap_envelope(ns, ele, attrs, parent)
|
|
|
|
return o if o
|
|
|
|
end
|
|
|
|
|
|
|
|
# Encoding based parsing.
|
|
|
|
handler = find_handler(encodingstyle)
|
|
|
|
if handler
|
|
|
|
return handler.decode_tag(ns, ele, attrs, parent)
|
|
|
|
else
|
|
|
|
raise FormatDecodeError.new("Unknown encodingStyle: #{ encodingstyle }.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def decode_tag_end(ns, node, encodingstyle)
|
|
|
|
return unless encodingstyle
|
|
|
|
|
|
|
|
handler = find_handler(encodingstyle)
|
|
|
|
if handler
|
|
|
|
return handler.decode_tag_end(ns, node)
|
|
|
|
else
|
|
|
|
raise FormatDecodeError.new("Unknown encodingStyle: #{ encodingstyle }.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def decode_text(ns, text, encodingstyle)
|
|
|
|
handler = find_handler(encodingstyle)
|
|
|
|
|
|
|
|
if handler
|
|
|
|
handler.decode_text(ns, text)
|
|
|
|
else
|
|
|
|
# How should I do?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def decode_soap_envelope(ns, ele, attrs, parent)
|
|
|
|
o = nil
|
|
|
|
if ele.name == EleEnvelope
|
|
|
|
o = SOAPEnvelope.new
|
* 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
|
|
|
if ext = @opt[:external_content]
|
|
|
|
ext.each do |k, v|
|
|
|
|
o.external_content[k] = v
|
|
|
|
end
|
|
|
|
end
|
2003-09-24 11:18:44 -04:00
|
|
|
elsif ele.name == EleHeader
|
|
|
|
unless parent.node.is_a?(SOAPEnvelope)
|
|
|
|
raise FormatDecodeError.new("Header should be a child of Envelope.")
|
|
|
|
end
|
|
|
|
o = SOAPHeader.new
|
|
|
|
parent.node.header = o
|
|
|
|
elsif ele.name == EleBody
|
|
|
|
unless parent.node.is_a?(SOAPEnvelope)
|
|
|
|
raise FormatDecodeError.new("Body should be a child of Envelope.")
|
|
|
|
end
|
|
|
|
o = SOAPBody.new
|
|
|
|
parent.node.body = o
|
|
|
|
elsif ele.name == EleFault
|
|
|
|
unless parent.node.is_a?(SOAPBody)
|
|
|
|
raise FormatDecodeError.new("Fault should be a child of Body.")
|
|
|
|
end
|
|
|
|
o = SOAPFault.new
|
|
|
|
parent.node.fault = o
|
|
|
|
end
|
|
|
|
o
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_handler(encodingstyle)
|
|
|
|
unless @handlers.key?(encodingstyle)
|
|
|
|
handler_factory = SOAP::EncodingStyle::Handler.handler(encodingstyle) ||
|
|
|
|
SOAP::EncodingStyle::Handler.handler(EncodingNamespace)
|
|
|
|
handler = handler_factory.new(@parser.charset)
|
|
|
|
handler.decode_typemap = @decode_typemap
|
|
|
|
handler.decode_prologue
|
|
|
|
@handlers[encodingstyle] = handler
|
|
|
|
end
|
|
|
|
@handlers[encodingstyle]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|