| Class | SOAP::RPC::Proxy |
| In: |
lib/soap/rpc/proxy.rb
|
| Parent: | Object |
| allow_unqualified_element | [RW] | |
| default_encodingstyle | [RW] | |
| generate_explicit_type | [RW] | |
| headerhandler | [R] | |
| literal_mapping_registry | [RW] | |
| mandatorycharset | [RW] | |
| mapping_registry | [RW] | |
| operation | [R] | |
| soapaction | [RW] | |
| streamhandler | [R] |
# File lib/soap/rpc/proxy.rb, line 40
40: def initialize(endpoint_url, soapaction, options)
41: @endpoint_url = endpoint_url
42: @soapaction = soapaction
43: @options = options
44: @streamhandler = HTTPStreamHandler.new(
45: @options["protocol.http"] ||= ::SOAP::Property.new)
46: @operation = {}
47: @mandatorycharset = nil
48: @allow_unqualified_element = true
49: @default_encodingstyle = nil
50: @generate_explicit_type = true
51: @headerhandler = Header::HandlerSet.new
52: @mapping_registry = nil
53: @literal_mapping_registry = ::SOAP::Mapping::WSDLLiteralRegistry.new
54: end
# File lib/soap/rpc/proxy.rb, line 90
90: def add_document_operation(soapaction, name, param_def, opt = {})
91: opt[:request_style] ||= :document
92: opt[:response_style] ||= :document
93: opt[:request_use] ||= :literal
94: opt[:response_use] ||= :literal
95: # default values of these values are unqualified in XML Schema.
96: # set true for backward compatibility.
97: unless opt.key?(:elementformdefault)
98: opt[:elementformdefault] = true
99: end
100: unless opt.key?(:attributeformdefault)
101: opt[:attributeformdefault] = true
102: end
103: @operation[name] = Operation.new(soapaction, param_def, opt)
104: end
# File lib/soap/rpc/proxy.rb, line 81
81: def add_rpc_operation(qname, soapaction, name, param_def, opt = {})
82: opt[:request_qname] = qname
83: opt[:request_style] ||= :rpc
84: opt[:response_style] ||= :rpc
85: opt[:request_use] ||= :encoded
86: opt[:response_use] ||= :encoded
87: @operation[name] = Operation.new(soapaction, param_def, opt)
88: end
# File lib/soap/rpc/proxy.rb, line 116
116: def call(name, *params)
117: unless op_info = @operation[name]
118: raise MethodDefinitionError, "method: #{name} not defined"
119: end
120: mapping_opt = create_mapping_opt
121: req_header = create_request_header
122: req_body = SOAPBody.new(
123: op_info.request_body(params, @mapping_registry,
124: @literal_mapping_registry, mapping_opt)
125: )
126: reqopt = create_encoding_opt(
127: :soapaction => op_info.soapaction || @soapaction,
128: :envelopenamespace => @options["soap.envelope.requestnamespace"],
129: :default_encodingstyle =>
130: @default_encodingstyle || op_info.request_default_encodingstyle,
131: :elementformdefault => op_info.elementformdefault,
132: :attributeformdefault => op_info.attributeformdefault
133: )
134: resopt = create_encoding_opt(
135: :envelopenamespace => @options["soap.envelope.responsenamespace"],
136: :default_encodingstyle =>
137: @default_encodingstyle || op_info.response_default_encodingstyle,
138: :elementformdefault => op_info.elementformdefault,
139: :attributeformdefault => op_info.attributeformdefault
140: )
141: env = route(req_header, req_body, reqopt, resopt)
142: raise EmptyResponseError unless env
143: receive_headers(env.header)
144: begin
145: check_fault(env.body)
146: rescue ::SOAP::FaultError => e
147: op_info.raise_fault(e, @mapping_registry, @literal_mapping_registry)
148: end
149: op_info.response_obj(env.body, @mapping_registry,
150: @literal_mapping_registry, mapping_opt)
151: end
# File lib/soap/rpc/proxy.rb, line 178
178: def check_fault(body)
179: if body.fault
180: raise SOAP::FaultError.new(body.fault)
181: end
182: end
# File lib/soap/rpc/proxy.rb, line 64
64: def endpoint_url=(endpoint_url)
65: @endpoint_url = endpoint_url
66: reset_stream
67: end
# File lib/soap/rpc/proxy.rb, line 56
56: def inspect
57: "#<#{self.class}:#{@endpoint_url}>"
58: end
# File lib/soap/rpc/proxy.rb, line 111
111: def invoke(req_header, req_body, opt = nil)
112: opt ||= create_encoding_opt
113: route(req_header, req_body, opt, opt)
114: end
# File lib/soap/rpc/proxy.rb, line 69
69: def reset_stream
70: @streamhandler.reset(@endpoint_url)
71: end
# File lib/soap/rpc/proxy.rb, line 153
153: def route(req_header, req_body, reqopt, resopt)
154: req_env = ::SOAP::SOAPEnvelope.new(req_header, req_body)
155: unless reqopt[:envelopenamespace].nil?
156: set_envelopenamespace(req_env, reqopt[:envelopenamespace])
157: end
158: reqopt[:external_content] = nil
159: conn_data = marshal(req_env, reqopt)
160: if ext = reqopt[:external_content]
161: mime = MIMEMessage.new
162: ext.each do |k, v|
163: mime.add_attachment(v.data)
164: end
165: mime.add_part(conn_data.send_string + "\r\n")
166: mime.close
167: conn_data.send_string = mime.content_str
168: conn_data.send_contenttype = mime.headers['content-type'].str
169: end
170: conn_data = @streamhandler.send(@endpoint_url, conn_data,
171: reqopt[:soapaction])
172: if conn_data.receive_string.empty?
173: return nil
174: end
175: unmarshal(conn_data, resopt)
176: end
# File lib/soap/rpc/proxy.rb, line 73
73: def set_wiredump_file_base(wiredump_file_base)
74: @streamhandler.wiredump_file_base = wiredump_file_base
75: end
# File lib/soap/rpc/proxy.rb, line 77
77: def test_loopback_response
78: @streamhandler.test_loopback_response
79: end
# File lib/soap/rpc/proxy.rb, line 253
253: def create_encoding_opt(hash = nil)
254: opt = {}
255: opt[:default_encodingstyle] = @default_encodingstyle
256: opt[:allow_unqualified_element] = @allow_unqualified_element
257: opt[:generate_explicit_type] = @generate_explicit_type
258: opt[:no_indent] = @options["soap.envelope.no_indent"]
259: opt[:use_numeric_character_reference] =
260: @options["soap.envelope.use_numeric_character_reference"]
261: opt.update(hash) if hash
262: opt
263: end
# File lib/soap/rpc/proxy.rb, line 245
245: def create_header(headers)
246: header = SOAPHeader.new()
247: headers.each do |content, mustunderstand, encodingstyle|
248: header.add(SOAPHeaderItem.new(content, mustunderstand, encodingstyle))
249: end
250: header
251: end
# File lib/soap/rpc/proxy.rb, line 265
265: def create_mapping_opt(hash = nil)
266: opt = {
267: :external_ces => @options["soap.mapping.external_ces"]
268: }
269: opt.update(hash) if hash
270: opt
271: end
# File lib/soap/rpc/proxy.rb, line 196
196: def create_request_header
197: headers = @headerhandler.on_outbound
198: if headers.empty?
199: nil
200: else
201: h = ::SOAP::SOAPHeader.new
202: headers.each do |header|
203: h.add(header.elename.name, header)
204: end
205: h
206: end
207: end
# File lib/soap/rpc/proxy.rb, line 213
213: def marshal(env, opt)
214: send_string = Processor.marshal(env, opt)
215: StreamHandler::ConnectionData.new(send_string)
216: end
# File lib/soap/rpc/proxy.rb, line 209
209: def receive_headers(headers)
210: @headerhandler.on_inbound(headers) if headers
211: end
# File lib/soap/rpc/proxy.rb, line 186
186: def set_envelopenamespace(env, namespace)
187: env.elename = XSD::QName.new(namespace, env.elename.name)
188: if env.header
189: env.header.elename = XSD::QName.new(namespace, env.header.elename.name)
190: end
191: if env.body
192: env.body.elename = XSD::QName.new(namespace, env.body.elename.name)
193: end
194: end
# File lib/soap/rpc/proxy.rb, line 218
218: def unmarshal(conn_data, opt)
219: contenttype = conn_data.receive_contenttype
220: if /#{MIMEMessage::MultipartContentType}/i =~ contenttype
221: opt[:external_content] = {}
222: mime = MIMEMessage.parse("Content-Type: " + contenttype,
223: conn_data.receive_string)
224: mime.parts.each do |part|
225: value = Attachment.new(part.content)
226: value.contentid = part.contentid
227: obj = SOAPAttachment.new(value)
228: opt[:external_content][value.contentid] = obj if value.contentid
229: end
230: opt[:charset] = @mandatorycharset ||
231: StreamHandler.parse_media_type(mime.root.headers['content-type'].str)
232: env = Processor.unmarshal(mime.root.content, opt)
233: else
234: opt[:charset] = @mandatorycharset ||
235: ::SOAP::StreamHandler.parse_media_type(contenttype)
236: env = Processor.unmarshal(conn_data.receive_string, opt)
237: end
238: unless env.is_a?(::SOAP::SOAPEnvelope)
239: raise ResponseFormatError.new(
240: "response is not a SOAP envelope: #{conn_data.receive_string}")
241: end
242: env
243: end