Minor implementation changes (feature renaming, ... )

This commit is contained in:
Jocelyn Fiat
2012-09-11 20:51:36 +02:00
parent ace897ea2b
commit 0503e63209
5 changed files with 59 additions and 11 deletions

View File

@@ -30,11 +30,12 @@ feature -- Access
feature -- Status feature -- Status
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER 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 local
p: READABLE_STRING_8 p: READABLE_STRING_8
s: like based_uri s: like based_uri
do do
p := source_uri (req) p := path_from_request (req)
s := based_uri (uri, a_router) s := based_uri (uri, a_router)
if p.starts_with (s) then if p.starts_with (s) then
Result := handler Result := handler
@@ -47,6 +48,7 @@ feature -- Status
feature {NONE} -- Implementation feature {NONE} -- Implementation
based_uri (a_uri: like uri; a_router: WSF_ROUTER): like uri based_uri (a_uri: like uri; a_router: WSF_ROUTER): like uri
-- `uri' prefixed by the `WSF_ROUTER.base_url' if any
local local
s: STRING_8 s: STRING_8
do do
@@ -59,4 +61,14 @@ feature {NONE} -- Implementation
end end
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 end

View File

@@ -43,7 +43,7 @@ feature -- Status
p: READABLE_STRING_8 p: READABLE_STRING_8
l_uri: like uri l_uri: like uri
do do
p := source_uri (req) p := path_from_request (req)
l_uri := based_uri (uri, a_router) l_uri := based_uri (uri, a_router)
if l_uri.ends_with ("/") then if l_uri.ends_with ("/") then
if not p.ends_with ("/") then if not p.ends_with ("/") then

View File

@@ -48,14 +48,18 @@ feature -- Status
p: READABLE_STRING_32 p: READABLE_STRING_32
ctx: detachable WSF_URI_TEMPLATE_HANDLER_CONTEXT ctx: detachable WSF_URI_TEMPLATE_HANDLER_CONTEXT
do do
p := source_uri (req) p := path_from_request (req)
tpl := based_uri_template (template, a_router) tpl := based_uri_template (template, a_router)
if attached tpl.match (p) as tpl_res then if attached tpl.match (p) as tpl_res then
Result := handler 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) a_router.execute_before (Current)
--| Applied the context to the request
--| in practice, this will fill the {WSF_REQUEST}.path_parameters
ctx.apply (req) ctx.apply (req)
handler.execute (ctx, req, res) 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) ctx.revert (req)
a_router.execute_after (Current) a_router.execute_after (Current)
end end
@@ -78,4 +82,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 end

View File

@@ -17,23 +17,25 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (n: INTEGER) make (n: INTEGER)
-- Create the router with a capacity of `n' mappings
do do
create mappings.make (n) create mappings.make (n)
initialize initialize (n)
end end
make_with_base_url (n: INTEGER; a_base_url: like base_url) make_with_base_url (n: INTEGER; a_base_url: like base_url)
-- Make router allocated for at least `n' maps, -- 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 do
make (n) make (n)
set_base_url (a_base_url) set_base_url (a_base_url)
end end
initialize initialize (n: INTEGER)
-- Initialize router -- Initialize router
do do
create mappings.make (10) create mappings.make (n)
create pre_execution_actions create pre_execution_actions
end end
@@ -59,9 +61,11 @@ feature -- Access
is_dispatched: BOOLEAN is_dispatched: BOOLEAN
-- `dispatch' set `is_dispatched' to True -- `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 (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Dispatch request `req' among the `mappings'
-- Set `is_dispatched' if the request were dispatched
do do
if attached dispatch_and_return_handler (req, res) then if attached dispatch_and_return_handler (req, res) then
check is_dispatched: is_dispatched end check is_dispatched: is_dispatched end
@@ -69,6 +73,8 @@ feature -- Access
end end
dispatch_and_return_handler (req: WSF_REQUEST; res: WSF_RESPONSE): detachable WSF_HANDLER 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 local
l_req_method: READABLE_STRING_8 l_req_method: READABLE_STRING_8
m: WSF_ROUTER_MAPPING m: WSF_ROUTER_MAPPING
@@ -96,11 +102,14 @@ feature -- Access
feature -- Hook feature -- Hook
execute_before (a_mapping: WSF_ROUTER_MAPPING) execute_before (a_mapping: WSF_ROUTER_MAPPING)
-- Execute before the handler associated with the matching mapping is executed
do do
pre_execution_actions.call ([a_mapping]) pre_execution_actions.call ([a_mapping])
end end
execute_after (a_mapping: WSF_ROUTER_MAPPING) 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 do
end end
@@ -111,6 +120,7 @@ feature -- Hook
feature -- Base url feature -- Base url
count: INTEGER count: INTEGER
-- Number of mappings registered
do do
Result := mappings.count Result := mappings.count
end end
@@ -260,4 +270,14 @@ feature {NONE} -- Access: Implementation
end end
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 end

View File

@@ -10,19 +10,21 @@ deferred class
feature -- Access feature -- Access
handler: WSF_HANDLER handler: WSF_HANDLER
-- Handler associated with Current mapping.
deferred deferred
end end
feature -- Status feature -- Status
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER 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 deferred
end end
feature -- Helper feature -- Helper
source_uri (req: WSF_REQUEST): READABLE_STRING_32 path_from_request (req: WSF_REQUEST): READABLE_STRING_32
-- URI to use to find handler. -- Path used by Current to check that Current mapping matches request `req'.
do do
Result := req.path_info Result := req.path_info
end end