2
require 'soap/rpc/driver'
4
require 'webrick/httpproxy'
11
class TestStreamHandler < Test::Unit::TestCase
16
@logger = Logger.new(STDERR)
17
@logger.level = Logger::Severity::ERROR
18
@url = "http://localhost:#{Port}/"
19
@proxyurl = "http://localhost:#{ProxyPort}/"
20
@server = @proxyserver = @client = nil
21
@server_thread = @proxyserver_thread = nil
28
teardown_proxyserver if @proxyserver
33
@server = WEBrick::HTTPServer.new(
34
:BindAddress => "0.0.0.0",
38
:DocumentRoot => File.dirname(File.expand_path(__FILE__))
42
WEBrick::HTTPServlet::ProcHandler.new(method(:do_server_proc).to_proc)
44
@server_thread = start_server_thread(@server)
48
@proxyserver = WEBrick::HTTPProxyServer.new(
49
:BindAddress => "0.0.0.0",
54
@proxyserver_thread = start_server_thread(@proxyserver)
58
@client = SOAP::RPC::Driver.new(@url, '')
59
@client.add_method("do_server_proc")
68
def teardown_proxyserver
70
@proxyserver_thread.kill
71
@proxyserver_thread.join
78
def start_server_thread(server)
80
Thread.current.abort_on_exception = true
86
def do_server_proc(req, res)
87
res['content-type'] = 'text/xml'
89
<?xml version="1.0" encoding="utf-8" ?>
90
<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">
92
<n1:do_server_proc xmlns:n1="urn:foo" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
93
<return xsi:nil="true"/>
100
def parse_req_header(str)
101
if ::SOAP::HTTPStreamHandler::Client.to_s == 'SOAP::NetHttpClient'
102
str = eval(str.split(/\r?\n/)[4][3..-1])
104
parse_req_header_http_access2(str)
107
def parse_req_header_http_access2(str)
111
str.split(/(?:\r?\n)/).each do |line|
112
if headerp and /^$/ =~line
117
k, v = line.scan(/^([^:]+):\s*(.*)$/)[0]
118
headers[k.downcase] = v
130
@client.wiredump_dev = str
131
assert_nil(@client.do_server_proc)
132
r, h = parse_req_header(str)
133
assert_match(%r"POST / HTTP/1.", r)
134
assert(/^text\/xml;/ =~ h["content-type"])
138
# initialize client with URI object
139
@client = SOAP::RPC::Driver.new(URI.parse(@url), '')
140
@client.add_method("do_server_proc")
141
# same as test_normal
143
@client.wiredump_dev = str
144
assert_nil(@client.do_server_proc)
145
r, h = parse_req_header(str)
146
assert_match(%r"POST / HTTP/1.", r)
147
assert(/^text\/xml;/ =~ h["content-type"])
151
unless Object.const_defined?('HTTPAccess2')
152
# soap4r + net/http + basic_auth is not supported.
153
# use http-access2 instead.
158
@client.wiredump_dev = str
159
@client.options["protocol.http.basic_auth"] << [@url, "foo", "bar"]
160
assert_nil(@client.do_server_proc)
161
r, h = parse_req_header(str)
162
assert_equal("Basic Zm9vOmJhcg==", h["authorization"])
166
if Object.const_defined?('HTTPAccess2')
167
backup = HTTPAccess2::Client::NO_PROXY_HOSTS.dup
168
HTTPAccess2::Client::NO_PROXY_HOSTS.clear
170
backup = SOAP::NetHttpClient::NO_PROXY_HOSTS.dup
171
SOAP::NetHttpClient::NO_PROXY_HOSTS.clear
175
@client.wiredump_dev = str
176
@client.options["protocol.http.proxy"] = @proxyurl
177
assert_nil(@client.do_server_proc)
178
r, h = parse_req_header(str)
179
assert_match(%r"POST http://localhost:17171/ HTTP/1.", r)
181
assert_raise(ArgumentError) do
182
@client.options["protocol.http.proxy"] = 'ftp://foo:8080'
185
if Object.const_defined?('HTTPAccess2')
186
HTTPAccess2::Client::NO_PROXY_HOSTS.replace(backup)
188
SOAP::NetHttpClient::NO_PROXY_HOSTS.replace(backup)
194
@client.wiredump_dev = str
195
@client.options["protocol.http.charset"] = "iso-8859-8"
196
assert_nil(@client.do_server_proc)
197
r, h = parse_req_header(str)
198
assert_equal("text/xml; charset=iso-8859-8", h["content-type"])
201
@client.options["protocol.http.charset"] = "iso-8859-3"
202
assert_nil(@client.do_server_proc)
203
r, h = parse_req_header(str)
204
assert_equal("text/xml; charset=iso-8859-3", h["content-type"])