Added notion of mapping factory, so one can implement a handler without having to implement new_mapping

Added filter context handler
Added WSF_STARTS_WITH_ROUTING_HANDLER and WSF_URI_ROUTING_HANDLER (in addition to the uri template version)
This commit is contained in:
Jocelyn Fiat
2012-10-04 14:31:03 +02:00
parent f7615edec9
commit 2f6a6cbf5f
11 changed files with 148 additions and 21 deletions

View File

@@ -16,13 +16,6 @@ feature -- Execution
deferred deferred
end end
feature {WSF_ROUTER} -- Mapping
new_mapping (a_resource: READABLE_STRING_8): WSF_ROUTER_MAPPING
-- New mapping built with Current as handler
deferred
end
note note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -0,0 +1,29 @@
note
description: "Summary description for {WSF_STARTS_WITH_ROUTING_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_STARTS_WITH_ROUTING_HANDLER
inherit
WSF_ROUTING_HANDLER
WSF_STARTS_WITH_HANDLER
create
make,
make_with_router
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

View File

@@ -10,6 +10,8 @@ deferred class
inherit inherit
WSF_HANDLER WSF_HANDLER
WSF_ROUTER_MAPPING_FACTORY
feature -- Execution feature -- Execution
execute (a_start_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE) execute (a_start_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE)

View File

@@ -0,0 +1,29 @@
note
description: "Summary description for {WSF_URI_ROUTING_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_URI_ROUTING_HANDLER
inherit
WSF_ROUTING_HANDLER
WSF_URI_HANDLER
create
make,
make_with_router
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

View File

@@ -10,6 +10,8 @@ deferred class
inherit inherit
WSF_HANDLER WSF_HANDLER
WSF_ROUTER_MAPPING_FACTORY
feature -- Execution feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE) execute (req: WSF_REQUEST; res: WSF_RESPONSE)

View File

@@ -10,6 +10,8 @@ deferred class
inherit inherit
WSF_HANDLER WSF_HANDLER
WSF_ROUTER_MAPPING_FACTORY
feature -- Execution feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE) execute (req: WSF_REQUEST; res: WSF_RESPONSE)

View File

@@ -10,6 +10,8 @@ deferred class
inherit inherit
WSF_CONTEXT_HANDLER [C] WSF_CONTEXT_HANDLER [C]
WSF_ROUTER_MAPPING_FACTORY
feature {WSF_ROUTER} -- Mapping feature {WSF_ROUTER} -- Mapping
new_mapping (a_tpl: READABLE_STRING_8): WSF_ROUTER_MAPPING new_mapping (a_tpl: READABLE_STRING_8): WSF_ROUTER_MAPPING

View File

@@ -17,14 +17,7 @@ feature -- Status report
feature {WSF_ROUTER} -- Mapping feature {WSF_ROUTER} -- Mapping
new_mapping (a_resource: READABLE_STRING_8): WSF_ROUTER_MAPPING on_mapped (a_mapping: WSF_ROUTER_MAPPING; a_rqst_methods: detachable WSF_ROUTER_METHODS)
-- New mapping built with Current as handler
deferred
ensure
Result /= Void and then Result.handler = Current
end
on_mapped (a_mapping: like new_mapping; a_rqst_methods: detachable WSF_ROUTER_METHODS)
-- Callback called when a router map a route to Current handler -- Callback called when a router map a route to Current handler
do do
end end

View File

@@ -59,17 +59,17 @@ feature -- Mapping
feature -- Mapping handler feature -- Mapping handler
handle (a_resource: READABLE_STRING_8; h: WSF_HANDLER) handle (a_resource: READABLE_STRING_8; f: WSF_ROUTER_MAPPING_FACTORY)
-- Map the mapping associated to handler `h' for resource `a_resource' -- Map the mapping created by factory `f' for resource `a_resource'
do do
handle_with_request_methods (a_resource, h, Void) handle_with_request_methods (a_resource, f, Void)
end end
handle_with_request_methods (a_resource: READABLE_STRING_8; h: WSF_HANDLER; rqst_methods: detachable WSF_ROUTER_METHODS) handle_with_request_methods (a_resource: READABLE_STRING_8; f: WSF_ROUTER_MAPPING_FACTORY; rqst_methods: detachable WSF_ROUTER_METHODS)
-- Map the mapping associated to handler `h' for resource `a_resource' -- Map the mapping created by factory `f' for resource `a_resource'
-- and only for request methods `rqst_methods' -- and only for request methods `rqst_methods'
do do
map_with_request_methods (h.new_mapping (a_resource), rqst_methods) map_with_request_methods (f.new_mapping (a_resource), rqst_methods)
end end
feature -- Access feature -- Access
@@ -220,6 +220,15 @@ feature -- Request methods helper
Result.lock Result.lock
end end
methods_get_put_delete: WSF_ROUTER_METHODS
once ("THREAD")
create Result.make (3)
Result.enable_get
Result.enable_put
Result.enable_delete
Result.lock
end
methods_head_get: WSF_ROUTER_METHODS methods_head_get: WSF_ROUTER_METHODS
once ("THREAD") once ("THREAD")
create Result.make (2) create Result.make (2)

View File

@@ -0,0 +1,32 @@
note
description: "[
Component that know how to create a router mapping from request and response.
Usually handler inherits from this classes, this way, it is easy to use WSF_ROUTER.handle_... (resource, handler, ..)
]"
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_ROUTER_MAPPING_FACTORY
feature {WSF_ROUTER} -- Mapping
new_mapping (a_uri: READABLE_STRING_8): WSF_ROUTER_MAPPING
-- New mapping object
deferred
ensure
Result_attached: Result /= Void
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

View File

@@ -0,0 +1,34 @@
note
description: "Summary description for {WSF_FILTER_CONTEXT_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_FILTER_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end, H -> WSF_CONTEXT_HANDLER [C]]
inherit
WSF_FILTER_HANDLER [H]
WSF_CONTEXT_HANDLER [C]
feature {NONE} -- Implementation
execute_next (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do
if attached next as n then
n.execute (ctx, req, res)
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