提交 d37604f0 编写于 作者: K Kent Sibilev

Fixed XMLRPC multicall when one of the called methods returns a struct object.



git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4810 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 8cbe22ab
*SVN*
* Fixed XMLRPC multicall when one of the called methods returns a struct object. [Kent Sibilev]
* Replace Reloadable with Reloadable::Deprecated. [Nicholas Seckar]
* Fix invoke_layered since api_method didn't declare :expects. Closes #4720. [Kevin Ballard <kevin@sb.org>, Kent Sibilev]
......
......@@ -62,7 +62,7 @@ def xmlrpc_multicall_invoke(invocations)
responses = []
invocations.each do |invocation|
if invocation.is_a?(Hash)
responses << invocation
responses << [invocation, nil]
next
end
begin
......@@ -74,15 +74,18 @@ def xmlrpc_multicall_invoke(invocations)
end
api_method = invocation.api_method
if invocation.api.has_api_method?(api_method.name)
response_type = (api_method.returns ? api_method.returns[0] : nil)
return_value = api_method.cast_returns(return_value)
else
response_type = ActionWebService::SignatureTypes.canonical_signature_entry(return_value.class, 0)
end
responses << [return_value]
responses << [return_value, response_type]
rescue Exception => e
responses << { 'faultCode' => 3, 'faultString' => e.message }
responses << [{ 'faultCode' => 3, 'faultString' => e.message }, nil]
end
end
invocation = invocations[0]
invocation.protocol.encode_response('system.multicall', responses, nil, invocation.protocol_options)
invocation.protocol.encode_multicall_response(responses, invocation.protocol_options)
end
def web_service_invocation(request, level = 0)
......
......@@ -58,6 +58,19 @@ def encode_response(method_name, return_value, return_type, protocol_options={})
Response.new(raw_response, 'text/xml', return_value)
end
def encode_multicall_response(responses, protocol_options={})
result = responses.map do |return_value, return_type|
if return_value && return_type
return_value = value_to_xmlrpc_wire_format(return_value, return_type)
return_value = [return_value] unless return_value.nil?
end
return_value = false if return_value.nil?
return_value
end
raw_response = XMLRPC::Marshal.dump_response(result)
Response.new(raw_response, 'text/xml', result)
end
def protocol_client(api, protocol_name, endpoint_uri, options={})
return nil unless protocol_name == :xmlrpc
ActionWebService::Client::XmlRpc.new(api, endpoint_uri, options)
......
......@@ -110,6 +110,7 @@ class MTAPI < ActionWebService::API::Base
api_method :getCategories, :returns => [[:string]]
api_method :bool, :returns => [:bool]
api_method :alwaysFail
api_method :person, :returns => [Person]
end
class BloggerAPI < ActionWebService::API::Base
......@@ -133,6 +134,10 @@ def bool
def alwaysFail
raise "MT AlwaysFail"
end
def person
Person.new('id' => 1, 'name' => 'person1')
end
end
class BloggerService < ActionWebService::Base
......
......@@ -28,7 +28,8 @@ def test_multicall
{'methodName' => 'mt.alwaysFail'},
{'methodName' => 'blogger.alwaysFail'},
{'methodName' => 'mt.blah'},
{'methodName' => 'blah.blah'}
{'methodName' => 'blah.blah'},
{'methodName' => 'mt.person'}
])
assert_equal [
[["mtCat1", "mtCat2"]],
......@@ -38,7 +39,8 @@ def test_multicall
{"faultCode" => 3, "faultString" => "MT AlwaysFail"},
{"faultCode" => 3, "faultString" => "Blogger AlwaysFail"},
{"faultCode" => 4, "faultMessage" => "no such method 'blah' on API DispatcherTest::MTAPI"},
{"faultCode" => 4, "faultMessage" => "no such web service 'blah'"}
{"faultCode" => 4, "faultMessage" => "no such web service 'blah'"},
[{"name"=>"person1", "id"=>1}]
], response
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册