lib/soap/rpc/proxy.rb in soap4r-1.5.5.20061022 vs lib/soap/rpc/proxy.rb in soap4r-1.5.6

- old
+ new

@@ -1,7 +1,7 @@ # SOAP4R - RPC Proxy library. -# Copyright (C) 2000, 2003-2006 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. +# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. # This program is copyrighted free software by NAKAMURA, Hiroshi. You can # redistribute it and/or modify it under the same terms of Ruby's license; # either the dual license version in 2003, or any later version. @@ -10,10 +10,12 @@ require 'soap/processor' require 'soap/mapping' require 'soap/mapping/literalregistry' require 'soap/rpc/rpc' require 'soap/rpc/element' +require 'soap/header/handlerset' +require 'soap/filter' require 'soap/streamHandler' require 'soap/mimemessage' module SOAP @@ -30,10 +32,11 @@ attr_accessor :allow_unqualified_element attr_accessor :default_encodingstyle attr_accessor :generate_explicit_type attr_accessor :return_response_as_xml attr_reader :headerhandler + attr_reader :filterchain attr_reader :streamhandler attr_accessor :mapping_registry attr_accessor :literal_mapping_registry @@ -52,10 +55,11 @@ @allow_unqualified_element = true @default_encodingstyle = nil @generate_explicit_type = true @return_response_as_xml = false @headerhandler = Header::HandlerSet.new + @filterchain = Filter::FilterChain.new @mapping_registry = nil @literal_mapping_registry = ::SOAP::Mapping::LiteralRegistry.new end def inspect @@ -82,24 +86,18 @@ def test_loopback_response @streamhandler.test_loopback_response end def add_rpc_operation(qname, soapaction, name, param_def, opt = {}) + ensure_styleuse_option(opt, :rpc, :encoded) opt[:request_qname] = qname - opt[:request_style] ||= :rpc - opt[:response_style] ||= :rpc - opt[:request_use] ||= :encoded - opt[:response_use] ||= :encoded op = Operation.new(soapaction, param_def, opt) assign_operation(name, qname, soapaction, op) end def add_document_operation(soapaction, name, param_def, opt = {}) - opt[:request_style] ||= :document - opt[:response_style] ||= :document - opt[:request_use] ||= :literal - opt[:response_use] ||= :literal + ensure_styleuse_option(opt, :document, :literal) op = Operation.new(soapaction, param_def, opt) assign_operation(name, nil, soapaction, op) end # add_method is for shortcut of typical rpc/encoded method definition. @@ -140,10 +138,13 @@ @default_encodingstyle || op_info.response_default_encodingstyle, :elementformdefault => op_info.elementformdefault, :attributeformdefault => op_info.attributeformdefault ) env = route(req_header, req_body, reqopt, resopt) + if op_info.response_use.nil? + return nil + end raise EmptyResponseError unless env receive_headers(env.header) begin check_fault(env.body) rescue ::SOAP::FaultError => e @@ -188,10 +189,21 @@ end end private + def ensure_styleuse_option(opt, style, use) + if opt[:request_style] || opt[:response_style] || opt[:request_use] || opt[:response_use] + # do not edit + else + opt[:request_style] ||= style + opt[:response_style] ||= style + opt[:request_use] ||= use + opt[:response_use] ||= use + end + end + def initialize_streamhandler(options) value = options["streamhandler"] if value and !value.empty? factory = Property::Util.const_from_name(value) else @@ -221,33 +233,34 @@ env.body.elename = XSD::QName.new(namespace, env.body.elename.name) end end def create_request_header - headers = @headerhandler.on_outbound - if headers.empty? - nil - else - h = ::SOAP::SOAPHeader.new - headers.each do |header| - h.add(header.elename.name, header) - end - h + header = ::SOAP::SOAPHeader.new + items = @headerhandler.on_outbound(header) + items.each do |item| + header.add(item.elename.name, item) end + header end - def receive_headers(headers) - @headerhandler.on_inbound(headers) if headers + def receive_headers(header) + @headerhandler.on_inbound(header) if header end def marshal(env, opt) + @filterchain.each do |filter| + env = filter.on_outbound(env, opt) + break unless env + end send_string = Processor.marshal(env, opt) StreamHandler::ConnectionData.new(send_string) end def unmarshal(conn_data, opt) contenttype = conn_data.receive_contenttype + xml = nil if /#{MIMEMessage::MultipartContentType}/i =~ contenttype opt[:external_content] = {} mime = MIMEMessage.parse("Content-Type: " + contenttype, conn_data.receive_string) mime.parts.each do |part| @@ -256,22 +269,24 @@ obj = SOAPAttachment.new(value) opt[:external_content][value.contentid] = obj if value.contentid end opt[:charset] = @mandatorycharset || StreamHandler.parse_media_type(mime.root.headers['content-type'].str) - env = Processor.unmarshal(mime.root.content, opt) - if @return_response_as_xml - opt[:response_as_xml] = mime.root.content - end + xml = mime.root.content else opt[:charset] = @mandatorycharset || ::SOAP::StreamHandler.parse_media_type(contenttype) - env = Processor.unmarshal(conn_data.receive_string, opt) - if @return_response_as_xml - opt[:response_as_xml] = conn_data.receive_string - end + xml = conn_data.receive_string end + @filterchain.reverse_each do |filter| + xml = filter.on_inbound(xml, opt) + break unless xml + end + env = Processor.unmarshal(xml, opt) + if @return_response_as_xml + opt[:response_as_xml] = xml + end unless env.is_a?(::SOAP::SOAPEnvelope) raise ResponseFormatError.new("response is not a SOAP envelope: #{env}") end env end @@ -428,12 +443,13 @@ unless [:rpc, :document].include?(style) raise MethodDefinitionError.new("unknown style: #{style}") end end + # nil means oneway def check_use(use) - unless [:encoded, :literal].include?(use) + unless [:encoded, :literal, nil].include?(use) raise MethodDefinitionError.new("unknown use: #{use}") end end def request_rpc(values, mapping_registry, literal_mapping_registry, opt) @@ -453,12 +469,16 @@ end def request_rpc_enc(values, mapping_registry, opt) method = @rpc_method_factory.dup names = method.input_params - obj = create_request_obj(names, values) - soap = Mapping.obj2soap(obj, mapping_registry, @rpc_request_qname, opt) + types = method.input_param_types + ary = Mapping.objs2soap(values, mapping_registry, types, opt) + soap = {} + 0.upto(ary.length - 1) do |idx| + soap[names[idx]] = ary[idx] + end method.set_param(soap) method end def request_rpc_lit(values, mapping_registry, opt) @@ -542,19 +562,9 @@ def response_doc_lit(body, mapping_registry, opt) body.collect { |key, value| Mapping.soap2obj(value, mapping_registry) } - end - - def create_request_obj(names, params) - o = Object.new - idx = 0 - while idx < params.length - o.instance_variable_set('@' + names[idx], params[idx]) - idx += 1 - end - o end end end