class SOAP::RPC::Proxy

Attributes

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]

Public Class Methods

new(endpoint_url, soapaction, options) click to toggle source
# File lib/soap/rpc/proxy.rb, line 40
def initialize(endpoint_url, soapaction, options)
  @endpoint_url = endpoint_url
  @soapaction = soapaction
  @options = options
  @streamhandler = HTTPStreamHandler.new(
    @options["protocol.http"] ||= ::SOAP::Property.new)
  @operation = {}
  @mandatorycharset = nil
  @allow_unqualified_element = true
  @default_encodingstyle = nil
  @generate_explicit_type = true
  @headerhandler = Header::HandlerSet.new
  @mapping_registry = nil
  @literal_mapping_registry = ::SOAP::Mapping::WSDLLiteralRegistry.new
end

Public Instance Methods

add_document_method(soapaction, name, param_def, opt = {})
add_document_operation(soapaction, name, param_def, opt = {}) click to toggle source
# File lib/soap/rpc/proxy.rb, line 90
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
  # default values of these values are unqualified in XML Schema.
  # set true for backward compatibility.
  unless opt.key?(:elementformdefault)
    opt[:elementformdefault] = true
  end
  unless opt.key?(:attributeformdefault)
    opt[:attributeformdefault] = true
  end
  @operation[name] = Operation.new(soapaction, param_def, opt)
end
Also aliased as: add_document_method
add_method(qname, soapaction, name, param_def, opt = {})

add_method is for shortcut of typical rpc/encoded method definition.

Alias for: add_rpc_operation
add_rpc_method(qname, soapaction, name, param_def, opt = {})
Alias for: add_rpc_operation
add_rpc_operation(qname, soapaction, name, param_def, opt = {}) click to toggle source
# File lib/soap/rpc/proxy.rb, line 81
def add_rpc_operation(qname, soapaction, name, param_def, opt = {})
  opt[:request_qname] = qname
  opt[:request_style] ||= :rpc
  opt[:response_style] ||= :rpc
  opt[:request_use] ||= :encoded
  opt[:response_use] ||= :encoded
  @operation[name] = Operation.new(soapaction, param_def, opt)
end
Also aliased as: add_method, add_rpc_method
call(name, *params) click to toggle source
# File lib/soap/rpc/proxy.rb, line 116
def call(name, *params)
  unless op_info = @operation[name]
    raise MethodDefinitionError, "method: #{name} not defined"
  end
  mapping_opt = create_mapping_opt
  req_header = create_request_header
  req_body = SOAPBody.new(
    op_info.request_body(params, @mapping_registry,
      @literal_mapping_registry, mapping_opt)
  )
  reqopt = create_encoding_opt(
    :soapaction => op_info.soapaction || @soapaction,
    :envelopenamespace => @options["soap.envelope.requestnamespace"],
    :default_encodingstyle =>
      @default_encodingstyle || op_info.request_default_encodingstyle,
    :elementformdefault => op_info.elementformdefault,
    :attributeformdefault => op_info.attributeformdefault
  )
  resopt = create_encoding_opt(
    :envelopenamespace => @options["soap.envelope.responsenamespace"],
    :default_encodingstyle =>
      @default_encodingstyle || op_info.response_default_encodingstyle,
    :elementformdefault => op_info.elementformdefault,
    :attributeformdefault => op_info.attributeformdefault
  )
  env = route(req_header, req_body, reqopt, resopt)
  raise EmptyResponseError unless env
  receive_headers(env.header)
  begin
    check_fault(env.body)
  rescue ::SOAP::FaultError => e
    op_info.raise_fault(e, @mapping_registry, @literal_mapping_registry)
  end
  op_info.response_obj(env.body, @mapping_registry,
    @literal_mapping_registry, mapping_opt)
end
check_fault(body) click to toggle source
# File lib/soap/rpc/proxy.rb, line 178
def check_fault(body)
  if body.fault
    raise SOAP::FaultError.new(body.fault)
  end
end
endpoint_url() click to toggle source
# File lib/soap/rpc/proxy.rb, line 60
def endpoint_url
  @endpoint_url
end
endpoint_url=(endpoint_url) click to toggle source
# File lib/soap/rpc/proxy.rb, line 64
def endpoint_url=(endpoint_url)
  @endpoint_url = endpoint_url
  reset_stream
end
inspect() click to toggle source
# File lib/soap/rpc/proxy.rb, line 56
def inspect
  "#<#{self.class}:#{@endpoint_url}>"
end
invoke(req_header, req_body, opt = nil) click to toggle source
# File lib/soap/rpc/proxy.rb, line 111
def invoke(req_header, req_body, opt = nil)
  opt ||= create_encoding_opt
  route(req_header, req_body, opt, opt)
