Class: ActionService::Protocol::XmlRpc::XmlRpcProtocol

Inherits:
AbstractProtocol show all
Includes:
XMLRPC::ParserWriterChooseMixin
Defined in:
lib/action_service/protocol/xmlrpc.rb

Instance Attribute Summary

Attributes inherited from AbstractProtocol

#container_klass

Instance Method Summary collapse

Constructor Details

#initialize(container_klass) ⇒ XmlRpcProtocol

Returns a new instance of XmlRpcProtocol.



15
16
17
18
# File 'lib/action_service/protocol/xmlrpc.rb', line 15

def initialize(container_klass)
  @container_klass = container_klass
  @container_klass.write_inheritable_hash('default_system_exports', XmlRpcProtocol => method(:xmlrpc_default_system_handler))
end

Instance Method Details

#marshal_exception(exception) ⇒ Object



52
53
54
55
# File 'lib/action_service/protocol/xmlrpc.rb', line 52

def marshal_exception(exception)
  raw_response = create().methodResponse(false, exception)
  ServiceResponseInfo.new(raw_response, 'text/xml')
end

#marshal_response(request_info, export_info, return_value, strict = true) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/action_service/protocol/xmlrpc.rb', line 32

def marshal_response(request_info, export_info, return_value, strict=true)
  returns = export_info[:returns]
  if returns
    returns = array_types(returns)
    validate_types(request_info.public_method_name, returns, [return_value], :out)
    raw_response = create().methodResponse(true, return_value)
  else
    # XML-RPC doesn't have the concept of a void method, nor does it
    # support a nil return value, so return true if we would have returned
    # nil
    if strict
      raw_response = create().methodResponse(true, true)
    else
      return_value = true if return_value.nil?
      raw_response = create().methodResponse(true, return_value)
    end
  end
  ServiceResponseInfo.new(raw_response, 'text/xml')
end

#request_infoObject



57
58
59
# File 'lib/action_service/protocol/xmlrpc.rb', line 57

def request_info
  @request_info
end

#request_supported?(request) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/action_service/protocol/xmlrpc.rb', line 61

def request_supported?(request)
  begin
    service_name = request.parameters['action']
    methodname, params = parser().parseMethodCall(request.raw_post)
    @request_info = ServiceRequestInfo.new(service_name,
      methodname,
      request.raw_post,
      request.env['HTTP_CONTENT_TYPE'] || 'text/xml',
      :xmlrpc => { :params => params })
    true
  rescue
    false
  end
end

#unmarshal_request(request_info, export_info, strict = true) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/action_service/protocol/xmlrpc.rb', line 20

def unmarshal_request(request_info, export_info, strict=true)
  expects = export_info[:expects]
  params = request_info.protocol_info[:xmlrpc][:params]
  if expects
    expects = array_types(expects)
    validate_types(request_info.public_method_name, expects, params, :in)
    params
  else
    strict ? [] : params
  end
end