From b94bd32f3116b469b48400382dbc964bf17994d1 Mon Sep 17 00:00:00 2001 From: Leon Breedt Date: Tue, 29 Mar 2005 12:31:39 +0000 Subject: first pass of web service scaffolding. add ability to quickly generate an action pack request for a protocol, add missing log_error when we fail to parse protocol messages. add RDoc for scaffolding and functional testing. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1037 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_web_service/protocol/abstract.rb | 54 ++++++++++++++++++++++ .../action_web_service/protocol/soap_protocol.rb | 8 +++- .../action_web_service/protocol/xmlrpc_protocol.rb | 2 +- 3 files changed, 62 insertions(+), 2 deletions(-) (limited to 'actionwebservice/lib/action_web_service/protocol') diff --git a/actionwebservice/lib/action_web_service/protocol/abstract.rb b/actionwebservice/lib/action_web_service/protocol/abstract.rb index ed50a6ffde..0ff4feef84 100644 --- a/actionwebservice/lib/action_web_service/protocol/abstract.rb +++ b/actionwebservice/lib/action_web_service/protocol/abstract.rb @@ -7,10 +7,64 @@ module ActionWebService # :nodoc: attr :marshaler attr :encoder + def unmarshal_request(ap_request) + end + def marshal_response(method, return_value) body = method.encode_rpc_response(marshaler, encoder, return_value) Response.new(body, 'text/xml') end + + def protocol_client(api, protocol_name, endpoint_uri, options) + end + + def create_action_pack_request(service_name, public_method_name, raw_body, options={}) + klass = options[:request_class] || SimpleActionPackRequest + request = klass.new + request.request_parameters['action'] = service_name.to_s + request.env['RAW_POST_DATA'] = raw_body + request.env['REQUEST_METHOD'] = 'POST' + request.env['HTTP_CONTENT_TYPE'] = 'text/xml' + request + end + end + + class SimpleActionPackRequest < ActionController::AbstractRequest + def initialize + @env = {} + @qparams = {} + @rparams = {} + @cookies = {} + reset_session + end + + def query_parameters + @qparams + end + + def request_parameters + @rparams + end + + def env + @env + end + + def host + '' + end + + def cookies + @cookies + end + + def session + @session + end + + def reset_session + @session = {} + end end class Request # :nodoc: diff --git a/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb b/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb index 253812b5e2..5e56748ae3 100644 --- a/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb +++ b/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb @@ -20,11 +20,17 @@ module ActionWebService # :nodoc: Request.new(self, method_name, params, service_name) end - def protocol_client(api, protocol_name, endpoint_uri, options) + def protocol_client(api, protocol_name, endpoint_uri, options={}) return nil unless protocol_name == :soap ActionWebService::Client::Soap.new(api, endpoint_uri, options) end + def create_action_pack_request(service_name, public_method_name, raw_body, options={}) + request = super + request.env['HTTP_SOAPACTION'] = '/soap/%s/%s' % [service_name, public_method_name] + request + end + private def has_valid_soap_action?(request) return nil unless request.method == :post diff --git a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb index 37ef16c12f..f8ff12cfa3 100644 --- a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb +++ b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb @@ -18,7 +18,7 @@ module ActionWebService # :nodoc: Request.new(self, method_name, params, service_name) end - def protocol_client(api, protocol_name, endpoint_uri, options) + def protocol_client(api, protocol_name, endpoint_uri, options={}) return nil unless protocol_name == :xmlrpc ActionWebService::Client::XmlRpc.new(api, endpoint_uri, options) end -- cgit v1.2.3