Added routing condition mapping.

Added WSF_EXECUTE_HANDLER as common ancestor for handler with `execute (WSF_REQUEST, WSF_RESPONSE) ..` routine.
Made more flexible a few routine by accepting ITERABLE instead of ARRAY, and READABLE_STRING_GENERAL when possible.
This commit is contained in:
Jocelyn Fiat
2017-11-03 17:59:10 +01:00
parent f770c236d5
commit 95cebe26bb
32 changed files with 822 additions and 186 deletions

View File

@@ -0,0 +1,43 @@
note
description: "Summary description for {WSF_ROUTING_AGENT_CONDITION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_ROUTING_AGENT_CONDITION
inherit
WSF_ROUTING_CONDITION
create
make
feature {NONE} -- Initialization
make (act: like condition)
do
condition := act
end
condition: FUNCTION [TUPLE [request: WSF_REQUEST], BOOLEAN]
feature -- Status report
accepted (req: WSF_REQUEST): BOOLEAN
-- Does `req` satisfy Current condition?
do
Result := condition (req)
end
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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,44 @@
note
description: "[
Request path info ends with one of the specified extensions.
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_ROUTING_EXTENSION_CONDITION
inherit
WSF_ROUTING_CONDITION
create
make
feature {NONE} -- Creation
make (a_extension_list: ITERABLE [READABLE_STRING_GENERAL])
do
extension_list := a_extension_list
end
feature -- Access
extension_list: ITERABLE [READABLE_STRING_GENERAL]
feature -- Status report
accepted (req: WSF_REQUEST): BOOLEAN
-- Does `req` satisfy Current condition?
local
l_path: READABLE_STRING_GENERAL
i: INTEGER
do
l_path := req.percent_encoded_path_info
i := l_path.last_index_of ('.', l_path.count)
if i > 0 then
i := i + 1
Result := across extension_list as ic some ic.item.same_caseless_characters (l_path, i, l_path.count, 1) end
end
end
end

View File

