mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
![nahi](/assets/img/avatar_default.png)
* lib/soap/header/* * lib/soap/rpc/httpserver.rb * lib/wsdl/soap/cgiStubCreator.rb * lib/wsdl/soap/classDefCreator.rb * lib/wsdl/soap/classDefCreatorSupport.rb * lib/wsdl/soap/clientSkeltonCreator.rb * lib/wsdl/soap/driverCreator.rb * lib/wsdl/soap/mappingRegistryCreator.rb * lib/wsdl/soap/methodDefCreator.rb * lib/wsdl/soap/servantSkeltonCreator.rb * lib/wsdl/soap/standaloneServerStubCreator.rb * lib/wsdl/xmlSchema/enumeration.rb * lib/wsdl/xmlSchema/simpleRestriction.rb * lib/wsdl/xmlSchema/simpleType.rb * lib/xsd/codegen/* * lib/xsd/codegen.rb * sample/soap/authheader/* * sample/soap/raa2.4/* * sample/soap/ssl/* * sample/soap/swa/* * sample/soap/whois.rb * sample/wsdl/raa2.4/* * test/soap/header/* * test/soap/ssl/* * test/soap/struct/* * test/soap/swa/* * test/soap/wsdlDriver/* * test/wsdl/multiplefault.wsdl * test/wsdl/simpletype/* * test/wsdl/test_multiplefault.rb * modified files: * lib/soap/baseData.rb * lib/soap/element.rb * lib/soap/generator.rb * lib/soap/netHttpClient.rb * lib/soap/parser.rb * lib/soap/property.rb * lib/soap/soap.rb * lib/soap/streamHandler.rb * lib/soap/wsdlDriver.rb * lib/soap/wsdlDriver.rb * lib/soap/encodingstyle/handler.rb * lib/soap/encodingstyle/literalHandler.rb * lib/soap/encodingstyle/soapHandler.rb * lib/soap/mapping/factory.rb * lib/soap/mapping/mapping.rb * lib/soap/mapping/registry.rb * lib/soap/mapping/rubytypeFactory.rb * lib/soap/mapping/wsdlRegistry.rb * lib/soap/rpc/cgistub.rb * lib/soap/rpc/driver.rb * lib/soap/rpc/proxy.rb * lib/soap/rpc/router.rb * lib/soap/rpc/soaplet.rb * lib/soap/rpc/standaloneServer.rb * lib/wsdl/data.rb * lib/wsdl/definitions.rb * lib/wsdl/operation.rb * lib/wsdl/parser.rb * lib/wsdl/soap/definitions.rb * lib/wsdl/xmlSchema/complexContent.rb * lib/wsdl/xmlSchema/complexType.rb * lib/wsdl/xmlSchema/data.rb * lib/wsdl/xmlSchema/parser.rb * lib/wsdl/xmlSchema/schema.rb * lib/xsd/datatypes.rb * lib/xsd/qname.rb * sample/soap/sampleStruct/server.rb * sample/wsdl/amazon/AmazonSearch.rb * sample/wsdl/amazon/AmazonSearchDriver.rb * test/soap/test_property.rb * test/soap/calc/test_calc_cgi.rb * test/wsdl/test_emptycomplextype.rb * summary * add SOAP Header mustUnderstand support. * add HTTP client SSL configuration and Cookies support (works completely with http-access2). * add header handler for handling sending/receiving SOAP Header. * map Ruby's anonymous Struct to common SOAP Struct in SOAP Object Model. it caused error. * add WSDL simpleType support to restrict lexical value space. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
300 lines
7.2 KiB
Ruby
300 lines
7.2 KiB
Ruby
# SOAP4R - SOAP RPC driver
|
|
# Copyright (C) 2000, 2001, 2003, 2004 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.
|
|
|
|
|
|
require 'soap/soap'
|
|
require 'soap/mapping'
|
|
require 'soap/rpc/rpc'
|
|
require 'soap/rpc/proxy'
|
|
require 'soap/rpc/element'
|
|
require 'soap/streamHandler'
|
|
require 'soap/property'
|
|
require 'soap/header/handlerset'
|
|
|
|
|
|
module SOAP
|
|
module RPC
|
|
|
|
|
|
class Driver
|
|
class EmptyResponseError < Error; end
|
|
|
|
class << self
|
|
def __attr_proxy(symbol, assignable = false)
|
|
name = symbol.to_s
|
|
module_eval <<-EOD
|
|
def #{name}
|
|
@servant.#{name}
|
|
end
|
|
EOD
|
|
if assignable
|
|
module_eval <<-EOD
|
|
def #{name}=(rhs)
|
|
@servant.#{name} = rhs
|
|
end
|
|
EOD
|
|
end
|
|
end
|
|
end
|
|
|
|
__attr_proxy :options
|
|
__attr_proxy :headerhandler
|
|
__attr_proxy :test_loopback_response
|
|
__attr_proxy :endpoint_url, true
|
|
__attr_proxy :mapping_registry, true
|
|
__attr_proxy :soapaction, true
|
|
__attr_proxy :default_encodingstyle, true
|
|
|
|
def httpproxy
|
|
@servant.options["protocol.http.proxy"]
|
|
end
|
|
|
|
def httpproxy=(httpproxy)
|
|
@servant.options["protocol.http.proxy"] = httpproxy
|
|
end
|
|
|
|
def wiredump_dev
|
|
@servant.options["protocol.http.wiredump_dev"]
|
|
end
|
|
|
|
def wiredump_dev=(wiredump_dev)
|
|
@servant.options["protocol.http.wiredump_dev"] = wiredump_dev
|
|
end
|
|
|
|
def mandatorycharset
|
|
@servant.options["protocol.mandatorycharset"]
|
|
end
|
|
|
|
def mandatorycharset=(mandatorycharset)
|
|
@servant.options["protocol.mandatorycharset"] = mandatorycharset
|
|
end
|
|
|
|
def wiredump_file_base
|
|
@servant.options["protocol.wiredump_file_base"]
|
|
end
|
|
|
|
def wiredump_file_base=(wiredump_file_base)
|
|
@servant.options["protocol.wiredump_file_base"] = wiredump_file_base
|
|
end
|
|
|
|
def initialize(endpoint_url, namespace, soapaction = nil)
|
|
@servant = Servant__.new(self, endpoint_url, namespace)
|
|
@servant.soapaction = soapaction
|
|
@proxy = @servant.proxy
|
|
end
|
|
|
|
def loadproperty(propertyname)
|
|
unless options.loadproperty(propertyname)
|
|
raise LoadError.new("No such property to load -- #{propertyname}")
|
|
end
|
|
end
|
|
|
|
def inspect
|
|
"#<#{self.class}:#{@servant.streamhandler.inspect}>"
|
|
end
|
|
|
|
def add_method(name, *params)
|
|
add_method_with_soapaction_as(name, name, @servant.soapaction, *params)
|
|
end
|
|
|
|
def add_method_as(name, name_as, *params)
|
|
add_method_with_soapaction_as(name, name_as, @servant.soapaction, *params)
|
|
end
|
|
|
|
def add_method_with_soapaction(name, soapaction, *params)
|
|
add_method_with_soapaction_as(name, name, soapaction, *params)
|
|
end
|
|
|
|
def add_method_with_soapaction_as(name, name_as, soapaction, *params)
|
|
param_def = if params.size == 1 and params[0].is_a?(Array)
|
|
params[0]
|
|
else
|
|
SOAPMethod.create_param_def(params)
|
|
end
|
|
@servant.add_method(name_as, soapaction, name, param_def)
|
|
end
|
|
|
|
def reset_stream
|
|
@servant.streamhandler.reset
|
|
end
|
|
|
|
def invoke(headers, body)
|
|
@servant.invoke(headers, body)
|
|
end
|
|
|
|
def call(name, *params)
|
|
@servant.call(name, *params)
|
|
end
|
|
|
|
private
|
|
|
|
def add_rpc_method_interface(name, param_def)
|
|
@servant.add_rpc_method_interface(name, param_def)
|
|
end
|
|
|
|
class Servant__
|
|
attr_reader :options
|
|
attr_reader :streamhandler
|
|
attr_reader :headerhandler
|
|
attr_reader :proxy
|
|
|
|
def initialize(host, endpoint_url, namespace)
|
|
@host = host
|
|
@namespace = namespace
|
|
@mapping_registry = nil
|
|
@soapaction = nil
|
|
@wiredump_file_base = nil
|
|
@options = setup_options
|
|
@streamhandler = HTTPPostStreamHandler.new(endpoint_url,
|
|
@options["protocol.http"] ||= ::SOAP::Property.new)
|
|
@headerhandler = Header::HandlerSet.new
|
|
@proxy = Proxy.new(@streamhandler, @soapaction)
|
|
@proxy.allow_unqualified_element = true
|
|
end
|
|
|
|
def endpoint_url
|
|
@streamhandler.endpoint_url
|
|
end
|
|
|
|
def endpoint_url=(endpoint_url)
|
|
@streamhandler.endpoint_url = endpoint_url
|
|
@streamhandler.reset
|
|
end
|
|
|
|
def mapping_registry
|
|
@mapping_registry
|
|
end
|
|
|
|
def mapping_registry=(mapping_registry)
|
|
@mapping_registry = mapping_registry
|
|
end
|
|
|
|
def soapaction
|
|
@soapaction
|
|
end
|
|
|
|
def soapaction=(soapaction)
|
|
@soapaction = soapaction
|
|
end
|
|
|
|
def default_encodingstyle
|
|
@proxy.default_encodingstyle
|
|
end
|
|
|
|
def default_encodingstyle=(encodingstyle)
|
|
@proxy.default_encodingstyle = encodingstyle
|
|
end
|
|
|
|
def test_loopback_response
|
|
@streamhandler.test_loopback_response
|
|
end
|
|
|
|
def invoke(headers, body)
|
|
set_wiredump_file_base(body.elename.name)
|
|
env = @proxy.invoke(headers, body)
|
|
if env.nil?
|
|
return nil, nil
|
|
else
|
|
return env.header, env.body
|
|
end
|
|
end
|
|
|
|
def call(name, *params)
|
|
set_wiredump_file_base(name)
|
|
# Convert parameters: params array => SOAPArray => members array
|
|
params = Mapping.obj2soap(params, @mapping_registry).to_a
|
|
env = @proxy.call(call_headers, name, *params)
|
|
raise EmptyResponseError.new("Empty response.") unless env
|
|
receive_headers(env.header)
|
|
begin
|
|
@proxy.check_fault(env.body)
|
|
rescue SOAP::FaultError => e
|
|
Mapping.fault2exception(e)
|
|
end
|
|
|
|
ret = env.body.response ?
|
|
Mapping.soap2obj(env.body.response, @mapping_registry) : nil
|
|
if env.body.outparams
|
|
outparams = env.body.outparams.collect { |outparam|
|
|
Mapping.soap2obj(outparam)
|
|
}
|
|
return [ret].concat(outparams)
|
|
else
|
|
return ret
|
|
end
|
|
end
|
|
|
|
def add_method(name_as, soapaction, name, param_def)
|
|
qname = XSD::QName.new(@namespace, name_as)
|
|
@proxy.add_method(qname, soapaction, name, param_def)
|
|
add_rpc_method_interface(name, param_def)
|
|
end
|
|
|
|
def add_rpc_method_interface(name, param_def)
|
|
param_names = []
|
|
i = 0
|
|
@proxy.method[name].each_param_name(RPC::SOAPMethod::IN,
|
|
RPC::SOAPMethod::INOUT) do |param_name|
|
|
i += 1
|
|
param_names << "arg#{ i }"
|
|
end
|
|
callparam = (param_names.collect { |pname| ", " + pname }).join
|
|
@host.instance_eval <<-EOS
|
|
def #{ name }(#{ param_names.join(", ") })
|
|
@servant.call(#{ name.dump }#{ callparam })
|
|
end
|
|
EOS
|
|
@host.method(name)
|
|
end
|
|
|
|
private
|
|
|
|
def call_headers
|
|
headers = @headerhandler.on_outbound
|
|
if headers.empty?
|
|
nil
|
|
else
|
|
h = ::SOAP::SOAPHeader.new
|
|
headers.each do |header|
|
|
h.add(header.elename.name, header)
|
|
end
|
|
h
|
|
end
|
|
end
|
|
|
|
def receive_headers(headers)
|
|
@headerhandler.on_inbound(headers) if headers
|
|
end
|
|
|
|
def set_wiredump_file_base(name)
|
|
if @wiredump_file_base
|
|
@streamhandler.wiredump_file_base = @wiredump_file_base + "_#{ name }"
|
|
end
|
|
end
|
|
|
|
def setup_options
|
|
if opt = Property.loadproperty(::SOAP::PropertyName)
|
|
opt = opt["client"]
|
|
end
|
|
opt ||= Property.new
|
|
opt.add_hook("protocol.mandatorycharset") do |key, value|
|
|
@proxy.mandatorycharset = value
|
|
end
|
|
opt.add_hook("protocol.wiredump_file_base") do |key, value|
|
|
@wiredump_file_base = value
|
|
end
|
|
opt["protocol.http.charset"] ||= XSD::Charset.encoding_label
|
|
opt["protocol.http.proxy"] ||= Env::HTTP_PROXY
|
|
opt["protocol.http.no_proxy"] ||= Env::NO_PROXY
|
|
opt
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
end
|
|
end
|