summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-05 13:26:26 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-05 13:26:26 +0000
commit1ed39b739237bffd9c78e696c09462ce67017b95 (patch)
tree032499118c88146a86aede2d89fa707bb242edc7 /lib
parent3be09a4f4ffee94601051c37e5303b9546d816e1 (diff)
* lib/soap/netHttpClient.rb: proxy support did not work. fixed.
* lib/soap/property.rb: add class methods for loading property from stream/file/propertyfile. propertyfile is a file which is located at somedir in $:. * lib/soap/soap.rb, lib/soap/wsdlDriver.rb, lib/soap/rpc/driver.rb, lib/wsdl/importer.rb: load property from propertyfile 'soap/property' e.g. /usr/local/lib/ruby/site_ruby/1.8/soap/property. * test/soap/test_property.rb, test/soap/test_streamhandler.rb: new file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/soap/netHttpClient.rb19
-rw-r--r--lib/soap/property.rb42
-rw-r--r--lib/soap/rpc/driver.rb24
-rw-r--r--lib/soap/soap.rb1
-rw-r--r--lib/soap/wsdlDriver.rb26
-rw-r--r--lib/wsdl/importer.rb13
6 files changed, 87 insertions, 38 deletions
diff --git a/lib/soap/netHttpClient.rb b/lib/soap/netHttpClient.rb
index 3eacdad69d..a0b3b7ca26 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 84fa876cae..b67ffa8361 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 e6ca3f39d3..dd433ca33f 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 b082823181..ea2b4db2e1 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 3931c7c514..0961751474 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
diff --git a/lib/wsdl/importer.rb b/lib/wsdl/importer.rb
index df354311a1..fac02b51a0 100644
--- a/lib/wsdl/importer.rb
+++ b/lib/wsdl/importer.rb
@@ -9,6 +9,7 @@
require 'wsdl/info'
require 'wsdl/parser'
require 'soap/soap'
+require 'soap/property'
module WSDL
@@ -29,15 +30,15 @@ class Importer
content = File.open(location).read
else
client = web_client.new(nil, "WSDL4R")
- if env_httpproxy = ::SOAP::Env::HTTP_PROXY
- client.proxy = env_httpproxy
- end
- if env_no_proxy = ::SOAP::Env::NO_PROXY
- client.no_proxy = env_no_proxy
+ if opt = ::SOAP::Property.loadproperty(::SOAP::PropertyName)
+ client.proxy = opt["client.protocol.http.proxy"]
+ client.no_proxy = opt["client.protocol.http.no_proxy"]
end
+ client.proxy ||= ::SOAP::Env::HTTP_PROXY
+ client.no_proxy ||= ::SOAP::Env::NO_PROXY
content = client.get_content(location)
end
- opt = {} # charset?
+ opt = {}
begin
WSDL::Parser.new(opt).parse(content)
rescue WSDL::Parser::ParseError => orgexcn