@@ -0,0 +1,39 @@
note
description: "[
Request path info is associated with existing file.
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_ROUTING_FILE_EXISTS_CONDITION
inherit
WSF_ROUTING_PATH_EXISTS_CONDITION
redefine
path_exists
end
create
make
feature -- Status report
path_exists (p: PATH): BOOLEAN
local
fut: FILE_UTILITIES
do
Result := fut.file_path_exists (p)
end
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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,64 @@
note
description: "[
Request path info is associated with existing file or folder.
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_ROUTING_PATH_EXISTS_CONDITION
inherit
WSF_ROUTING_CONDITION
create
make
feature {NONE} -- Creation
make (a_parent_location: PATH)
do
parent_location := a_parent_location
end
feature -- Access
parent_location: PATH
feature -- Status report
path_exists (p: PATH): BOOLEAN
local
fut: FILE_UTILITIES
do
Result := fut.file_path_exists (p) or fut.directory_path_exists (p)
end
accepted (req: WSF_REQUEST): BOOLEAN
-- Does `req` satisfy Current condition?
local
l_path: READABLE_STRING_GENERAL
p: PATH
fut: FILE_UTILITIES
do
l_path := req.path_info
if not l_path.is_empty then
if l_path[1] = '/' then
l_path := l_path.substring (2, l_path.count)
end
p := parent_location.extended (l_path)
Result := path_exists (p)
end
end
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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,43 @@
note
description: "Summary description for {WSF_ROUTING_AND_CONDITION}."
date: "$Date$"
revision: "$Revision$"
class
WSF_ROUTING_AND_CONDITION
inherit
WSF_ROUTING_CONDITION
create
make
feature {NONE} -- Creation
make (a_left, a_right: WSF_ROUTING_CONDITION)
do
left := a_left
right := a_right
end
left, right: WSF_ROUTING_CONDITION
feature -- Status report
accepted (req: WSF_REQUEST): BOOLEAN
-- Does `req` satisfy Current condition?
do
Result := left.accepted (req) and then right.accepted (req)
end
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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,39 @@
note
description: "Summary description for {WSF_ROUTING_CONDITION}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_ROUTING_CONDITION
feature -- Status report
accepted (req: WSF_REQUEST): BOOLEAN
-- Does `req` satisfy Current condition?
deferred
end
feature -- Factory
conjuncted alias "and" (cond: WSF_ROUTING_CONDITION): WSF_ROUTING_AND_CONDITION
do
create Result.make (Current, cond)
end
disjuncted alias "or" (cond: WSF_ROUTING_CONDITION): WSF_ROUTING_OR_CONDITION
do
create Result.make (Current, cond)
end
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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,43 @@
note
description: "Summary description for {WSF_ROUTING_OR_CONDITION}."
date: "$Date$"
revision: "$Revision$"
class
WSF_ROUTING_OR_CONDITION
inherit
WSF_ROUTING_CONDITION
create
make
feature {NONE} -- Creation
make (a_left, a_right: WSF_ROUTING_CONDITION)
do
left := a_left
right := a_right
end
left, right: WSF_ROUTING_CONDITION
feature -- Status report
accepted (req: WSF_REQUEST): BOOLEAN
-- Does `req` satisfy Current condition?
do
Result := left.accepted (req) or else right.accepted (req)
end
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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,22 @@
note
description: "Summary description for {WSF_WITH_CONDITION_HANDLER}."
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_WITH_CONDITION_HANDLER
inherit
WSF_EXECUTE_HANDLER
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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,44 @@
note
description: "Summary description for WSF_WITH_CONDITION_MAPPING."
date: "$Date$"
revision: "$Revision$"
class
WSF_WITH_CONDITION_MAPPING
inherit
WSF_WITH_CONDITION_MAPPING_I
create
make
feature -- Access
handler: WSF_EXECUTE_HANDLER
feature -- change
set_handler (h: like handler)
do
handler := h
end
feature {NONE} -- Execution
execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute handler `h' with `req' and `res' for Current mapping
do
h.execute (req, res)
end
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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,109 @@
note
description: "Summary description for WSF_WITH_CONDITION_MAPPING_I."
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_WITH_CONDITION_MAPPING_I
inherit
WSF_ROUTER_MAPPING
WSF_SELF_DOCUMENTED_ROUTER_MAPPING
feature {NONE} -- Initialization
make (a_condition: like condition; h: like handler)
do
set_handler (h)
condition := a_condition
end
feature -- Access
condition: WSF_ROUTING_CONDITION
associated_resource: READABLE_STRING_8
-- Name (URI, or URI template or regular expression or ...) of handled resource
do
if attached condition_description as desc and then desc.is_valid_as_string_8 then
Result := desc.to_string_8
else
Result := description
end
end
feature -- Access
condition_description: detachable READABLE_STRING_32
feature -- Element change
set_condition_description (desc: detachable READABLE_STRING_GENERAL)
do
if desc = Void then
condition_description := Void
else
condition_description := desc.as_string_32
end
end
set_handler (h: like handler)
-- Set `handler' to `h'.
require
h_attached: h /= Void
deferred
ensure
h_aliased: handler = h
end
feature -- Documentation
description: STRING_32 = "With-Condition"
feature -- Status
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
-- <Precursor>
do
Result := condition.accepted (req)
end
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
-- <Precursor>
do
if condition.accepted (req) then
sess.set_dispatched_handler (handler)
a_router.execute_before (Current)
execute_handler (handler, req, res)
a_router.execute_after (Current)
end
end
feature {NONE} -- Execution
execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute handler `h' with `req' and `res' for Current mapping.
require
h_attached: h /= Void
req_attached: req /= Void
res_attached: res /= Void
path_validate_condition: condition.accepted (req)
deferred
end
invariant
condition_attached: condition /= Void
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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