Sha256: 5e8e5e9c1acc74bbc9032bc1c5c1daffc0a6d72f35f8246edf18ef040f52462d

Contents?: true

Size: 1.45 KB

Versions: 5

Compression:

Stored size: 1.45 KB

Contents

# encoding: ASCII-8BIT
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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
soap5r-2.0.3 sample/payload/cookies/filterclient.rb
soap5r-2.0.2 sample/payload/cookies/filterclient.rb
soap5r-2.0.1 sample/payload/cookies/filterclient.rb
soap5r-2.0.0 sample/payload/cookies/filterclient.rb
soap5r-2.0.0.20120130130121 sample/payload/cookies/filterclient.rb