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

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

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from AbstractProtocol

#container_class

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container_class) ⇒ XmlRpcProtocol

Returns a new instance of XmlRpcProtocol.



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

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

Class Method Details

.create_protocol_request(container_class, action_pack_request) ⇒ Object



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

def self.create_protocol_request(container_class, action_pack_request)
  helper = XMLRPC::XmlRpcHelper.instance
  service_name = action_pack_request.parameters['action']
  methodname, params = helper.parse_method_call(action_pack_request.raw_post)
  methodname.gsub!(/^[^\.]+\./, '') unless methodname =~ /^system\./ # XXX
  protocol = XmlRpcProtocol.new(container_class)
  content_type = action_pack_request.env['HTTP_CONTENT_TYPE']
  content_type ||= 'text/xml'
  request = ProtocolRequest.new(protocol,
                                action_pack_request.raw_post,
                                service_name.to_sym,
                                methodname,
                                content_type,
                                :xmlrpc_values => params)
  request
rescue
  nil
end

Instance Method Details

#marshal_exception(exception) ⇒ Object



93
94
95
96
97
98
# File 'lib/action_service/protocol/xmlrpc.rb', line 93

def marshal_exception(exception)
  helper = XMLRPC::XmlRpcHelper.instance
  exception = XMLRPC::FaultException.new(1, exception.message)
  raw_response = helper.create_method_response(false, exception)
  ProtocolResponse.new(self, raw_response, 'text/xml')
end

#marshal_response(protocol_request, return_value) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/action_service/protocol/xmlrpc.rb', line 71

def marshal_response(protocol_request, return_value)
  helper = XMLRPC::XmlRpcHelper.instance
  signature = protocol_request.return_signature
  if signature
    signature = array_types(signature)
    protocol_request.check_parameter_types([return_value], signature)
    return_value = transform_return_value(return_value)
    raw_response = helper.create_method_response(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 protocol_request.checked?
      raw_response = helper.create_method_response(true, true)
    else
      return_value = true if return_value.nil?
      raw_response = helper.create_method_response(true, return_value)
    end
  end
  ProtocolResponse.new(self, raw_response, 'text/xml')
end

#unmarshal_request(protocol_request) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/action_service/protocol/xmlrpc.rb', line 58

def unmarshal_request(protocol_request)
  values = protocol_request.options[:xmlrpc_values]
  signature = protocol_request.signature
  if signature
    signature = array_types(signature)
    values = transform_expected_params(signature, values)
    protocol_request.check_parameter_types(values, signature)
    values
  else
    protocol_request.checked? ? [] : values
  end
end