diff options
Diffstat (limited to 'lib/soap')
-rw-r--r-- | lib/soap/netHttpClient.rb | 19 | ||||
-rw-r--r-- | lib/soap/property.rb | 42 | ||||
-rw-r--r-- | lib/soap/rpc/driver.rb | 24 | ||||
-rw-r--r-- | lib/soap/soap.rb | 1 | ||||
-rw-r--r-- | lib/soap/wsdlDriver.rb | 26 |
5 files changed, 80 insertions, 32 deletions
diff --git a/lib/soap/netHttpClient.rb b/lib/soap/netHttpClient.rb index 3eacdad69..a0b3b7ca2 100644 --- a/lib/soap/netHttpClient.rb +++ b/lib/soap/netHttpClient.rb @@ -21,7 +21,7 @@ class NetHttpClient false end - attr_accessor :proxy + attr_reader :proxy attr_accessor :no_proxy attr_accessor :debug_dev attr_accessor :ssl_config # ignored for now. @@ -34,21 +34,30 @@ class NetHttpClient @session_manager = SessionManager.new @no_proxy = nil end + + def proxy=(proxy_str) + if proxy_str.nil? + @proxy = nil + else + @proxy = URI.parse(proxy_str) + end + end def set_basic_auth(uri, user_id, passwd) - # ignored for now. + # net/http does not handle url. + @basic_auth = [user_id, passwd] end def set_cookie_store(filename) - # ignored for now. + # ignored. end def reset(url) - # ignored for now. + # no persistent connection. ignored. end def reset_all - # ignored for now. + # no persistent connection. ignored. end def post(url, req_body, header = {}) diff --git a/lib/soap/property.rb b/lib/soap/property.rb index 84fa876ca..b67ffa836 100644 --- a/lib/soap/property.rb +++ b/lib/soap/property.rb @@ -12,6 +12,44 @@ module SOAP class Property include Enumerable + # Property file format: + # line separator is \r?\n. 1 line per a property. + # line which begins with '#' is comment line. empty line is ignored. + # key/value separator is ':', '=', or \s. + # '\' as escape character. but line separator cannot be escaped. + # \s at the head/tail of key/value are trimmed. + def self.load(stream) + prop = new + stream.each_with_index do |line, lineno| + line.sub!(/\r?\n\z/, '') + next if /^(#.*|)$/ =~ line + if /^\s*([^=:\s\\]+(?:\\.[^=:\s\\]*)*)\s*[=:\s]\s*(.*)$/ =~ line + key, value = $1, $2 + key = eval("\"#{key}\"") + value = eval("\"#{value.strip}\"") + prop[key] = value + else + raise TypeError.new("property format error at line #{lineno + 1}: `#{line}'") + end + end + prop + end + + def self.open(filename) + File.open(filename) do |f| + load(f) + end + end + + def self.loadproperty(propname) + $:.each do |path| + if File.file?(file = File.join(path, propname)) + return open(file) + end + end + nil + end + def initialize @store = Hash.new @hook = Hash.new @@ -193,7 +231,7 @@ private when Symbol [name] when String - name.split(/\./) + name.scan(/[^.\\]+(?:\\.[^.\\])*/) # split with unescaped '.' when Array name else @@ -212,7 +250,7 @@ private end def to_key(name) - name.to_s.downcase.intern + name.to_s.downcase end def generate_new_key diff --git a/lib/soap/rpc/driver.rb b/lib/soap/rpc/driver.rb index e6ca3f39d..dd433ca33 100644 --- a/lib/soap/rpc/driver.rb +++ b/lib/soap/rpc/driver.rb @@ -82,12 +82,6 @@ class Driver @servant = Servant__.new(self, endpoint_url, namespace) @servant.soapaction = soapaction @proxy = @servant.proxy - if env_httpproxy = ::SOAP::Env::HTTP_PROXY - @servant.options["protocol.http.proxy"] = env_httpproxy - end - if env_no_proxy = ::SOAP::Env::NO_PROXY - @servant.options["protocol.http.no_proxy"] = env_no_proxy - end end def inspect @@ -144,8 +138,7 @@ private @mapping_registry = nil @soapaction = nil @wiredump_file_base = nil - @options = ::SOAP::Property.new - set_options + @options = setup_options @streamhandler = HTTPPostStreamHandler.new(endpoint_url, @options["protocol.http"] ||= ::SOAP::Property.new) @proxy = Proxy.new(@streamhandler, @soapaction) @@ -244,14 +237,21 @@ private end end - def set_options - @options.add_hook("protocol.mandatorycharset") do |key, value| + 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 - @options.add_hook("protocol.wiredump_file_base") do |key, value| + opt.add_hook("protocol.wiredump_file_base") do |key, value| @wiredump_file_base = value end - @options["protocol.http.charset"] = XSD::Charset.encoding_label + 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 diff --git a/lib/soap/soap.rb b/lib/soap/soap.rb index b08282318..ea2b4db2e 100644 --- a/lib/soap/soap.rb +++ b/lib/soap/soap.rb @@ -14,6 +14,7 @@ module SOAP Version = '1.5.2' +PropertyName = 'soap/property' EnvelopeNamespace = 'http://schemas.xmlsoap.org/soap/envelope/' EncodingNamespace = 'http://schemas.xmlsoap.org/soap/encoding/' diff --git a/lib/soap/wsdlDriver.rb b/lib/soap/wsdlDriver.rb index 3931c7c51..096175147 100644 --- a/lib/soap/wsdlDriver.rb +++ b/lib/soap/wsdlDriver.rb @@ -132,12 +132,6 @@ class WSDLDriver def initialize(wsdl, port, logdev) @servant = Servant__.new(self, wsdl, port, logdev) - if env_httpproxy = ::SOAP::Env::HTTP_PROXY - @servant.options["protocol.http.proxy"] = env_httpproxy - end - if env_httpproxy = ::SOAP::Env::NO_PROXY - @servant.options["protocol.http.no_proxy"] = env_httpproxy - end end def inspect @@ -171,8 +165,7 @@ class WSDLDriver @port = port @logdev = logdev - @options = ::SOAP::Property.new - set_options + @options = setup_options @mapping_registry = nil # for rpc unmarshal @wsdl_mapping_registry = nil # for rpc marshal @default_encodingstyle = EncodingNamespace @@ -189,7 +182,7 @@ class WSDLDriver @doc_mapper = Mapper.new(@wsdl_elements, @wsdl_types) endpoint_url = @port.soap_address.location @streamhandler = HTTPPostStreamHandler.new(endpoint_url, - @options["protocol.http"] ||= ::SOAP::Property.new) + @options["protocol.http"] ||= Property.new) # Convert a map which key is QName, to a Hash which key is String. @operations = {} @port.inputoperation_map.each do |op_name, op_info| @@ -402,14 +395,21 @@ class WSDLDriver @logdev.add(sev, nil, self.class) { yield } if @logdev end - def set_options - @options.add_hook("protocol.mandatorycharset") do |key, value| + def setup_options + if opt = Property.loadproperty(::SOAP::PropertyName) + opt = opt["client"] + end + opt ||= Property.new + opt.add_hook("protocol.mandatorycharset") do |key, value| @mandatorycharset = value end - @options.add_hook("protocol.wiredump_file_base") do |key, value| + opt.add_hook("protocol.wiredump_file_base") do |key, value| @wiredump_file_base = value end - @options["protocol.http.charset"] = XSD::Charset.encoding_label + 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 class Mapper |