soap4r 1.5.6 → 1.5.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/wsdl2ruby.rb +1 -1
- data/bin/xsd2ruby.rb +12 -4
- data/lib/soap/baseData.rb +3 -1
- data/lib/soap/encodingstyle/literalHandler.rb +3 -2
- data/lib/soap/encodingstyle/soapHandler.rb +7 -4
- data/lib/soap/filter.rb +4 -1
- data/lib/soap/filter/filterchain.rb +1 -1
- data/lib/soap/filter/streamhandler.rb +29 -0
- data/lib/soap/generator.rb +6 -0
- data/lib/soap/httpconfigloader.rb +21 -6
- data/lib/soap/mapping/encodedregistry.rb +2 -1
- data/lib/soap/mapping/literalregistry.rb +31 -16
- data/lib/soap/mapping/registry.rb +5 -1
- data/lib/soap/mapping/rubytypeFactory.rb +3 -0
- data/lib/soap/mapping/wsdlliteralregistry.rb +3 -3
- data/lib/soap/netHttpClient.rb +6 -0
- data/lib/soap/rpc/router.rb +26 -17
- data/lib/soap/soap.rb +4 -4
- data/lib/soap/streamHandler.rb +61 -26
- data/lib/wsdl/soap/classDefCreator.rb +4 -2
- data/lib/wsdl/soap/literalMappingRegistryCreator.rb +7 -2
- data/lib/wsdl/soap/mappingRegistryCreator.rb +0 -2
- data/lib/wsdl/soap/mappingRegistryCreatorSupport.rb +2 -0
- data/lib/wsdl/soap/methodDefCreator.rb +6 -3
- data/lib/wsdl/xmlSchema/element.rb +4 -0
- data/lib/wsdl/xmlSchema/importer.rb +21 -9
- data/lib/wsdl/xmlSchema/xsd2ruby.rb +56 -3
- data/lib/xsd/mapping.rb +30 -13
- data/test/interopR2/client.log +5 -0
- data/test/interopR2/client.rb +9 -3
- data/test/interopR2/server.rb +1 -0
- data/test/soap/asp.net/test_aspdotnet.rb +1 -1
- data/test/soap/auth/htdigest +2 -0
- data/test/soap/auth/htpasswd +2 -0
- data/test/soap/auth/test_basic.rb +116 -0
- data/test/soap/auth/test_digest.rb +117 -0
- data/test/soap/htpasswd +2 -0
- data/test/soap/ssl/README +1 -1
- data/test/soap/ssl/test_ssl.rb +9 -9
- data/test/soap/test_cookie.rb +112 -0
- data/test/soap/test_custom_ns.rb +63 -0
- data/test/soap/test_httpconfigloader.rb +20 -5
- data/test/soap/test_mapping.rb +62 -0
- data/test/soap/test_nil.rb +55 -0
- data/test/soap/test_no_indent.rb +1 -1
- data/test/soap/test_streamhandler.rb +26 -14
- data/test/wsdl/datetime/datetimeServant.rb +1 -0
- data/test/wsdl/datetime/test_datetime.rb +4 -0
- data/test/wsdl/document/array/double.wsdl +50 -0
- data/test/wsdl/document/array/test_array.rb +34 -7
- data/test/wsdl/qualified/test_qualified.rb +1 -1
- data/test/wsdl/qualified/test_unqualified.rb +2 -16
- data/test/wsdl/rpc/test_rpc.rb +3 -0
- data/test/wsdl/rpc/test_rpc_lit.rb +1 -1
- data/test/wsdl/simpletype/rpc/expectedMappingRegistry.rb +2 -2
- data/test/wsdl/soap/wsdl2ruby/expectedMappingRegistry.rb +2 -2
- data/test/wsdl/soap/wsdl2ruby/section/test_section.rb +1 -1
- data/test/xsd/xsd2ruby/expected_mysample.rb +54 -0
- data/test/xsd/xsd2ruby/expected_mysample_mapper.rb +11 -0
- data/test/xsd/xsd2ruby/expected_mysample_mapping_registry.rb +57 -0
- data/test/xsd/xsd2ruby/section.xsd +41 -0
- data/test/xsd/xsd2ruby/test_xsd2ruby.rb +90 -0
- metadata +31 -12
- data/lib/soap/mapping/encodedregistry.rb~ +0 -531
- data/lib/tags +0 -5144
- data/lib/xsd/classloader.rb +0 -26
- data/test/interopR2/result_client.NetRemoting.txt +0 -0
- data/test/wsdl/rpc/test-rpc-lit-qualified.wsdl +0 -74
- data/test/wsdl/rpc/test-rpc-lit12.wsdl +0 -455
data/lib/xsd/mapping.rb
CHANGED
@@ -18,23 +18,40 @@ module XSD
|
|
18
18
|
|
19
19
|
module Mapping
|
20
20
|
MappingRegistry = SOAP::Mapping::LiteralRegistry.new
|
21
|
-
MappingOpt = {:default_encodingstyle => SOAP::LiteralNamespace}
|
22
21
|
|
23
22
|
def self.obj2xml(obj, elename = nil, io = nil)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
soap.elename = elename
|
30
|
-
generator = SOAP::SOAPGenerator.new(MappingOpt)
|
31
|
-
generator.generate(soap, io)
|
23
|
+
Mapper.new(MappingRegistry).obj2xml(obj, elename, io)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.xml2obj(stream, klass = nil)
|
27
|
+
Mapper.new(MappingRegistry).xml2obj(stream, klass)
|
32
28
|
end
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
class Mapper
|
31
|
+
MAPPING_OPT = {:default_encodingstyle => SOAP::LiteralNamespace}
|
32
|
+
|
33
|
+
def initialize(registry)
|
34
|
+
@registry = registry
|
35
|
+
end
|
36
|
+
|
37
|
+
def obj2xml(obj, elename = nil, io = nil)
|
38
|
+
if !elename.nil? and !elename.is_a?(XSD::QName)
|
39
|
+
elename = XSD::QName.new(nil, elename)
|
40
|
+
end
|
41
|
+
soap = SOAP::Mapping.obj2soap(obj, @registry, elename)
|
42
|
+
if soap.elename.nil? or soap.elename == XSD::QName::EMPTY
|
43
|
+
soap.elename =
|
44
|
+
XSD::QName.new(nil, SOAP::Mapping.name2elename(obj.class.to_s))
|
45
|
+
end
|
46
|
+
generator = SOAP::SOAPGenerator.new(MAPPING_OPT)
|
47
|
+
generator.generate(soap, io)
|
48
|
+
end
|
49
|
+
|
50
|
+
def xml2obj(stream, klass = nil)
|
51
|
+
parser = SOAP::Parser.new(MAPPING_OPT)
|
52
|
+
soap = parser.parse(stream)
|
53
|
+
SOAP::Mapping.soap2obj(soap, @registry, klass)
|
54
|
+
end
|
38
55
|
end
|
39
56
|
end
|
40
57
|
|
data/test/interopR2/client.rb
CHANGED
@@ -5,6 +5,7 @@ require 'soap/rpc/driver'
|
|
5
5
|
require 'soap/mapping'
|
6
6
|
require 'base'
|
7
7
|
require 'interopResultBase'
|
8
|
+
require 'xsd/xmlparser/rexmlparser'
|
8
9
|
#XSD::Charset.encoding = 'EUC'
|
9
10
|
|
10
11
|
class Float
|
@@ -100,7 +101,11 @@ class SOAPBuildersTest < Test::Unit::TestCase
|
|
100
101
|
soap_action = InterfaceNS
|
101
102
|
@@drv = RPC::Driver.new(location, namespace, soap_action)
|
102
103
|
@@drv.mapping_registry = SOAPBuildersInterop::MappingRegistry
|
103
|
-
|
104
|
+
if $DEBUG
|
105
|
+
@@drv.wiredump_dev = STDOUT
|
106
|
+
else
|
107
|
+
@@drv.wiredump_dev = @@log
|
108
|
+
end
|
104
109
|
method_def(@@drv, soap_action)
|
105
110
|
end
|
106
111
|
|
@@ -1222,7 +1227,8 @@ class SOAPBuildersTest < Test::Unit::TestCase
|
|
1222
1227
|
end
|
1223
1228
|
|
1224
1229
|
if $0 == __FILE__
|
1225
|
-
name = ARGV.shift || 'localhost'
|
1226
|
-
location = ARGV.shift || 'http://localhost:10080/'
|
1230
|
+
#name = ARGV.shift || 'localhost'
|
1231
|
+
#location = ARGV.shift || 'http://localhost:10080/'
|
1232
|
+
name = 'localhsot'; location = 'http://localhost:10080/'
|
1227
1233
|
SOAPBuildersTest.setup(name, location)
|
1228
1234
|
end
|
data/test/interopR2/server.rb
CHANGED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'soap/rpc/driver'
|
3
|
+
require 'webrick'
|
4
|
+
require 'webrick/httpproxy'
|
5
|
+
require 'logger'
|
6
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'testutil.rb')
|
7
|
+
|
8
|
+
|
9
|
+
module SOAP; module Auth
|
10
|
+
|
11
|
+
|
12
|
+
class TestBasic < Test::Unit::TestCase
|
13
|
+
Port = 17171
|
14
|
+
ProxyPort = 17172
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@logger = Logger.new(STDERR)
|
18
|
+
@logger.level = Logger::Severity::ERROR
|
19
|
+
@url = "http://localhost:#{Port}/"
|
20
|
+
@proxyurl = "http://localhost:#{ProxyPort}/"
|
21
|
+
@server = @proxyserver = @client = nil
|
22
|
+
@server_thread = @proxyserver_thread = nil
|
23
|
+
setup_server
|
24
|
+
setup_client
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
teardown_client
|
29
|
+
teardown_proxyserver if @proxyserver
|
30
|
+
teardown_server
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_server
|
34
|
+
@server = WEBrick::HTTPServer.new(
|
35
|
+
:BindAddress => "0.0.0.0",
|
36
|
+
:Logger => @logger,
|
37
|
+
:Port => Port,
|
38
|
+
:AccessLog => [],
|
39
|
+
:DocumentRoot => File.dirname(File.expand_path(__FILE__))
|
40
|
+
)
|
41
|
+
htpasswd = File.join(File.dirname(__FILE__), 'htpasswd')
|
42
|
+
htpasswd_userdb = WEBrick::HTTPAuth::Htpasswd.new(htpasswd)
|
43
|
+
@basic_auth = WEBrick::HTTPAuth::BasicAuth.new(
|
44
|
+
:Realm => 'auth',
|
45
|
+
:UserDB => htpasswd_userdb
|
46
|
+
)
|
47
|
+
@server.mount(
|
48
|
+
'/',
|
49
|
+
WEBrick::HTTPServlet::ProcHandler.new(method(:do_server_proc).to_proc)
|
50
|
+
)
|
51
|
+
@server_thread = TestUtil.start_server_thread(@server)
|
52
|
+
end
|
53
|
+
|
54
|
+
def setup_proxyserver
|
55
|
+
@proxyserver = WEBrick::HTTPProxyServer.new(
|
56
|
+
:BindAddress => "0.0.0.0",
|
57
|
+
:Logger => @logger,
|
58
|
+
:Port => ProxyPort,
|
59
|
+
:AccessLog => []
|
60
|
+
)
|
61
|
+
@proxyserver_thread = TestUtil.start_server_thread(@proxyserver)
|
62
|
+
end
|
63
|
+
|
64
|
+
def setup_client
|
65
|
+
@client = SOAP::RPC::Driver.new(@url, '')
|
66
|
+
@client.add_method("do_server_proc")
|
67
|
+
end
|
68
|
+
|
69
|
+
def teardown_server
|
70
|
+
@server.shutdown
|
71
|
+
@server_thread.kill
|
72
|
+
@server_thread.join
|
73
|
+
end
|
74
|
+
|
75
|
+
def teardown_proxyserver
|
76
|
+
@proxyserver.shutdown
|
77
|
+
@proxyserver_thread.kill
|
78
|
+
@proxyserver_thread.join
|
79
|
+
end
|
80
|
+
|
81
|
+
def teardown_client
|
82
|
+
@client.reset_stream
|
83
|
+
end
|
84
|
+
|
85
|
+
def do_server_proc(req, res)
|
86
|
+
@basic_auth.authenticate(req, res)
|
87
|
+
res['content-type'] = 'text/xml'
|
88
|
+
res.body = <<__EOX__
|
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">
|
91
|
+
<env:Body>
|
92
|
+
<n1:do_server_proc xmlns:n1="urn:foo" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
93
|
+
<return>OK</return>
|
94
|
+
</n1:do_server_proc>
|
95
|
+
</env:Body>
|
96
|
+
</env:Envelope>
|
97
|
+
__EOX__
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_direct
|
101
|
+
@client.wiredump_dev = STDOUT if $DEBUG
|
102
|
+
@client.options["protocol.http.auth"] << [@url, "admin", "admin"]
|
103
|
+
assert_equal("OK", @client.do_server_proc)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_proxy
|
107
|
+
setup_proxyserver
|
108
|
+
@client.wiredump_dev = STDOUT if $DEBUG
|
109
|
+
@client.options["protocol.http.proxy"] = @proxyurl
|
110
|
+
@client.options["protocol.http.auth"] << [@url, "guest", "guest"]
|
111
|
+
assert_equal("OK", @client.do_server_proc)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
end; end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'soap/rpc/driver'
|
3
|
+
require 'webrick'
|
4
|
+
require 'webrick/httpproxy'
|
5
|
+
require 'logger'
|
6
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'testutil.rb')
|
7
|
+
|
8
|
+
|
9
|
+
module SOAP; module Auth
|
10
|
+
|
11
|
+
|
12
|
+
class TestDigest < Test::Unit::TestCase
|
13
|
+
Port = 17171
|
14
|
+
ProxyPort = 17172
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@logger = Logger.new(STDERR)
|
18
|
+
@logger.level = Logger::Severity::ERROR
|
19
|
+
@url = "http://localhost:#{Port}/"
|
20
|
+
@proxyurl = "http://localhost:#{ProxyPort}/"
|
21
|
+
@server = @proxyserver = @client = nil
|
22
|
+
@server_thread = @proxyserver_thread = nil
|
23
|
+
setup_server
|
24
|
+
setup_client
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
teardown_client
|
29
|
+
teardown_proxyserver if @proxyserver
|
30
|
+
teardown_server
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_server
|
34
|
+
@server = WEBrick::HTTPServer.new(
|
35
|
+
:BindAddress => "0.0.0.0",
|
36
|
+
:Logger => @logger,
|
37
|
+
:Port => Port,
|
38
|
+
:AccessLog => [],
|
39
|
+
:DocumentRoot => File.dirname(File.expand_path(__FILE__))
|
40
|
+
)
|
41
|
+
htdigest = File.join(File.dirname(__FILE__), 'htdigest')
|
42
|
+
htdigest_userdb = WEBrick::HTTPAuth::Htdigest.new(htdigest)
|
43
|
+
@digest_auth = WEBrick::HTTPAuth::DigestAuth.new(
|
44
|
+
:Algorithm => 'MD5',
|
45
|
+
:Realm => 'auth',
|
46
|
+
:UserDB => htdigest_userdb
|
47
|
+
)
|
48
|
+
@server.mount(
|
49
|
+
'/',
|
50
|
+
WEBrick::HTTPServlet::ProcHandler.new(method(:do_server_proc).to_proc)
|
51
|
+
)
|
52
|
+
@server_thread = TestUtil.start_server_thread(@server)
|
53
|
+
end
|
54
|
+
|
55
|
+
def setup_proxyserver
|
56
|
+
@proxyserver = WEBrick::HTTPProxyServer.new(
|
57
|
+
:BindAddress => "0.0.0.0",
|
58
|
+
:Logger => @logger,
|
59
|
+
:Port => ProxyPort,
|
60
|
+
:AccessLog => []
|
61
|
+
)
|
62
|
+
@proxyserver_thread = TestUtil.start_server_thread(@proxyserver)
|
63
|
+
end
|
64
|
+
|
65
|
+
def setup_client
|
66
|
+
@client = SOAP::RPC::Driver.new(@url, '')
|
67
|
+
@client.add_method("do_server_proc")
|
68
|
+
end
|
69
|
+
|
70
|
+
def teardown_server
|
71
|
+
@server.shutdown
|
72
|
+
@server_thread.kill
|
73
|
+
@server_thread.join
|
74
|
+
end
|
75
|
+
|
76
|
+
def teardown_proxyserver
|
77
|
+
@proxyserver.shutdown
|
78
|
+
@proxyserver_thread.kill
|
79
|
+
@proxyserver_thread.join
|
80
|
+
end
|
81
|
+
|
82
|
+
def teardown_client
|
83
|
+
@client.reset_stream
|
84
|
+
end
|
85
|
+
|
86
|
+
def do_server_proc(req, res)
|
87
|
+
@digest_auth.authenticate(req, res)
|
88
|
+
res['content-type'] = 'text/xml'
|
89
|
+
res.body = <<__EOX__
|
90
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
91
|
+
<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
|
+
<env:Body>
|
93
|
+
<n1:do_server_proc xmlns:n1="urn:foo" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
94
|
+
<return>OK</return>
|
95
|
+
</n1:do_server_proc>
|
96
|
+
</env:Body>
|
97
|
+
</env:Envelope>
|
98
|
+
__EOX__
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_direct
|
102
|
+
@client.wiredump_dev = STDOUT if $DEBUG
|
103
|
+
@client.options["protocol.http.auth"] << [@url, "admin", "admin"]
|
104
|
+
assert_equal("OK", @client.do_server_proc)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_proxy
|
108
|
+
setup_proxyserver
|
109
|
+
@client.wiredump_dev = STDOUT if $DEBUG
|
110
|
+
@client.options["protocol.http.proxy"] = @proxyurl
|
111
|
+
@client.options["protocol.http.auth"] << [@url, "guest", "guest"]
|
112
|
+
assert_equal("OK", @client.do_server_proc)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
end; end
|
data/test/soap/htpasswd
ADDED
data/test/soap/ssl/README
CHANGED
@@ -1 +1 @@
|
|
1
|
-
* certificates and keys in this directory is copied from
|
1
|
+
* certificates and keys in this directory is copied from httpclient test.
|
data/test/soap/ssl/test_ssl.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
begin
|
3
|
-
require '
|
3
|
+
require 'httpclient'
|
4
4
|
rescue LoadError
|
5
5
|
end
|
6
6
|
require 'soap/rpc/driver'
|
7
7
|
|
8
|
-
if defined?(
|
8
|
+
if defined?(HTTPClient) and defined?(OpenSSL)
|
9
9
|
|
10
10
|
module SOAP; module SSL
|
11
11
|
|
@@ -58,7 +58,7 @@ class TestSSL < Test::Unit::TestCase
|
|
58
58
|
@client.hello_world("ssl client")
|
59
59
|
assert(false)
|
60
60
|
rescue OpenSSL::SSL::SSLError => ssle
|
61
|
-
|
61
|
+
assert(/certificate verify failed/ =~ ssle.message)
|
62
62
|
assert(@verify_callback_called)
|
63
63
|
end
|
64
64
|
#
|
@@ -69,7 +69,7 @@ class TestSSL < Test::Unit::TestCase
|
|
69
69
|
@client.hello_world("ssl client")
|
70
70
|
assert(false)
|
71
71
|
rescue OpenSSL::SSL::SSLError => ssle
|
72
|
-
|
72
|
+
assert(/certificate verify failed/ =~ ssle.message)
|
73
73
|
assert(@verify_callback_called)
|
74
74
|
end
|
75
75
|
#
|
@@ -79,7 +79,7 @@ class TestSSL < Test::Unit::TestCase
|
|
79
79
|
@client.hello_world("ssl client")
|
80
80
|
assert(false)
|
81
81
|
rescue OpenSSL::SSL::SSLError => ssle
|
82
|
-
|
82
|
+
assert(/certificate verify failed/ =~ ssle.message)
|
83
83
|
assert(@verify_callback_called)
|
84
84
|
end
|
85
85
|
#
|
@@ -94,7 +94,7 @@ class TestSSL < Test::Unit::TestCase
|
|
94
94
|
@client.hello_world("ssl client")
|
95
95
|
assert(false)
|
96
96
|
rescue OpenSSL::SSL::SSLError => ssle
|
97
|
-
|
97
|
+
assert(/certificate verify failed/ =~ ssle.message)
|
98
98
|
assert(@verify_callback_called)
|
99
99
|
end
|
100
100
|
#
|
@@ -105,7 +105,7 @@ class TestSSL < Test::Unit::TestCase
|
|
105
105
|
@client.hello_world("ssl client")
|
106
106
|
assert(false)
|
107
107
|
rescue OpenSSL::SSL::SSLError => ssle
|
108
|
-
|
108
|
+
assert(/certificate verify failed/ =~ ssle.message)
|
109
109
|
end
|
110
110
|
#
|
111
111
|
cfg["protocol.http.ssl_config.verify_mode"] = ""
|
@@ -135,7 +135,7 @@ __EOP__
|
|
135
135
|
@client.hello_world("ssl client")
|
136
136
|
assert(false)
|
137
137
|
rescue OpenSSL::SSL::SSLError => ssle
|
138
|
-
|
138
|
+
assert(/certificate verify failed/ =~ ssle.message)
|
139
139
|
assert(@verify_callback_called)
|
140
140
|
end
|
141
141
|
# NG with Integer
|
@@ -144,7 +144,7 @@ __EOP__
|
|
144
144
|
@client.hello_world("ssl client")
|
145
145
|
assert(false)
|
146
146
|
rescue OpenSSL::SSL::SSLError => ssle
|
147
|
-
|
147
|
+
assert(/certificate verify failed/ =~ ssle.message)
|
148
148
|
assert(@verify_callback_called)
|
149
149
|
end
|
150
150
|
# OK with empty
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'soap/rpc/driver'
|
3
|
+
require 'webrick'
|
4
|
+
require 'logger'
|
5
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'testutil.rb')
|
6
|
+
|
7
|
+
|
8
|
+
module SOAP
|
9
|
+
|
10
|
+
|
11
|
+
class TestCookie < Test::Unit::TestCase
|
12
|
+
Port = 17171
|
13
|
+
|
14
|
+
class CookieFilter < SOAP::Filter::StreamHandler
|
15
|
+
attr_accessor :cookie_value
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@cookie_value = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def on_http_outbound(req)
|
22
|
+
if @cookie_value
|
23
|
+
req.header.delete('Cookie')
|
24
|
+
req.header['Cookie'] = @cookie_value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_http_inbound(req, res)
|
29
|
+
# this sample filter only caputures the first cookie.
|
30
|
+
cookie = res.header['Set-Cookie'][0]
|
31
|
+
cookie.sub!(/;.*\z/, '') if cookie
|
32
|
+
@cookie_value = cookie
|
33
|
+
# do not save cookie value.
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup
|
38
|
+
@logger = Logger.new(STDERR)
|
39
|
+
@logger.level = Logger::Severity::ERROR
|
40
|
+
@url = "http://localhost:#{Port}/"
|
41
|
+
@server = @client = nil
|
42
|
+
@server_thread = nil
|
43
|
+
setup_server
|
44
|
+
setup_client
|
45
|
+
end
|
46
|
+
|
47
|
+
def teardown
|
48
|
+
teardown_client
|
49
|
+
teardown_server
|
50
|
+
end
|
51
|
+
|
52
|
+
def setup_server
|
53
|
+
@server = WEBrick::HTTPServer.new(
|
54
|
+
:BindAddress => "0.0.0.0",
|
55
|
+
:Logger => @logger,
|
56
|
+
:Port => Port,
|
57
|
+
:AccessLog => [],
|
58
|
+
:DocumentRoot => File.dirname(File.expand_path(__FILE__))
|
59
|
+
)
|
60
|
+
@server.mount(
|
61
|
+
'/',
|
62
|
+
WEBrick::HTTPServlet::ProcHandler.new(method(:do_server_proc).to_proc)
|
63
|
+
)
|
64
|
+
@server_thread = TestUtil.start_server_thread(@server)
|
65
|
+
end
|
66
|
+
|
67
|
+
def setup_client
|
68
|
+
@client = SOAP::RPC::Driver.new(@url, '')
|
69
|
+
@client.add_method("do_server_proc")
|
70
|
+
end
|
71
|
+
|
72
|
+
def teardown_server
|
73
|
+
@server.shutdown
|
74
|
+
@server_thread.kill
|
75
|
+
@server_thread.join
|
76
|
+
end
|
77
|
+
|
78
|
+
def teardown_client
|
79
|
+
@client.reset_stream
|
80
|
+
end
|
81
|
+
|
82
|
+
def do_server_proc(req, res)
|
83
|
+
cookie = req['Cookie'].to_s
|
84
|
+
cookie = "var=hello world" if cookie.empty?
|
85
|
+
res['content-type'] = 'text/xml'
|
86
|
+
res['Set-Cookie'] = cookie
|
87
|
+
res.body = <<__EOX__
|
88
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
89
|
+
<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">
|
90
|
+
<env:Body>
|
91
|
+
<n1:do_server_proc xmlns:n1="urn:foo" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
92
|
+
<return xsi:nil="true"/>
|
93
|
+
</n1:do_server_proc>
|
94
|
+
</env:Body>
|
95
|
+
</env:Envelope>
|
96
|
+
__EOX__
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_normal
|
100
|
+
@client.wiredump_dev = STDOUT if $DEBUG
|
101
|
+
filter = CookieFilter.new
|
102
|
+
@client.streamhandler.filterchain << filter
|
103
|
+
assert_nil(@client.do_server_proc)
|
104
|
+
assert_equal('var=hello world', filter.cookie_value)
|
105
|
+
filter.cookie_value = 'var=empty'
|
106
|
+
assert_nil(@client.do_server_proc)
|
107
|
+
assert_equal('var=empty', filter.cookie_value)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
end
|