File: filterclient.rb

package info (click to toggle)
ruby-soap4r 2.0.5-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,032 kB
  • sloc: ruby: 52,729; xml: 266; sh: 42; javascript: 20; makefile: 13; perl: 10
file content (52 lines) | stat: -rw-r--r-- 1,459 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'soap/rpc/driver'
require 'soap/filter/streamhandler'

server = ARGV.shift || 'http://localhost:7000/'

class CookieFilter < SOAP::Filter::StreamHandler
  attr_accessor :cookie_value

  def initialize
    @cookie_value = nil
  end

  def on_http_outbound(req)
    req.header['Cookie'] = @cookie_value if @cookie_value
  end

  def on_http_inbound(req, res)
    # this sample filter only caputures the first cookie.
    cookie = res.header['Set-Cookie'][0]
    cookie.sub!(/;.*\z/, '') if cookie
    @cookie_value = cookie
    # do not save cookie value.
    puts "new cookie value: #{@cookie_value}"
  end
end

var = SOAP::RPC::Driver.new( server, 'http://tempuri.org/calcService' )
var.add_method( 'set', 'newValue' )
var.add_method( 'get' )
var.add_method_as( '+', 'add', 'rhs' )
var.add_method_as( '-', 'sub', 'rhs' )
var.add_method_as( '*', 'multi', 'rhs' )
var.add_method_as( '/', 'div', 'rhs' )
var.streamhandler.filterchain << CookieFilter.new
var.wiredump_dev = STDOUT if $DEBUG

puts 'var.set( 1 )'
puts '# Bare in mind that another client set another value to this service.'
puts '# This is only a sample for proof of concept.'
var.set( 1 )
puts 'var + 2	# => 1 + 2 = 3'
puts var + 2
puts 'var - 2.2	# => 1 - 2.2 = -1.2'
puts var - 2.2
puts 'var * 2.2	# => 1 * 2.2 = 2.2'
puts var * 2.2
puts 'var / 2	# => 1 / 2 = 0'
puts var / 2
puts 'var / 2.0	# => 1 / 2.0 = 0.5'
puts var / 2.0
puts 'var / 0	# => 1 / 0 => ZeroDivisionError'
puts var / 0