Added WSF_ROUTER.pre_route_execution_actions: ACTION_SEQUENCE [like route]

This way, one can add logger hook to router, to see which "route" was taken by the request.
This commit is contained in:
Jocelyn Fiat
2012-04-13 16:40:19 +02:00
parent 0bd2d16c12
commit 21b03a05fd
6 changed files with 25 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ inherit
redefine
map_agent_with_request_methods, map_agent_response_with_request_methods
end
create
make

View File

@@ -34,6 +34,7 @@ feature -- Initialization
do
create handlers.make (n)
handlers.compare_objects
initialize
end
make_with_base_url (n: INTEGER; a_base_url: like base_url)

View File

@@ -31,6 +31,7 @@ feature -- Initialization
create handlers.make (n)
create templates.make (n)
handlers.compare_objects
initialize
end
make_with_base_url (n: INTEGER; a_base_url: like base_url)

View File

@@ -36,11 +36,10 @@ feature -- Setup
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
local
l_handled: BOOLEAN
do
l_handled := router.dispatch (req, res)
if not l_handled then
if attached router.route (req) as r then
router.execute_route (r, req, res)
else
execute_default (req, res)
end
end

View File

@@ -12,6 +12,14 @@ deferred class
inherit
ITERABLE [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]]
feature {NONE} -- Initialization
initialize
-- Initialize router
do
create pre_route_execution_actions
end
feature -- Status report
has_map (a_resource: READABLE_STRING_8; rqst_methods: detachable ARRAY [READABLE_STRING_8]; a_handler: detachable H): BOOLEAN
@@ -116,7 +124,13 @@ feature -- Element change
end
end
feature -- Execution
feature -- Hook
pre_route_execution_actions: ACTION_SEQUENCE [TUPLE [like route]]
-- Action triggered before a route is execute
--| Could be used for tracing, logging
feature -- Routing
route (req: WSF_REQUEST): detachable WSF_ROUTE [H, C]
-- Route matching `req'.
@@ -124,11 +138,14 @@ feature -- Execution
Result := matching_route (req)
end
feature -- Execution
execute_route (a_route: WSF_ROUTE [H,C]; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Process route `a_route'
require
a_route_attached: a_route /= Void
do
pre_route_execution_actions.call ([a_route])
a_route.handler.execute (a_route.context, req, res)
end

View File

@@ -24,8 +24,7 @@ note
revision: "$Revision$"
deferred class
WSF_ROUTING_HANDLER [H -> WSF_HANDLER [C],
C -> WSF_HANDLER_CONTEXT]
WSF_ROUTING_HANDLER [H -> WSF_HANDLER [C], C -> WSF_HANDLER_CONTEXT]
inherit
WSF_HANDLER [C]