From 5249275b23b39de0834b8d342cb99838c3deda78 Mon Sep 17 00:00:00 2001 From: Colin Adams Date: Wed, 27 Mar 2013 15:38:13 +0000 Subject: [PATCH] Further changes in response to review comments by Jocelyn --- .../helpers/wsf_uri_template_routed_service.e | 27 ++++++++ .../helpers/wsf_uri_template_router_helper.e | 68 +++++++++++++++++++ .../wsf/router/wsf_routed_skeleton_service.e | 14 ++-- .../wsf_method_not_allowed_response.e | 46 +++++++------ 4 files changed, 128 insertions(+), 27 deletions(-) create mode 100644 library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_routed_service.e create mode 100644 library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_router_helper.e diff --git a/library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_routed_service.e b/library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_routed_service.e new file mode 100644 index 00000000..8db2b0e0 --- /dev/null +++ b/library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_routed_service.e @@ -0,0 +1,27 @@ +note + description: "Summary description for {WSF_URI_TEMPLATE_ROUTED_SERVICE}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + WSF_URI_TEMPLATE_ROUTED_SERVICE + +obsolete "Inherit from WSF_ROUTED_SERVICE and WSF_URI_ROUTER_HELPER [2013-mar-19]" + +inherit + WSF_ROUTED_SERVICE + + WSF_URI_TEMPLATE_ROUTER_HELPER + +note + copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" + source: "[ + Eiffel Software + 5949 Hollister Ave., Goleta, CA 93117 USA + Telephone 805-685-1006, Fax 805-685-6869 + Website http://www.eiffel.com + Customer support http://support.eiffel.com + ]" +end diff --git a/library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_router_helper.e b/library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_router_helper.e new file mode 100644 index 00000000..b1db35ad --- /dev/null +++ b/library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_router_helper.e @@ -0,0 +1,68 @@ +note + description: "Summary description for {WSF_URI_TEMPLATE_ROUTER_HELPER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + WSF_URI_TEMPLATE_ROUTER_HELPER + + obsolete "Use class WSF_URI_TEMPLATE_HELPER_FOR_ROUTED_SERVICE in conjunction with WSF_ROUTED_SKELETON_SERVICE" + +feature -- Access + + router: WSF_ROUTER + deferred + end + +feature -- Mapping helper: uri + + map_uri_template (a_tpl: STRING; h: WSF_URI_TEMPLATE_HANDLER) + -- Map `h' as handler for `a_tpl' + require + a_tpl_attached: a_tpl /= Void + h_attached: h /= Void + do + map_uri_template_with_request_methods (a_tpl, h, Void) + end + + map_uri_template_with_request_methods (a_tpl: READABLE_STRING_8; h: WSF_URI_TEMPLATE_HANDLER; rqst_methods: detachable WSF_REQUEST_METHODS) + -- Map `h' as handler for `a_tpl' for request methods `rqst_methods'. + require + a_tpl_attached: a_tpl /= Void + h_attached: h /= Void + do + router.map_with_request_methods (create {WSF_URI_TEMPLATE_MAPPING}.make (a_tpl, h), rqst_methods) + end + +feature -- Mapping helper: uri agent + + map_uri_template_agent (a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]) + -- Map `proc' as handler for `a_tpl' + require + a_tpl_attached: a_tpl /= Void + proc_attached: proc /= Void + do + map_uri_template_agent_with_request_methods (a_tpl, proc, Void) + end + + map_uri_template_agent_with_request_methods (a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_REQUEST_METHODS) + -- Map `proc' as handler for `a_tpl' for request methods `rqst_methods'. + require + a_tpl_attached: a_tpl /= Void + proc_attached: proc /= Void + do + map_uri_template_with_request_methods (a_tpl, create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (proc), rqst_methods) + end + +note + copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" + source: "[ + Eiffel Software + 5949 Hollister Ave., Goleta, CA 93117 USA + Telephone 805-685-1006, Fax 805-685-6869 + Website http://www.eiffel.com + Customer support http://support.eiffel.com + ]" +end diff --git a/library/server/wsf/router/wsf_routed_skeleton_service.e b/library/server/wsf/router/wsf_routed_skeleton_service.e index 9aff9444..6253c8cd 100644 --- a/library/server/wsf/router/wsf_routed_skeleton_service.e +++ b/library/server/wsf/router/wsf_routed_skeleton_service.e @@ -22,6 +22,8 @@ feature -- Execution execute (req: WSF_REQUEST; res: WSF_RESPONSE) -- If the service is available, and request URI is not too long, dispatch the request -- and if handler is not found, execute the default procedure `execute_default'. + local + l_sess: WSF_ROUTER_SESSION do --| When we reach here, the request has already passed check for 400 (Bad request), --| which is implemented in WSF_REQUEST.make_from_wgi (when it calls `analyze'). @@ -34,10 +36,12 @@ feature -- Execution elseif req.is_request_method ({HTTP_REQUEST_METHODS}.method_options) and then req.request_uri.same_string ("*") then handle_server_options (req, res) - elseif attached router.dispatch_and_return_handler (req, res) as p then - -- executed else - execute_default (req, res) + create l_sess + router.dispatch (req, res, l_sess) + if not l_sess.dispatched then + execute_default (req, res) + end end end @@ -180,7 +184,7 @@ feature {NONE} -- Implementation frozen handle_system_options_forbidden (req: WSF_REQUEST; res: WSF_RESPONSE) -- Write a 403 Forbidden or a 404 Not found response into `res'. - require + require req_attached: req /= Void res_attached: res /= Void method_is_options: req.is_request_method ({HTTP_REQUEST_METHODS}.method_options) @@ -217,7 +221,7 @@ feature {NONE} -- Implementation handle_system_options (req: WSF_REQUEST; res: WSF_RESPONSE) -- Write response to OPTIONS * into `res'. -- This may be redefined by the user, but normally this will not be necessary. - require + require req_attached: req /= Void res_attached: res /= Void method_is_options: req.is_request_method ({HTTP_REQUEST_METHODS}.method_options) diff --git a/library/server/wsf/src/response/wsf_method_not_allowed_response.e b/library/server/wsf/src/response/wsf_method_not_allowed_response.e index ee8a6b8b..4b1b580c 100644 --- a/library/server/wsf/src/response/wsf_method_not_allowed_response.e +++ b/library/server/wsf/src/response/wsf_method_not_allowed_response.e @@ -82,17 +82,18 @@ feature {WSF_RESPONSE} -- Output l_text: detachable READABLE_STRING_GENERAL l_loc: detachable READABLE_STRING_8 h: like header - l_recognized: BOOLEAN + --l_recognized: BOOLEAN l_messages: HTTP_STATUS_CODE_MESSAGES do create l_messages h := header - l_recognized := recognized_methods.has (request.request_method.as_upper) - if l_recognized then - res.set_status_code (l_messages.method_not_allowed) - else - res.set_status_code (l_messages.not_implemented) - end + -- To be considered later + --l_recognized := recognized_methods.has (request.request_method.as_upper) + --if l_recognized then + res.set_status_code (l_messages.method_not_allowed) + --else + -- res.set_status_code (l_messages.not_implemented) + --end if attached suggested_methods as lst and then not lst.is_empty then h.put_allow (lst) @@ -109,7 +110,7 @@ feature {WSF_RESPONSE} -- Output s := "Bug in server" end - l_html_error_code_text := html_error_code_text (l_messages, l_recognized) + l_html_error_code_text := html_error_code_text (l_messages, True) if request.is_content_type_accepted ({HTTP_MIME_TYPES}.text_html) then s := "" @@ -262,23 +263,24 @@ feature {WSF_RESPONSE} -- Output feature {NONE} -- Implementation - recognized_methods: WSF_REQUEST_METHODS + -- To be discussed later... + --recognized_methods: WSF_REQUEST_METHODS -- All methods defined in HTTP/1.1 specification --| Should this include CONNECT? It probably shouldn't be recognized by an origin server, --| We will need a way to extend this for additional methods that the server implements. E.g. PATCH. - do - create Result.make_from_iterable (<< - {HTTP_REQUEST_METHODS}.method_head, - {HTTP_REQUEST_METHODS}.method_get, - {HTTP_REQUEST_METHODS}.method_trace, - {HTTP_REQUEST_METHODS}.method_options, - {HTTP_REQUEST_METHODS}.method_post, - {HTTP_REQUEST_METHODS}.method_put, - {HTTP_REQUEST_METHODS}.method_delete - >>) - ensure - recognized_methods_not_void: Result /= Void - end + -- do + -- create Result.make_from_iterable (<< + -- {HTTP_REQUEST_METHODS}.method_head, + -- {HTTP_REQUEST_METHODS}.method_get, + -- {HTTP_REQUEST_METHODS}.method_trace, + -- {HTTP_REQUEST_METHODS}.method_options, + -- {HTTP_REQUEST_METHODS}.method_post, + -- {HTTP_REQUEST_METHODS}.method_put, + -- {HTTP_REQUEST_METHODS}.method_delete + -- >>) + -- ensure + -- recognized_methods_not_void: Result /= Void + -- end html_error_code_text (a_messages: HTTP_STATUS_CODE_MESSAGES; a_recognized: BOOLEAN): READABLE_STRING_8 -- Message for including in HTML error text according to `a_recognized'