From 0503e63209f026f16349ce3fb55407f3b7a79236 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Tue, 11 Sep 2012 20:51:36 +0200 Subject: [PATCH] Minor implementation changes (feature renaming, ... ) --- .../starts_with/wsf_starts_with_mapping.e | 14 ++++++++- .../server/wsf/router/uri/wsf_uri_mapping.e | 2 +- .../uri_template/wsf_uri_template_mapping.e | 18 +++++++++-- library/server/wsf/router/wsf_router.e | 30 +++++++++++++++---- .../server/wsf/router/wsf_router_mapping.e | 6 ++-- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/library/server/wsf/router/starts_with/wsf_starts_with_mapping.e b/library/server/wsf/router/starts_with/wsf_starts_with_mapping.e index fed15b87..a71f2da8 100644 --- a/library/server/wsf/router/starts_with/wsf_starts_with_mapping.e +++ b/library/server/wsf/router/starts_with/wsf_starts_with_mapping.e @@ -30,11 +30,12 @@ feature -- Access feature -- Status routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER + -- Return the handler if Current matches the request `req'. local p: READABLE_STRING_8 s: like based_uri do - p := source_uri (req) + p := path_from_request (req) s := based_uri (uri, a_router) if p.starts_with (s) then Result := handler @@ -47,6 +48,7 @@ feature -- Status feature {NONE} -- Implementation based_uri (a_uri: like uri; a_router: WSF_ROUTER): like uri + -- `uri' prefixed by the `WSF_ROUTER.base_url' if any local s: STRING_8 do @@ -59,4 +61,14 @@ feature {NONE} -- Implementation end end +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, 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/uri/wsf_uri_mapping.e b/library/server/wsf/router/uri/wsf_uri_mapping.e index fcc33642..bf6e8d90 100644 --- a/library/server/wsf/router/uri/wsf_uri_mapping.e +++ b/library/server/wsf/router/uri/wsf_uri_mapping.e @@ -43,7 +43,7 @@ feature -- Status p: READABLE_STRING_8 l_uri: like uri do - p := source_uri (req) + p := path_from_request (req) l_uri := based_uri (uri, a_router) if l_uri.ends_with ("/") then if not p.ends_with ("/") then diff --git a/library/server/wsf/router/uri_template/wsf_uri_template_mapping.e b/library/server/wsf/router/uri_template/wsf_uri_template_mapping.e index 2623af3f..af8b7bf3 100644 --- a/library/server/wsf/router/uri_template/wsf_uri_template_mapping.e +++ b/library/server/wsf/router/uri_template/wsf_uri_template_mapping.e @@ -48,14 +48,18 @@ feature -- Status p: READABLE_STRING_32 ctx: detachable WSF_URI_TEMPLATE_HANDLER_CONTEXT do - p := source_uri (req) + p := path_from_request (req) tpl := based_uri_template (template, a_router) if attached tpl.match (p) as tpl_res then Result := handler - create ctx.make (req, tpl, tpl_res, source_uri (req)) + create ctx.make (req, tpl, tpl_res, path_from_request (req)) a_router.execute_before (Current) + --| Applied the context to the request + --| in practice, this will fill the {WSF_REQUEST}.path_parameters ctx.apply (req) handler.execute (ctx, req, res) + --| Revert {WSF_REQUEST}.path_parameters_source to former value + --| In case the request object passed by other handler that alters its values. ctx.revert (req) a_router.execute_after (Current) end @@ -78,4 +82,14 @@ feature {NONE} -- Implementation end +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, 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_router.e b/library/server/wsf/router/wsf_router.e index c1403d0b..ed039aed 100644 --- a/library/server/wsf/router/wsf_router.e +++ b/library/server/wsf/router/wsf_router.e @@ -17,23 +17,25 @@ create feature {NONE} -- Initialization make (n: INTEGER) + -- Create the router with a capacity of `n' mappings do create mappings.make (n) - initialize + initialize (n) end make_with_base_url (n: INTEGER; a_base_url: like base_url) -- Make router allocated for at least `n' maps, - -- and use `a_base_url' as base_url + -- and use `a_base_url' as `base_url' + --| This avoids prefixing all the resource string. do make (n) set_base_url (a_base_url) end - initialize + initialize (n: INTEGER) -- Initialize router do - create mappings.make (10) + create mappings.make (n) create pre_execution_actions end @@ -59,9 +61,11 @@ feature -- Access is_dispatched: BOOLEAN -- `dispatch' set `is_dispatched' to True - -- if handler was found and executed + -- if mapping was found, and associated handler executed dispatch (req: WSF_REQUEST; res: WSF_RESPONSE) + -- Dispatch request `req' among the `mappings' + -- Set `is_dispatched' if the request were dispatched do if attached dispatch_and_return_handler (req, res) then check is_dispatched: is_dispatched end @@ -69,6 +73,8 @@ feature -- Access end dispatch_and_return_handler (req: WSF_REQUEST; res: WSF_RESPONSE): detachable WSF_HANDLER + -- Dispatch request `req' among the `mappings' + -- And return the associated handler if mapping found and handler executed. local l_req_method: READABLE_STRING_8 m: WSF_ROUTER_MAPPING @@ -96,11 +102,14 @@ feature -- Access feature -- Hook execute_before (a_mapping: WSF_ROUTER_MAPPING) + -- Execute before the handler associated with the matching mapping is executed do pre_execution_actions.call ([a_mapping]) end execute_after (a_mapping: WSF_ROUTER_MAPPING) + -- Execute after the handler associated with the matching mapping is executed + --| Could be redefined to add specific hook. do end @@ -111,6 +120,7 @@ feature -- Hook feature -- Base url count: INTEGER + -- Number of mappings registered do Result := mappings.count end @@ -260,4 +270,14 @@ feature {NONE} -- Access: Implementation end end +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, 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_router_mapping.e b/library/server/wsf/router/wsf_router_mapping.e index 0fcf66da..f5fb7491 100644 --- a/library/server/wsf/router/wsf_router_mapping.e +++ b/library/server/wsf/router/wsf_router_mapping.e @@ -10,19 +10,21 @@ deferred class feature -- Access handler: WSF_HANDLER + -- Handler associated with Current mapping. deferred end feature -- Status routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER + -- Return the handler if Current matches the request `req'. deferred end feature -- Helper - source_uri (req: WSF_REQUEST): READABLE_STRING_32 - -- URI to use to find handler. + path_from_request (req: WSF_REQUEST): READABLE_STRING_32 + -- Path used by Current to check that Current mapping matches request `req'. do Result := req.path_info end