Class: SOAP::RPC::Router

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

Defined Under Namespace

Classes: ApplicationScopeOperation, Operation, RequestScopeOperation

Constant Summary

Constants included from SOAP

AttrActor, AttrActorName, AttrArrayType, AttrArrayTypeName, AttrEncodingStyle, AttrEncodingStyleName, AttrHref, AttrHrefName, AttrId, AttrIdName, 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, SOAPProxy, TypeMap, ValueArray, ValueArrayName, Version, XSDNamespaceTag, XSINamespaceTag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actor) ⇒ Router

Returns a new instance of Router.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/soap/rpc/router.rb', line 38

def initialize(actor)
  @actor = actor
  @mapping_registry = nil
  @headerhandler = Header::HandlerSet.new
  @literal_mapping_registry = ::SOAP::Mapping::LiteralRegistry.new
  @generate_explicit_type = false
  @use_default_namespace = false
  @external_ces = nil
  @operation_by_soapaction = {}
  @operation_by_qname = {}
  @headerhandlerfactory = []
  @filterchain = Filter::FilterChain.new
  @original_request = nil
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



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

def actor
  @actor
end

#external_cesObject

Returns the value of attribute external_ces.



34
35
36
# File 'lib/soap/rpc/router.rb', line 34

def external_ces
  @external_ces
end

#filterchainObject (readonly)

Returns the value of attribute filterchain.



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

def filterchain
  @filterchain
end

#generate_explicit_typeObject

Returns the value of attribute generate_explicit_type.



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

def generate_explicit_type
  @generate_explicit_type
end

#literal_mapping_registryObject

Returns the value of attribute literal_mapping_registry.



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

def literal_mapping_registry
  @literal_mapping_registry
end

#mapping_registryObject

Returns the value of attribute mapping_registry.



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

def mapping_registry
  @mapping_registry
end

#original_requestObject (readonly)

Returns the value of attribute original_request.



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

def original_request
  @original_request
end

#use_default_namespaceObject

Returns the value of attribute use_default_namespace.



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

def use_default_namespace
  @use_default_namespace
end

Instance Method Details

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



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/soap/rpc/router.rb', line 127

def add_document_operation(receiver, soapaction, name, param_def, opt = {})
  #
  # adopt workaround for doc/lit wrapper method
  # (you should consider to simply use rpc/lit service)
  #
  #unless soapaction
  #  raise RPCRoutingError.new("soapaction is a must for document method")
  #end
  ensure_styleuse_option(opt, :document, :literal)
  op = ApplicationScopeOperation.new(soapaction, receiver, name, param_def,
    opt)
  if opt[:request_style] != :document
    raise RPCRoutingError.new("illegal request_style given")
  end
  assign_operation(soapaction, first_input_part_qname(param_def), op)
end

#add_document_request_operation(factory, soapaction, name, param_def, opt = {}) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/soap/rpc/router.rb', line 145

def add_document_request_operation(factory, soapaction, name, param_def, opt = {})
  #
  # adopt workaround for doc/lit wrapper method
  # (you should consider to simply use rpc/lit service)
  #
  #unless soapaction
  #  raise RPCRoutingError.new("soapaction is a must for document method")
  #end
  ensure_styleuse_option(opt, :document, :literal)
  op = RequestScopeOperation.new(soapaction, receiver, name, param_def, opt)
  if opt[:request_style] != :document
    raise RPCRoutingError.new("illegal request_style given")
  end
  assign_operation(soapaction, first_input_part_qname(param_def), op)
end

#add_headerhandler(handler) ⇒ Object



63
64
65
# File 'lib/soap/rpc/router.rb', line 63

def add_headerhandler(handler)
  @headerhandler.add(handler)
end

#add_request_headerhandler(factory) ⇒ Object

header handler interface



56
57
58
59
60
61
# File 'lib/soap/rpc/router.rb', line 56

def add_request_headerhandler(factory)
  unless factory.respond_to?(:create)
    raise TypeError.new("factory must respond to 'create'")
  end
  @headerhandlerfactory << factory
end

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

operation definition interface



104
105
106
107
108
109
110
111
112
113
# File 'lib/soap/rpc/router.rb', line 104

def add_rpc_operation(receiver, qname, soapaction, name, param_def, opt = {})
  ensure_styleuse_option(opt, :rpc, :encoded)
  opt[:request_qname] = qname
  op = ApplicationScopeOperation.new(soapaction, receiver, name, param_def,
    opt)
  if opt[:request_style] != :rpc
    raise RPCRoutingError.new("illegal request_style given")
  end
  assign_operation(soapaction, qname, op)
end

#add_rpc_request_operation(factory, qname, soapaction, name, param_def, opt = {}) ⇒ Object



