1
# SOAP4R - SOAP RPC driver
2
# Copyright (C) 2000, 2001, 2003-2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5
# redistribute it and/or modify it under the same terms of Ruby's license;
6
# either the dual license version in 2003, or any later version.
10
require 'soap/mapping'
11
require 'soap/mapping/wsdlliteralregistry'
12
require 'soap/rpc/rpc'
13
require 'soap/rpc/proxy'
14
require 'soap/rpc/element'
15
require 'soap/streamHandler'
16
require 'soap/property'
17
require 'soap/header/handlerset'
26
if RUBY_VERSION >= "1.7.0"
27
def __attr_proxy(symbol, assignable = false)
34
define_method(aname) { |rhs|
35
@proxy.__send__(aname, rhs)
40
def __attr_proxy(symbol, assignable = false)
50
@proxy.#{name} = value
58
__attr_proxy :endpoint_url, true
59
__attr_proxy :mapping_registry, true
60
__attr_proxy :default_encodingstyle, true
61
__attr_proxy :generate_explicit_type, true
62
__attr_proxy :allow_unqualified_element, true
63
__attr_proxy :headerhandler
64
__attr_proxy :streamhandler
65
__attr_proxy :test_loopback_response
66
__attr_proxy :reset_stream
70
attr_accessor :soapaction
73
"#<#{self.class}:#{@proxy.inspect}>"
77
options["protocol.http.proxy"]
80
def httpproxy=(httpproxy)
81
options["protocol.http.proxy"] = httpproxy
85
options["protocol.http.wiredump_dev"]
88
def wiredump_dev=(wiredump_dev)
89
options["protocol.http.wiredump_dev"] = wiredump_dev
93
options["protocol.mandatorycharset"]
96
def mandatorycharset=(mandatorycharset)
97
options["protocol.mandatorycharset"] = mandatorycharset
100
def wiredump_file_base
101
options["protocol.wiredump_file_base"]
104
def wiredump_file_base=(wiredump_file_base)
105
options["protocol.wiredump_file_base"] = wiredump_file_base
108
def initialize(endpoint_url, namespace = nil, soapaction = nil)
109
@namespace = namespace
110
@soapaction = soapaction
111
@options = setup_options
112
@wiredump_file_base = nil
113
@proxy = Proxy.new(endpoint_url, @soapaction, @options)
116
def loadproperty(propertyname)
117
unless options.loadproperty(propertyname)
118
raise LoadError.new("No such property to load -- #{propertyname}")
122
def add_rpc_method(name, *params)
123
add_rpc_method_with_soapaction_as(name, name, @soapaction, *params)
126
def add_rpc_method_as(name, name_as, *params)
127
add_rpc_method_with_soapaction_as(name, name_as, @soapaction, *params)
130
def add_rpc_method_with_soapaction(name, soapaction, *params)
131
add_rpc_method_with_soapaction_as(name, name, soapaction, *params)
134
def add_rpc_method_with_soapaction_as(name, name_as, soapaction, *params)
135
param_def = SOAPMethod.create_rpc_param_def(params)
136
qname = XSD::QName.new(@namespace, name_as)
137
@proxy.add_rpc_method(qname, soapaction, name, param_def)
138
add_rpc_method_interface(name, param_def)
141
# add_method is for shortcut of typical rpc/encoded method definition.
142
alias add_method add_rpc_method
143
alias add_method_as add_rpc_method_as
144
alias add_method_with_soapaction add_rpc_method_with_soapaction
145
alias add_method_with_soapaction_as add_rpc_method_with_soapaction_as
147
def add_document_method(name, soapaction, req_qname, res_qname)
148
param_def = SOAPMethod.create_doc_param_def(req_qname, res_qname)
149
@proxy.add_document_method(soapaction, name, param_def)
150
add_document_method_interface(name, param_def)
153
def add_rpc_operation(qname, soapaction, name, param_def, opt = {})
154
@proxy.add_rpc_operation(qname, soapaction, name, param_def, opt)
155
add_rpc_method_interface(name, param_def)
158
def add_document_operation(soapaction, name, param_def, opt = {})
159
@proxy.add_document_operation(soapaction, name, param_def, opt)
160
add_document_method_interface(name, param_def)
163
def invoke(headers, body)
164
if headers and !headers.is_a?(SOAPHeader)
165
headers = create_header(headers)
167
set_wiredump_file_base(body.elename.name)
168
env = @proxy.invoke(headers, body)
172
return env.header, env.body
176
def call(name, *params)
177
set_wiredump_file_base(name)
178
@proxy.call(name, *params)
183
def set_wiredump_file_base(name)
184
if @wiredump_file_base
185
@proxy.set_wiredump_file_base("#{@wiredump_file_base}_#{name}")
189
def create_header(headers)
190
header = SOAPHeader.new()
191
headers.each do |content, mustunderstand, encodingstyle|
192
header.add(SOAPHeaderItem.new(content, mustunderstand, encodingstyle))
198
if opt = Property.loadproperty(::SOAP::PropertyName)
202
opt.add_hook("protocol.mandatorycharset") do |key, value|
203
@proxy.mandatorycharset = value
205
opt.add_hook("protocol.wiredump_file_base") do |key, value|
206
@wiredump_file_base = value
208
opt["protocol.http.charset"] ||= XSD::Charset.xml_encoding_label
209
opt["protocol.http.proxy"] ||= Env::HTTP_PROXY
210
opt["protocol.http.no_proxy"] ||= Env::NO_PROXY
214
def add_rpc_method_interface(name, param_def)
215
param_count = RPC::SOAPMethod.param_count(param_def,
216
RPC::SOAPMethod::IN, RPC::SOAPMethod::INOUT)
217
add_method_interface(name, param_count)
220
def add_document_method_interface(name, param_def)
221
param_count = RPC::SOAPMethod.param_count(param_def, RPC::SOAPMethod::IN)
222
add_method_interface(name, param_count)
225
if RUBY_VERSION > "1.7.0"
226
def add_method_interface(name, param_count)
227
::SOAP::Mapping.define_singleton_method(self, name) do |*arg|
228
unless arg.size == param_count
229
raise ArgumentError.new(
230
"wrong number of arguments (#{arg.size} for #{param_count})")
237
def add_method_interface(name, param_count)
240
unless arg.size == #{param_count}
241
raise ArgumentError.new(
242
"wrong number of arguments (\#{arg.size} for #{param_count})")
244
call(#{name.dump}, *arg)