Permalink
Browse files

remove usages of @request, @response, @params, and replace with #requ…

…est, #response, #params,

except for test_invoke (values come from the test case) and one scaffold RHTML template.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1287 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 811f6a7 commit 421045e2ff9e0f2077b4f1f23541f197b3249bd7 @leonbreedt leonbreedt committed May 5, 2005
@@ -35,7 +35,7 @@ module ClassMethods
# class ApiController < ApplicationController
# web_service_dispatching_mode :delegated
#
- # web_service(:person) { PersonService.new(@request.env) }
+ # web_service(:person) { PersonService.new(request.env) }
# end
def web_service(name, object=nil, &block)
if (object && block_given?) || (object.nil? && block.nil?)
@@ -40,53 +40,53 @@ module InstanceMethods # :nodoc:
def dispatch_web_service_request
exception = nil
begin
- request = discover_web_service_request(@request)
+ ws_request = discover_web_service_request(request)
rescue Exception => e
exception = e
end
- if request
- response = nil
+ if ws_request
+ ws_response = nil
exception = nil
bm = Benchmark.measure do
begin
- response = invoke_web_service_request(request)
+ ws_response = invoke_web_service_request(ws_request)
rescue Exception => e
exception = e
end
end
- log_request(request, @request.raw_post)
+ log_request(ws_request, request.raw_post)
if exception
log_error(exception) unless logger.nil?
- send_web_service_error_response(request, exception)
+ send_web_service_error_response(ws_request, exception)
else
- send_web_service_response(response, bm.real)
+ send_web_service_response(ws_response, bm.real)
end
else
exception ||= DispatcherError.new("Malformed SOAP or XML-RPC protocol message")
log_error(exception) unless logger.nil?
- send_web_service_error_response(request, exception)
+ send_web_service_error_response(ws_request, exception)
end
rescue Exception => e
log_error(e) unless logger.nil?
- send_web_service_error_response(request, e)
+ send_web_service_error_response(ws_request, e)
end
- def send_web_service_response(response, elapsed=nil)
- log_response(response, elapsed)
- options = { :type => response.content_type, :disposition => 'inline' }
- send_data(response.body, options)
+ def send_web_service_response(ws_response, elapsed=nil)
+ log_response(ws_response, elapsed)
+ options = { :type => ws_response.content_type, :disposition => 'inline' }
+ send_data(ws_response.body, options)
end
- def send_web_service_error_response(request, exception)
- if request
+ def send_web_service_error_response(ws_request, exception)
+ if ws_request
unless self.class.web_service_exception_reporting
exception = DispatcherError.new("Internal server error (exception raised)")
end
- api_method = request.api_method
- public_method_name = api_method ? api_method.public_name : request.method_name
+ api_method = ws_request.api_method
+ public_method_name = api_method ? api_method.public_name : ws_request.method_name
return_type = ActionWebService::SignatureTypes.canonical_signature_entry(Exception, 0)
- response = request.protocol.encode_response(public_method_name + 'Response', exception, return_type, request.protocol_options)
- send_web_service_response(response)
+ ws_response = ws_request.protocol.encode_response(public_method_name + 'Response', exception, return_type, ws_request.protocol_options)
+ send_web_service_response(ws_response)
else
if self.class.web_service_exception_reporting
message = exception.message
@@ -100,13 +100,10 @@ def send_web_service_error_response(request, exception)
end
def web_service_direct_invoke(invocation)
- @params ||= {}
invocation.method_named_params.each do |name, value|
- @params[name] = value
+ params[name] = value
end
- @session ||= {}
- @assigns ||= {}
- @params['action'] = invocation.api_method.name.to_s
+ params['action'] = invocation.api_method.name.to_s
if before_action == false
raise(DispatcherError, "Method filtered")
end
@@ -115,27 +112,27 @@ def web_service_direct_invoke(invocation)
return_value
end
- def log_request(request, body)
+ def log_request(ws_request, body)
unless logger.nil?
- name = request.method_name
- api_method = request.api_method
- params = request.method_params
+ name = ws_request.method_name
+ api_method = ws_request.api_method
+ params = ws_request.method_params
if api_method && api_method.expects
params = api_method.expects.zip(params).map{ |type, param| "#{type.name}=>#{param.inspect}" }
else
params = params.map{ |param| param.inspect }
end
- service = request.service_name
+ service = ws_request.service_name
logger.debug("\nWeb Service Request: #{name}(#{params.join(", ")}) Entrypoint: #{service}")
logger.debug(indent(body))
end
end
- def log_response(response, elapsed=nil)
+ def log_response(ws_response, elapsed=nil)
unless logger.nil?
elapsed = (elapsed ? " (%f):" % elapsed : ":")
- logger.debug("\nWeb Service Response" + elapsed + " => #{response.return_value.inspect}")
- logger.debug(indent(response.body))
+ logger.debug("\nWeb Service Response" + elapsed + " => #{ws_response.return_value.inspect}")
+ logger.debug(indent(ws_response.body))
end
end
@@ -152,7 +149,7 @@ module WsdlAction # :nodoc:
SoapHttpTransport = 'http://schemas.xmlsoap.org/soap/http'
def wsdl
- case @request.method
+ case request.method
when :get
begin
options = { :type => 'text/xml', :disposition => 'inline' }
@@ -167,15 +164,9 @@ def wsdl
private
def base_uri
- if @request
- host = @request.env['HTTP_HOST'] || @request.env['SERVER_NAME']
- relative_url_root = @request.relative_url_root
- scheme = @request.ssl? ? 'https' : 'http'
- else
- host = 'localhost'
- relative_url_root = ""
- scheme = 'http'
- end
+ host = request.env['HTTP_HOST'] || request.env['SERVER_NAME'] || 'localhost'
+ relative_url_root = request.relative_url_root
+ scheme = request.ssl? ? 'https' : 'http'
'%s://%s%s/%s/' % [scheme, host, relative_url_root, controller_name]
end
@@ -42,33 +42,33 @@ def web_service_scaffold(action_name)
add_template_helper(Helpers)
module_eval <<-END, __FILE__, __LINE__
def #{action_name}
- if @request.method == :get
+ if request.method == :get
setup_invocation_assigns
render_invocation_scaffold 'methods'
end
end
def #{action_name}_method_params
- if @request.method == :get
+ if request.method == :get
setup_invocation_assigns
render_invocation_scaffold 'parameters'
end
end
def #{action_name}_submit
- if @request.method == :post
+ if request.method == :post
setup_invocation_assigns
- protocol_name = @params['protocol'] ? @params['protocol'].to_sym : :soap
+ protocol_name = params['protocol'] ? params['protocol'].to_sym : :soap
case protocol_name
when :soap
@protocol = Protocol::Soap::SoapProtocol.new
when :xmlrpc
@protocol = Protocol::XmlRpc::XmlRpcProtocol.new
end
- @invocation_cgi = @request.respond_to?(:cgi) ? @request.cgi : nil
+ @invocation_cgi = request.respond_to?(:cgi) ? request.cgi : nil
bm = Benchmark.measure do
@protocol.register_api(@scaffold_service.api)
- post_params = @params['method_params'] ? @params['method_params'].dup : nil
+ post_params = params['method_params'] ? params['method_params'].dup : nil
params = []
if @scaffold_method.expects
@scaffold_method.expects.length.times do |i|
@@ -82,7 +82,7 @@ def #{action_name}_submit
prepare_request(new_request, @scaffold_service.name, @scaffold_method.public_name)
@request = new_request
if @scaffold_container.dispatching_mode != :direct
- @request.parameters['action'] = @scaffold_service.name
+ request.parameters['action'] = @scaffold_service.name
end
dispatch_web_service_request
@method_response_xml = @response.body
@@ -102,9 +102,9 @@ def setup_invocation_assigns
@scaffold_class = self.class
@scaffold_action_name = "#{action_name}"
@scaffold_container = WebServiceModel::Container.new(self)
- if @params['service'] && @params['method']
- @scaffold_service = @scaffold_container.services.find{ |x| x.name == @params['service'] }
- @scaffold_method = @scaffold_service.api_methods[@params['method']]
+ if params['service'] && params['method']
+ @scaffold_service = @scaffold_container.services.find{ |x| x.name == params['service'] }
+ @scaffold_method = @scaffold_service.api_methods[params['method']]
end
add_instance_variables_to_assigns
end
@@ -121,13 +121,13 @@ def scaffold_path(template_name)
end
def reset_invocation_response
- template = @response.template
+ template = response.template
if @invocation_cgi
@response = ::ActionController::CgiResponse.new(@invocation_cgi)
else
@response = ::ActionController::TestResponse.new
end
- @response.template = template
+ response.template = template
@performed_render = false
end
@@ -139,10 +139,10 @@ def public_method_name(service_name, method_name)
end
end
- def prepare_request(request, service_name, method_name)
- request.parameters.update(@request.parameters)
+ def prepare_request(new_request, service_name, method_name)
+ new_request.parameters.update(request.parameters)
if web_service_dispatching_mode == :layered && @protocol.is_a?(ActionWebService::Protocol::Soap::SoapProtocol)
- request.env['HTTP_SOAPACTION'] = "/\#{controller_name()}/\#{service_name}/\#{method_name}"
+ new_request.env['HTTP_SOAPACTION'] = "/\#{controller_name()}/\#{service_name}/\#{method_name}"
end
end
@@ -126,6 +126,7 @@ def getCategories
class AbstractController < ActionController::Base
def generate_wsdl
+ @request ||= ::ActionController::TestRequest.new
to_wsdl
end
end

0 comments on commit 421045e

Please sign in to comment.