end
reset_stream() click to toggle source
# File lib/soap/rpc/proxy.rb, line 69
def reset_stream
  @streamhandler.reset(@endpoint_url)
end
route(req_header, req_body, reqopt, resopt) click to toggle source
# File lib/soap/rpc/proxy.rb, line 153
def route(req_header, req_body, reqopt, resopt)
  req_env = ::SOAP::SOAPEnvelope.new(req_header, req_body)
  unless reqopt[:envelopenamespace].nil?
    set_envelopenamespace(req_env, reqopt[:envelopenamespace])
  end
  reqopt[:external_content] = nil
  conn_data = marshal(req_env, reqopt)
  if ext = reqopt[:external_content]
    mime = MIMEMessage.new
    ext.each do |k, v|
      mime.add_attachment(v.data)
    end
    mime.add_part(conn_data.send_string + "\r\n")
    mime.close
    conn_data.send_string = mime.content_str
    conn_data.send_contenttype = mime.headers['content-type'].str
  end
  conn_data = @streamhandler.send(@endpoint_url, conn_data,
    reqopt[:soapaction])
  if conn_data.receive_string.empty?
    return nil
  end
  unmarshal(conn_data, resopt)
end
set_wiredump_file_base(wiredump_file_base) click to toggle source
# File lib/soap/rpc/proxy.rb, line 73
def set_wiredump_file_base(wiredump_file_base)
  @streamhandler.wiredump_file_base = wiredump_file_base
end
test_loopback_response() click to toggle source
# File lib/soap/rpc/proxy.rb, line 77
def test_loopback_response
  @streamhandler.test_loopback_response
end

Private Instance Methods

create_encoding_opt(hash = nil) click to toggle source
# File lib/soap/rpc/proxy.rb, line 253
def create_encoding_opt(hash = nil)
  opt = {}
  opt[:default_encodingstyle] = @default_encodingstyle
  opt[:allow_unqualified_element] = @allow_unqualified_element
  opt[:generate_explicit_type] = @generate_explicit_type
  opt[:no_indent] = @options["soap.envelope.no_indent"]
  opt[:use_numeric_character_reference] =
    @options["soap.envelope.use_numeric_character_reference"]
  opt.update(hash) if hash
  opt
end
create_header(headers) click to toggle source
# File lib/soap/rpc/proxy.rb, line 245
def create_header(headers)
  header = SOAPHeader.new()
  headers.each do |content, mustunderstand, encodingstyle|
    header.add(SOAPHeaderItem.new(content, mustunderstand, encodingstyle))
  end
  header
end
create_mapping_opt(hash = nil) click to toggle source
# File lib/soap/rpc/proxy.rb, line 265
def create_mapping_opt(hash = nil)
  opt = {
    :external_ces => @options["soap.mapping.external_ces"]
  }
  opt.update(hash) if hash
  opt
end
create_request_header() click to toggle source
# File lib/soap/rpc/proxy.rb, line 196
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
  end
end
marshal(env, opt) click to toggle source
# File lib/soap/rpc/proxy.rb, line 213
def marshal(env, opt)
  send_string = Processor.marshal(env, opt)
  StreamHandler::ConnectionData.new(send_string)
end
receive_headers(headers) click to toggle source
# File lib/soap/rpc/proxy.rb, line 209
def receive_headers(headers)
  @headerhandler.on_inbound(headers) if headers
end
set_envelopenamespace(env, namespace) click to toggle source
# File lib/soap/rpc/proxy.rb, line 186
def set_envelopenamespace(env, namespace)
  env.elename = XSD::QName.new(namespace, env.elename.name)
  if env.header
    env.header.elename = XSD::QName.new(namespace, env.header.elename.name)
  end
  if env.body
    env.body.elename = XSD::QName.new(namespace, env.body.elename.name)
  end
end
unmarshal(conn_data, opt) click to toggle source
# File lib/soap/rpc/proxy.rb, line 218
def unmarshal(conn_data, opt)
  contenttype = conn_data.receive_contenttype
  if /#{MIMEMessage::MultipartContentType}/i =~ contenttype
    opt[:external_content] = {}
    mime = MIMEMessage.parse("Content-Type: " + contenttype,
      conn_data.receive_string)
    mime.parts.each do |part|
      value = Attachment.new(part.content)
      value.contentid = part.contentid
      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)
  else
    opt[:charset] = @mandatorycharset ||
      ::SOAP::StreamHandler.parse_media_type(contenttype)
    env = Processor.unmarshal(conn_data.receive_string, opt)
  end
  unless env.is_a?(::SOAP::SOAPEnvelope)
    raise ResponseFormatError.new(
      "response is not a SOAP envelope: #{conn_data.receive_string}")
  end
  env
end