117
118
119
120
121
122
123
124
125
# File 'lib/soap/rpc/router.rb', line 117

def add_rpc_request_operation(factory, qname, soapaction, name, param_def, opt = {})
  ensure_styleuse_option(opt, :rpc, :encoded)
  opt[:request_qname] = qname
  op = RequestScopeOperation.new(soapaction, factory, name, param_def, opt)
  if opt[:request_style] != :rpc
    raise RPCRoutingError.new("illegal request_style given")
  end
  assign_operation(soapaction, qname, op)
end

#add_rpc_request_servant(factory, namespace) ⇒ Object

servant definition interface



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/soap/rpc/router.rb', line 70

def add_rpc_request_servant(factory, namespace)
  unless factory.respond_to?(:create)
    raise TypeError.new("factory must respond to 'create'")
  end
  obj = factory.create        # a dummy instance for introspection
  ::SOAP::RPC.defined_methods(obj).each do |name|
    begin
      qname = XSD::QName.new(namespace, name)
      param_def = ::SOAP::RPC::SOAPMethod.derive_rpc_param_def(obj, name)
      opt = create_styleuse_option(:rpc, :encoded)
      add_rpc_request_operation(factory, qname, nil, name, param_def, opt)
    rescue SOAP::RPC::MethodDefinitionError => e
      p e if $DEBUG
    end
  end
end

#add_rpc_servant(obj, namespace) ⇒ Object Also known as: add_servant



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/soap/rpc/router.rb', line 87

def add_rpc_servant(obj, namespace)
  ::SOAP::RPC.defined_methods(obj).each do |name|
    begin
      qname = XSD::QName.new(namespace, name)
      param_def = ::SOAP::RPC::SOAPMethod.derive_rpc_param_def(obj, name)
      opt = create_styleuse_option(:rpc, :encoded)
      add_rpc_operation(obj, qname, nil, name, param_def, opt)
    rescue SOAP::RPC::MethodDefinitionError => e
      p e if $DEBUG
    end
  end
end

#create_fault_response(e) ⇒ Object

Create fault response string.



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/soap/rpc/router.rb', line 211

def create_fault_response(e)
  env = SOAPEnvelope.new(SOAPHeader.new, SOAPBody.new(fault(e, nil), true))
  opt = {}
  opt[:external_content] = nil
  @filterchain.reverse_each do |filter|
    env = filter.on_outbound(env, opt)
    break unless env
  end
  response_string = Processor.marshal(env, opt)
  conn_data = StreamHandler::ConnectionData.new(response_string)
  conn_data.is_fault = true
  if ext = opt[:external_content]
    mimeize(conn_data, ext)
  end
  conn_data
end

#route(conn_data) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/soap/rpc/router.rb', line 161

def route(conn_data)
  # we cannot set request_default_encodingsyle before parsing the content.
  env = unmarshal(conn_data)
  if env.nil?
    raise ArgumentError.new("illegal SOAP marshal format")
  end
  #Qui ho inserito il raw_post che arriva
  @original_request = conn_data.receive_string
  op = lookup_operation(conn_data.soapaction, env)
  #add_request_headerhandler(ServerAuthHeaderHandler)

  headerhandler = @headerhandler.dup
  @headerhandlerfactory.each do |f|
    headerhandler.add(f.create)
  end
  soap_response = default_encodingstyle = nil
  begin
    receive_headers(headerhandler, env.header)
    header = call_headers(headerhandler)
    #ricavo l'handler configurato
    my_handler = headerhandler.get_handler(@headerhandlerfactory[0])
    #chiamo il metodo che mi ritorna l'oggetto
    header_soap = nil
    header_soap = my_handler.on_mapping_outbound if my_handler
    soap_response = op.call(env, header_soap, @mapping_registry, @literal_mapping_registry,
        create_mapping_opt)
    conn_data.is_fault = true if soap_response.is_a?(SOAPFault)
    default_encodingstyle = op.response_default_encodingstyle
  rescue Exception => e
    # If a wsdl fault was raised by service, the fault declaration details
    # is kept in wsdl_fault. Otherwise (exception is a program fault)
    # wsdl_fault is nil
    wsdl_fault_details = op.faults && op.faults[e.class.name]
    soap_response = fault(e, wsdl_fault_details)
    conn_data.is_fault = true
    default_encodingstyle = nil
  end
  
  if op.response_use.nil?
    conn_data.send_string = ''
    conn_data.is_nocontent = true
    conn_data
  else
    body = SOAPBody.new(soap_response, conn_data.is_fault)
    env = SOAPEnvelope.new(header, body)
    marshal(conn_data, env, default_encodingstyle)
  end
end