diff options
author | Leon Breedt <bitserf@gmail.com> | 2005-03-28 03:20:13 +0000 |
---|---|---|
committer | Leon Breedt <bitserf@gmail.com> | 2005-03-28 03:20:13 +0000 |
commit | 594063f23cf8e7cecd24329e801992784f420b55 (patch) | |
tree | d52e9a6fc0521d51fcc3875162adf0411ee6caa0 /actionwebservice/lib/action_web_service/protocol | |
parent | 439a216dcb65ac83d86ca04bb898e1797a87ce70 (diff) | |
download | rails-594063f23cf8e7cecd24329e801992784f420b55.tar.gz rails-594063f23cf8e7cecd24329e801992784f420b55.tar.bz2 rails-594063f23cf8e7cecd24329e801992784f420b55.zip |
generalize casting code to be used by both SOAP and XML-RPC (previously only XML-RPC). switch
to better model for API methods, and improve the ability to generate protocol requests/response,
will be required by upcoming scaffolding.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1030 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionwebservice/lib/action_web_service/protocol')
3 files changed, 17 insertions, 37 deletions
diff --git a/actionwebservice/lib/action_web_service/protocol/abstract.rb b/actionwebservice/lib/action_web_service/protocol/abstract.rb index 7526539d53..ed50a6ffde 100644 --- a/actionwebservice/lib/action_web_service/protocol/abstract.rb +++ b/actionwebservice/lib/action_web_service/protocol/abstract.rb @@ -3,17 +3,31 @@ module ActionWebService # :nodoc: class ProtocolError < ActionWebServiceError # :nodoc: end + class AbstractProtocol + attr :marshaler + attr :encoder + + def marshal_response(method, return_value) + body = method.encode_rpc_response(marshaler, encoder, return_value) + Response.new(body, 'text/xml') + end + end + class Request # :nodoc: attr :protocol attr :method_name attr :method_params attr :service_name + attr_accessor :api + attr_accessor :api_method - def initialize(protocol, method_name, method_params, service_name) + def initialize(protocol, method_name, method_params, service_name, api=nil, api_method=nil) @protocol = protocol @method_name = method_name @method_params = method_params @service_name = service_name + @api = api + @api_method = api_method end end diff --git a/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb b/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb index 2dab7954f9..253812b5e2 100644 --- a/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb +++ b/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb @@ -6,7 +6,7 @@ module ActionWebService # :nodoc: base.class_inheritable_option(:wsdl_service_name) end - class SoapProtocol # :nodoc: + class SoapProtocol < AbstractProtocol # :nodoc: def initialize @encoder = WS::Encoding::SoapRpcEncoding.new 'urn:ActionWebService' @marshaler = WS::Marshaling::SoapMarshaler.new 'urn:ActionWebService' @@ -20,22 +20,6 @@ module ActionWebService # :nodoc: Request.new(self, method_name, params, service_name) end - def marshal_response(method_name, return_value, signature_type) - if !return_value.nil? && signature_type - type_binding = @marshaler.register_type(signature_type) - info = WS::ParamInfo.create(signature_type, type_binding, 0) - return_value = @marshaler.marshal(WS::Param.new(return_value, info)) - else - return_value = nil - end - body = @encoder.encode_rpc_response(method_name + 'Response', return_value) - Response.new(body, 'text/xml') - end - - def register_signature_type(spec) - @marshaler.register_type(spec) - end - def protocol_client(api, protocol_name, endpoint_uri, options) return nil unless protocol_name == :soap ActionWebService::Client::Soap.new(api, endpoint_uri, options) diff --git a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb index 8d6af246ec..f3e4a23b4b 100644 --- a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb +++ b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb @@ -5,9 +5,7 @@ module ActionWebService # :nodoc: base.register_protocol(XmlRpcProtocol) end - class XmlRpcProtocol # :nodoc: - attr :marshaler - + class XmlRpcProtocol < AbstractProtocol # :nodoc: def initialize @encoder = WS::Encoding::XmlRpcEncoding.new @marshaler = WS::Marshaling::XmlRpcMarshaler.new @@ -22,22 +20,6 @@ module ActionWebService # :nodoc: nil end - def marshal_response(method_name, return_value, signature_type) - if !return_value.nil? && signature_type - type_binding = @marshaler.register_type(signature_type) - info = WS::ParamInfo.create(signature_type, type_binding, 0) - return_value = @marshaler.marshal(WS::Param.new(return_value, info)) - else - return_value = nil - end - body = @encoder.encode_rpc_response(method_name, return_value) - Response.new(body, 'text/xml') - end - - def register_signature_type(spec) - nil - end - def protocol_client(api, protocol_name, endpoint_uri, options) return nil unless protocol_name == :xmlrpc ActionWebService::Client::XmlRpc.new(api, endpoint_uri, options) |