summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-21 15:08:56 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-21 15:08:56 +0000
commit3edeb852fe27ae9d11596697ea74f9b583f69e8a (patch)
treeec583bf4781cefd0a19735386b456046b8993d70 /sample
parent3a664c4b407c9273b90eaca48da83b8719eb5b1b (diff)
* lib/soap/*, test/soap/*, sample/soap/authheader/*: eval cleanup.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
-rw-r--r--sample/soap/authheader/client2.rb15
-rw-r--r--sample/soap/authheader/server.rb1
-rw-r--r--sample/soap/authheader/server2.rb22
3 files changed, 24 insertions, 14 deletions
diff --git a/sample/soap/authheader/client2.rb b/sample/soap/authheader/client2.rb
index 58a7da4..aa5172a 100644
--- a/sample/soap/authheader/client2.rb
+++ b/sample/soap/authheader/client2.rb
@@ -6,18 +6,16 @@ server = ARGV.shift || 'http://localhost:7000/'
class ClientAuthHeaderHandler < SOAP::Header::SimpleHandler
MyHeaderName = XSD::QName.new("http://tempuri.org/authHeader", "auth")
- def initialize(userid, passwd)
+ attr_accessor :sessionid
+
+ def initialize
super(MyHeaderName)
@sessionid = nil
- @userid = userid
- @passwd = passwd
end
def on_simple_outbound
if @sessionid
{ "sessionid" => @sessionid }
- else
- { "userid" => @userid, "passwd" => @passwd }
end
end
@@ -28,12 +26,17 @@ end
ns = 'http://tempuri.org/authHeaderPort'
serv = SOAP::RPC::Driver.new(server, ns)
+serv.add_method('login', 'userid', 'passwd')
serv.add_method('deposit', 'amt')
serv.add_method('withdrawal', 'amt')
-serv.headerhandler << ClientAuthHeaderHandler.new('NaHi', 'passwd')
+h = ClientAuthHeaderHandler.new
+
+serv.headerhandler << h
serv.wiredump_dev = STDOUT
+sessionid = serv.login('NaHi', 'passwd')
+h.sessionid = sessionid
p serv.deposit(150)
p serv.withdrawal(120)
diff --git a/sample/soap/authheader/server.rb b/sample/soap/authheader/server.rb
index 6b562d0..9c6adf2 100644
--- a/sample/soap/authheader/server.rb
+++ b/sample/soap/authheader/server.rb
@@ -23,6 +23,7 @@ class AuthHeaderPortServer < SOAP::RPC::StandaloneServer
def initialize(*arg)
super
add_rpc_servant(AuthHeaderService.new, Name)
+ # header handler must be a per request handler.
add_rpc_request_headerhandler(ServerAuthHeaderHandler)
end
diff --git a/sample/soap/authheader/server2.rb b/sample/soap/authheader/server2.rb
index b0065e3..8a0eaaf 100644
--- a/sample/soap/authheader/server2.rb
+++ b/sample/soap/authheader/server2.rb
@@ -6,10 +6,6 @@ require 'authmgr'
class AuthHeaderPortServer < SOAP::RPC::StandaloneServer
class AuthHeaderService
- def self.create
- new
- end
-
def initialize(authmgr)
@authmgr = authmgr
end
@@ -34,14 +30,20 @@ class AuthHeaderPortServer < SOAP::RPC::StandaloneServer
Name = 'http://tempuri.org/authHeaderPort'
def initialize(*arg)
super
- add_rpc_servant(AuthHeaderService.new, Name)
- ServerAuthHeaderHandler.init
+ authmgr = Authmgr.new
+ add_rpc_servant(AuthHeaderService.new(authmgr), Name)
+ ServerAuthHeaderHandler.init(authmgr)
+ # header handler must be a per request handler.
add_rpc_request_headerhandler(ServerAuthHeaderHandler)
end
class ServerAuthHeaderHandler < SOAP::Header::SimpleHandler
MyHeaderName = XSD::QName.new("http://tempuri.org/authHeader", "auth")
+ def self.init(authmgr)
+ @authmgr = authmgr
+ end
+
def self.create
new(@authmgr)
end
@@ -63,7 +65,7 @@ class AuthHeaderPortServer < SOAP::RPC::StandaloneServer
if sessionid = my_header["sessionid"]
if userid = @authmgr.auth(sessionid)
@authmgr.destroy_session(sessionid)
- @session_id = @authmgr.create_session(userid)
+ @sessionid = @authmgr.create_session(userid)
auth = true
end
end
@@ -73,5 +75,9 @@ class AuthHeaderPortServer < SOAP::RPC::StandaloneServer
end
if $0 == __FILE__
- status = AuthHeaderPortServer.new('AuthHeaderPortServer', nil, '0.0.0.0', 7000).start
+ svr = AuthHeaderPortServer.new('AuthHeaderPortServer', nil, '0.0.0.0', 7000)
+ trap(:INT) do
+ svr.shutdown
+ end
+ status = svr.start
end