Hi, I needed to create a fault message in a XML-RPC ws. The only tip I've found says to raise a FaultException giving the faultCode and the faultString. But testing with the scaffold I get: NoMethodError in UserController#invoke_submit
You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.collect
Here's the api implementation:
class UserController < ApplicationController wsdl_service_name 'User' web_service_scaffold :invoke def create(email, password, first_name, last_name, phone)
if first_name == "admin" raise XMLRPC::FaultException.new(3, "admin is not allowed...") else return 0 end end end
In the development log looks like the raised exeption correctly builds the answer: Web Service Response: => #<XMLRPC::FaultException: XMLRPC::FaultException> <?xml version="1.0" ?><methodResponse><fault><value><struct><member><name>faultCode</name><value><i4>3</i4></value></member><member><name>faultString</name><value><string>admin is not allowed...</string></value></member></struct></value></fault></methodResponse> Sending data
but then something happens and I have no clue. Thanks, Enrico
ps this is the complete development log file:
Processing UserController#invoke_submit (for 127.0.0.1 at 2007-02-14 00:21:13) [POST] Session ID: bf63f47951b57e90f2b11afaedb1d08a Parameters: {"commit"=>"Invoke", "protocol"=>"xmlrpc", "service"=>"user", "action"=>"invoke_submit", "method"=>"Create", "controller"=>"user", "method_params"=>{"0"=>"a", "1"=>"a", "2"=>"admin", "3"=>"a", "4"=>"a"}}
Web Service Request: Create(email=>"a", password=>"a", first_name=>"admin", last_name=>"a", phone=>"a") Entrypoint: invoke_submit <?xml version="1.0" ?><methodCall><methodName>Create</methodName><params><param><value><string>a</string></value></param><param><value><string>a</string></value></param><param><value><string>admin</string></value></param><param><value><string>a</string></value></param><param><value><string>a</string></value></param></params></methodCall>
XMLRPC::FaultException (admin is not allowed...): .//app/controllers/user_controller.rb:8:in `create' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/invocation.rb:141:in `perform_invocation_without_interception' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/invocation.rb:135:in `perform_invocation' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/dispatcher/abstract.rb:42:in `web_service_filtered_invoke' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/dispatcher/abstract.rb:33:in `web_service_direct_invoke_without_controller' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/dispatcher/action_controller_dispatcher.rb:109:in `web_service_direct_invoke' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/dispatcher/abstract.rb:54:in `web_service_invoke' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/dispatcher/abstract.rb:21:in `invoke_web_service_request' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/dispatcher/action_controller_dispatcher.rb:55:in `dispatch_web_service_request' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/dispatcher/action_controller_dispatcher.rb:53:in `dispatch_web_service_request' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/scaffolding.rb:83:in `invoke_submit' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/scaffolding.rb:67:in `invoke_submit' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:1095:in `perform_action_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:632:in `call_filter' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/rescue.rb:83:in `perform_action' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:430:in `process_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:624:in `process_without_session_management_support' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/session_management.rb:114:in `process' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:330:in `process' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/dispatcher.rb:41:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:113:in `handle_dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:79:in `service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:63:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/servers/webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in `new_constants_in' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/server.rb:39 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in `new_constants_in' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require' script/server:3
Web Service Response: => #<XMLRPC::FaultException: XMLRPC::FaultException> <?xml version="1.0" ?><methodResponse><fault><value><struct><member><name>faultCode</name><value><i4>3</i4></value></member><member><name>faultString</name><value><string>admin is not allowed...</string></value></member></struct></value></fault></methodResponse> Sending data
NoMethodError (You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.collect): /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/rescue.rb:139:in `clean_backtrace' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/rescue.rb:43:in `log_error' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/deprecation.rb:43:in `silence' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/rescue.rb:37:in `log_error' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/rescue.rb:25:in `rescue_action' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/scaffolding.rb:158:in `handle_invocation_exception' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/scaffolding.rb:86:in `invoke_submit' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.2.1/lib/action_web_service/scaffolding.rb:67:in `invoke_submit' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:1095:in `perform_action_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:632:in `call_filter' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/rescue.rb:83:in `perform_action' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:430:in `process_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:624:in `process_without_session_management_support' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/session_management.rb:114:in `process' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:330:in `process' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/dispatcher.rb:41:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:113:in `handle_dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:79:in `service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:63:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/servers/webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in `new_constants_in' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/server.rb:39 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in `new_constants_in' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require' script/server:3
Rendering /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/templates/rescues/layout.rhtml (500 Internal Error)