Class: SOAP::RPC::Proxy

Inherits:
Object show all
Includes:
SOAP
Defined in:
lib/soap/rpc/proxy.rb

Defined Under Namespace

Classes: Operation

Constant Summary

Constants included from SOAP

AttrActor, AttrArrayType, AttrArrayTypeName, AttrEncodingStyle, AttrEncodingStyleName, AttrMustUnderstand, AttrMustUnderstandName, AttrOffset, AttrOffsetName, AttrPosition, AttrPositionName, AttrRoot, AttrRootName, Base64Literal, EleBody, EleBodyName, EleEnvelope, EleEnvelopeName, EleFault, EleFaultActor, EleFaultActorName, EleFaultCode, EleFaultCodeName, EleFaultDetail, EleFaultDetailName, EleFaultName, EleFaultString, EleFaultStringName, EleHeader, EleHeaderName, EncodingNamespace, EnvelopeNamespace, LiteralNamespace, MediaType, NextActor, PropertyName, SOAPNamespaceTag, TypeMap, VERSION, ValueArray, ValueArrayName, XSDNamespaceTag, XSINamespaceTag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint_url, soapaction, options) ⇒ Proxy

Returns a new instance of Proxy.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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

Instance Attribute Details

#allow_unqualified_elementObject

Returns the value of attribute allow_unqualified_element



29
30
31
# File 'lib/soap/rpc/proxy.rb', line 29

def allow_unqualified_element
  @allow_unqualified_element
end

#default_encodingstyleObject

Returns the value of attribute default_encodingstyle



30
31
32
# File 'lib/soap/rpc/proxy.rb', line 30

def default_encodingstyle
  @default_encodingstyle
end

#generate_explicit_typeObject

Returns the value of attribute generate_explicit_type



31
32
33
# File 'lib/soap/rpc/proxy.rb', line 31

def generate_explicit_type
  @generate_explicit_type
end

#headerhandlerObject (readonly)

Returns the value of attribute headerhandler



32
33
34
# File 'lib/soap/rpc/proxy.rb', line 32

def headerhandler
  @headerhandler
end

#literal_mapping_registryObject

Returns the value of attribute literal_mapping_registry



36
37
38
# File 'lib/soap/rpc/proxy.rb', line 36

def literal_mapping_registry
  @literal_mapping_registry
end

#mandatorycharsetObject

Returns the value of attribute mandatorycharset



28
29
30
# File 'lib/soap/rpc/proxy.rb', line 28

def mandatorycharset
  @mandatorycharset
end

#mapping_registryObject

Returns the value of attribute mapping_registry



35
36
37
# File 'lib/soap/rpc/proxy.rb', line 35

def mapping_registry
  @mapping_registry
end

#operationObject (readonly)

Returns the value of attribute operation



38
39
40
# File 'lib/soap/rpc/proxy.rb', line 38

def operation
  @operation
end

#soapactionObject

Returns the value of attribute soapaction



27
28
29
# File 'lib/soap/rpc/proxy.rb', line 27

def soapaction
  @soapaction
end

#streamhandlerObject (readonly)

Returns the value of attribute streamhandler



33
34
35
# File 'lib/soap/rpc/proxy.rb', line 33

def streamhandler
  @streamhandler
end

Instance Method Details

#add_document_operation(soapaction, name, param_def, opt = {}) ⇒ Object Also known as: add_document_method



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# 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

#add_rpc_operation(qname, soapaction, name, param_def, opt = {}) ⇒ Object Also known as: add_method, add_rpc_method



81
82
83
84
85
86
87
88
# 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

#call(name, *params) ⇒ Object

Raises:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# 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) ⇒ Object



178
179
180
181
182
# File 'lib/soap/rpc/proxy.rb', line 178

def check_fault(body)
  if body.fault
    raise SOAP::FaultError.new(body.fault)
  end
end

#endpoint_urlObject



60
61
62
# File 'lib/soap/rpc/proxy.rb', line 60

def endpoint_url
  @endpoint_url
end

#endpoint_url=(endpoint_url) ⇒ Object



64
65
66
67
# File 'lib/soap/rpc/proxy.rb', line 64

def endpoint_url=(endpoint_url)
  @endpoint_url = endpoint_url
  reset_stream
end

#inspectObject



56
57
58
# File 'lib/soap/rpc/proxy.rb', line 56

def inspect
  "#<#{self.class}:#{@endpoint_url}>"
end

#invoke(req_header, req_body, opt = nil) ⇒ Object



111
112
113
114
# 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_streamObject



69
70
71
# File 'lib/soap/rpc/proxy.rb', line 69

def reset_stream
  @streamhandler.reset(@endpoint_url)
end

#route(req_header, req_body, reqopt, resopt) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# 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) ⇒ Object



73
74
75
# 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_responseObject



77
78
79
# File 'lib/soap/rpc/proxy.rb', line 77

def test_loopback_response
  @streamhandler.test_loopback_response
end