Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/branches/1_5/sample/howto/filter/client.rb

Revision 1848, 0.9 kB (checked in by nahi, 2 years ago)
  • forgot to add.
Line 
1 require 'soap/rpc/driver'
2
3
4 class ClientFilter1 < SOAP::Filter::Handler
5   # 1 -> 2
6   def on_outbound(envelope, opt)
7     param = envelope.body.root_node.inparam
8     param["amt"] = SOAP::SOAPInt.new(param["amt"].data + 1)
9     param["amt"].elename = XSD::QName.new(nil, 'amt')
10     envelope
11   end
12
13   # 31 -> 32
14   def on_inbound(xml, opt)
15     xml = xml.sub(/31/, '32')
16     xml
17   end
18 end
19
20 class ClientFilter2 < SOAP::Filter::Handler
21   # 2 -> 4
22   def on_outbound(envelope, opt)
23     param = envelope.body.root_node.inparam
24     param["amt"] = SOAP::SOAPInt.new(param["amt"].data * 2)
25     param["amt"].elename = XSD::QName.new(nil, 'amt')
26     envelope
27   end
28
29   # 30 -> 31
30   def on_inbound(xml, opt)
31     xml = xml.sub(/30/, '31')
32     xml
33   end
34 end
35
36
37 client = SOAP::RPC::Driver.new("http://localhost:7171", "urn:filter")
38 client.add_method('echo', 'amt')
39 client.filterchain << ClientFilter1.new
40 client.filterchain << ClientFilter2.new
41
42 p client.echo(1)
Note: See TracBrowser for help on using the browser.