/library/server/rest/interface/rest_application.e

http://github.com/jocelyn/EiffelWebReloaded · Specman e · 85 lines · 69 code · 13 blank · 3 comment · 3 complexity · f149a903c4f4863959921251e6806f67 MD5 · raw file

  1. note
  2. description : "Objects that ..."
  3. author : "$Author$"
  4. date : "$Date$"
  5. revision : "$Revision$"
  6. deferred class
  7. REST_APPLICATION
  8. inherit
  9. HTTPD_APPLICATION
  10. redefine
  11. new_request_context
  12. end
  13. feature {NONE} -- Handlers
  14. handler_manager: REST_REQUEST_HANDLER_MANAGER
  15. deferred
  16. end
  17. feature {NONE} -- Environment
  18. new_request_context (a_vars: HASH_TABLE [STRING, STRING]; a_input: HTTPD_SERVER_INPUT; a_output: HTTPD_SERVER_OUTPUT): REST_REQUEST_CONTEXT
  19. do
  20. create Result.make (a_vars, a_input, a_output)
  21. Result.environment_variables.add_variable (request_count.out, "REQUEST_COUNT")
  22. end
  23. feature -- Execution
  24. execute (ctx: like new_request_context)
  25. local
  26. rescued: INTEGER
  27. rq: detachable REST_REQUEST_HANDLER
  28. do
  29. if rescued = 0 then
  30. rq := handler_manager.handler (ctx)
  31. if rq = Void then
  32. rq := handler_manager.smart_handler (ctx)
  33. end
  34. if rq /= Void then
  35. rq.execute (ctx)
  36. else
  37. execute_default (ctx)
  38. end
  39. elseif rescued = 1 then
  40. execute_rescue (ctx)
  41. else
  42. -- Bye Bye
  43. exit_with_code (-1)
  44. end
  45. rescue
  46. rescued := rescued + 1
  47. retry
  48. end
  49. execute_default (ctx: like new_request_context)
  50. -- Execute the default behavior
  51. deferred
  52. end
  53. execute_rescue (ctx: like new_request_context)
  54. -- Execute the default rescue behavior
  55. deferred
  56. end
  57. feature -- Execution
  58. exit_with_code (a_code: INTEGER)
  59. do
  60. (create {EXCEPTIONS}).die (a_code)
  61. end
  62. note
  63. copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
  64. license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
  65. source: "[
  66. Eiffel Software
  67. 5949 Hollister Ave., Goleta, CA 93117 USA
  68. Telephone 805-685-1006, Fax 805-685-6869
  69. Website http://www.eiffel.com
  70. Customer support http://support.eiffel.com
  71. ]"
  72. end