From cb034fc94e85523c26651b84c638807b2e984ff5 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 13 Dec 2012 10:58:08 +0100 Subject: [PATCH] Added missing "context" classes for uri and starts_with mapping+handler (and helper classes). So that it is address more needs. Factorized code between "context" and non context classes. --- .../wsf_starts_with_agent_context_handler.e | 45 +++++++ .../wsf_starts_with_context_routed_service.e | 47 +++++++ .../wsf_starts_with_routing_context_handler.e | 39 ++++++ .../wsf_starts_with_context_handler.e | 38 ++++++ .../wsf_starts_with_context_mapping.e | 64 ++++++++++ .../starts_with/wsf_starts_with_mapping.e | 59 ++------- .../starts_with/wsf_starts_with_mapping_i.e | 105 ++++++++++++++++ .../wsf_uri_agent_context_handler.e | 31 +++++ .../wsf_uri_context_routed_service.e | 47 +++++++ .../wsf_uri_routing_context_handler.e | 43 +++++++ .../support/uri/wsf_uri_context_handler.e | 32 +++++ .../support/uri/wsf_uri_context_mapping.e | 53 ++++++++ .../wsf/router/support/uri/wsf_uri_handler.e | 2 +- .../wsf/router/support/uri/wsf_uri_mapping.e | 73 ++--------- .../router/support/uri/wsf_uri_mapping_i.e | 117 ++++++++++++++++++ .../wsf_uri_template_agent_context_handler.e | 0 .../wsf_uri_template_context_routed_service.e | 2 +- ...sf_uri_template_filter_context_handler.e-} | 2 +- ...wsf_uri_template_routing_context_handler.e | 0 .../wsf_uri_template_context_handler.e | 2 +- .../wsf_uri_template_context_mapping.e | 53 ++++++++ .../uri_template/wsf_uri_template_handler.e | 2 +- .../uri_template/wsf_uri_template_mapping.e | 74 +---------- .../wsf_uri_template_mapping_i.e} | 55 ++++---- .../server/wsf/router/wsf_router_mapping.e | 5 + .../server/wsf/router/wsf_router_methods.e | 2 - tests/all-safe.ecf | 1 + 27 files changed, 778 insertions(+), 215 deletions(-) create mode 100644 library/server/wsf/router/support/starts_with/context_helpers/wsf_starts_with_agent_context_handler.e create mode 100644 library/server/wsf/router/support/starts_with/context_helpers/wsf_starts_with_context_routed_service.e create mode 100644 library/server/wsf/router/support/starts_with/context_helpers/wsf_starts_with_routing_context_handler.e create mode 100644 library/server/wsf/router/support/starts_with/wsf_starts_with_context_handler.e create mode 100644 library/server/wsf/router/support/starts_with/wsf_starts_with_context_mapping.e create mode 100644 library/server/wsf/router/support/starts_with/wsf_starts_with_mapping_i.e create mode 100644 library/server/wsf/router/support/uri/context_helpers/wsf_uri_agent_context_handler.e create mode 100644 library/server/wsf/router/support/uri/context_helpers/wsf_uri_context_routed_service.e create mode 100644 library/server/wsf/router/support/uri/context_helpers/wsf_uri_routing_context_handler.e create mode 100644 library/server/wsf/router/support/uri/wsf_uri_context_handler.e create mode 100644 library/server/wsf/router/support/uri/wsf_uri_context_mapping.e create mode 100644 library/server/wsf/router/support/uri/wsf_uri_mapping_i.e rename library/server/wsf/router/support/{uri_template_with_context/helpers => uri_template/context_helpers}/wsf_uri_template_agent_context_handler.e (100%) rename library/server/wsf/router/support/{uri_template_with_context/helpers => uri_template/context_helpers}/wsf_uri_template_context_routed_service.e (94%) rename library/server/wsf/router/support/{uri_template_with_context/helpers/wsf_uri_template_filter_context_handler.e => uri_template/context_helpers/wsf_uri_template_filter_context_handler.e-} (91%) rename library/server/wsf/router/support/{uri_template_with_context/helpers => uri_template/context_helpers}/wsf_uri_template_routing_context_handler.e (100%) rename library/server/wsf/router/support/{uri_template_with_context => uri_template}/wsf_uri_template_context_handler.e (90%) create mode 100644 library/server/wsf/router/support/uri_template/wsf_uri_template_context_mapping.e rename library/server/wsf/router/support/{uri_template_with_context/wsf_uri_template_context_mapping.e => uri_template/wsf_uri_template_mapping_i.e} (76%) diff --git a/library/server/wsf/router/support/starts_with/context_helpers/wsf_starts_with_agent_context_handler.e b/library/server/wsf/router/support/starts_with/context_helpers/wsf_starts_with_agent_context_handler.e new file mode 100644 index 00000000..861a6649 --- /dev/null +++ b/library/server/wsf/router/support/starts_with/context_helpers/wsf_starts_with_agent_context_handler.e @@ -0,0 +1,45 @@ +note + description: "Summary description for {WSF_STARTS_WITH_AGENT_CONTEXT_HANDLER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_STARTS_WITH_AGENT_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end] + +inherit + WSF_STARTS_WITH_CONTEXT_HANDLER [C] + +create + make + +feature -- Change + + make (a_action: like action) + do + action := a_action + end + +feature -- Access + + action: PROCEDURE [ANY, TUPLE [start_path: READABLE_STRING_8; context: C; request: WSF_REQUEST; response: WSF_RESPONSE]] + +feature -- Execution + + execute (a_start_path: READABLE_STRING_8; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE) + do + action.call ([a_start_path, ctx, req, res]) + end + + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/starts_with/context_helpers/wsf_starts_with_context_routed_service.e b/library/server/wsf/router/support/starts_with/context_helpers/wsf_starts_with_context_routed_service.e new file mode 100644 index 00000000..cb9abe30 --- /dev/null +++ b/library/server/wsf/router/support/starts_with/context_helpers/wsf_starts_with_context_routed_service.e @@ -0,0 +1,47 @@ +note + description: "Summary description for {WSF_STARTS_WITH_CONTEXT_ROUTED_SERVICE}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + WSF_STARTS_WITH_CONTEXT_ROUTED_SERVICE [C -> WSF_HANDLER_CONTEXT create make end] + +inherit + WSF_ROUTED_SERVICE + +feature -- Mapping helper: starts_with + + map_starts_with (a_uri: READABLE_STRING_8; h: WSF_STARTS_WITH_CONTEXT_HANDLER [C]) + do + map_starts_with_request_methods (a_uri, h, Void) + end + + map_starts_with_request_methods (a_uri: READABLE_STRING_8; h: WSF_STARTS_WITH_CONTEXT_HANDLER [C]; rqst_methods: detachable WSF_ROUTER_METHODS) + do + router.map_with_request_methods (create {WSF_STARTS_WITH_CONTEXT_MAPPING [C]}.make (a_uri, h), rqst_methods) + end + +feature -- Mapping helper: starts_with agent + + map_starts_with_agent (a_uri: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [start_path: READABLE_STRING_8; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]]) + do + map_starts_with_agent_with_request_methods (a_uri, proc, Void) + end + + map_starts_with_agent_with_request_methods (a_uri: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [start_path: READABLE_STRING_8; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_ROUTER_METHODS) + do + map_starts_with_request_methods (a_uri, create {WSF_STARTS_WITH_AGENT_CONTEXT_HANDLER [C] }.make (proc), rqst_methods) + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/starts_with/context_helpers/wsf_starts_with_routing_context_handler.e b/library/server/wsf/router/support/starts_with/context_helpers/wsf_starts_with_routing_context_handler.e new file mode 100644 index 00000000..74965647 --- /dev/null +++ b/library/server/wsf/router/support/starts_with/context_helpers/wsf_starts_with_routing_context_handler.e @@ -0,0 +1,39 @@ +note + description: "Summary description for {WSF_STARTS_WITH_ROUTING_CONTEXT_HANDLER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_STARTS_WITH_ROUTING_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end] + +inherit + WSF_ROUTING_HANDLER + + WSF_STARTS_WITH_CONTEXT_HANDLER [C] + rename + execute as execute_with_context + end + +create + make, + make_with_router + +feature -- Execution + + execute_with_context (a_start_path: READABLE_STRING_8; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE) + do + execute (req, res) + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/starts_with/wsf_starts_with_context_handler.e b/library/server/wsf/router/support/starts_with/wsf_starts_with_context_handler.e new file mode 100644 index 00000000..d22e719b --- /dev/null +++ b/library/server/wsf/router/support/starts_with/wsf_starts_with_context_handler.e @@ -0,0 +1,38 @@ +note + description: "Summary description for {WSF_STARTS_WITH_CONTEXT_HANDLER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + WSF_STARTS_WITH_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end] + +inherit + WSF_HANDLER + + WSF_ROUTER_MAPPING_FACTORY + +feature -- Execution + + execute (a_start_path: READABLE_STRING_8; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE) + deferred + end + +feature {WSF_ROUTER} -- Mapping + + new_mapping (a_uri: READABLE_STRING_8): WSF_ROUTER_MAPPING + do + create {WSF_STARTS_WITH_CONTEXT_MAPPING [C]} Result.make (a_uri, Current) + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/starts_with/wsf_starts_with_context_mapping.e b/library/server/wsf/router/support/starts_with/wsf_starts_with_context_mapping.e new file mode 100644 index 00000000..a43e19bb --- /dev/null +++ b/library/server/wsf/router/support/starts_with/wsf_starts_with_context_mapping.e @@ -0,0 +1,64 @@ +note + description: "Summary description for WSF_STARTS_WITH_CONTEXT_MAPPING." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_STARTS_WITH_CONTEXT_MAPPING [C -> WSF_HANDLER_CONTEXT create make end] + +inherit + WSF_STARTS_WITH_MAPPING_I + undefine + debug_output + end + + WSF_ROUTER_MAPPING + redefine + debug_output + end + +create + make + +feature -- Access + + handler: WSF_STARTS_WITH_CONTEXT_HANDLER [C] + +feature -- change + + set_handler (h: like handler) + do + handler := h + end + +feature {NONE} -- Execution + + execute_handler (h: like handler; a_start_path: like uri; req: WSF_REQUEST; res: WSF_RESPONSE) + -- Execute handler `h' with `req' and `res' for Current mapping + local + ctx: C + do + create ctx.make (req, Current) + h.execute (a_start_path, ctx, req, res) + end + +feature -- Status report + + debug_output: STRING + -- String that should be displayed in debugger to represent `Current'. + do + Result := Precursor + " {" + ({C}).name + "}" + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/starts_with/wsf_starts_with_mapping.e b/library/server/wsf/router/support/starts_with/wsf_starts_with_mapping.e index c152150e..4259f88d 100644 --- a/library/server/wsf/router/support/starts_with/wsf_starts_with_mapping.e +++ b/library/server/wsf/router/support/starts_with/wsf_starts_with_mapping.e @@ -1,5 +1,5 @@ note - description: "Summary description for EWF_STARTS_WITH_PATH." + description: "Summary description for WSF_STARTS_WITH_MAPPING." author: "" date: "$Date$" revision: "$Revision$" @@ -8,69 +8,28 @@ class WSF_STARTS_WITH_MAPPING inherit - WSF_ROUTER_MAPPING - - WSF_SELF_DOCUMENTED_ROUTER_MAPPING + WSF_STARTS_WITH_MAPPING_I create make -feature {NONE} -- Initialization - - make (a_uri: READABLE_STRING_8; h: like handler) - do - handler := h - uri := a_uri - end - feature -- Access - associated_resource: READABLE_STRING_8 - -- Associated resource - do - Result := uri - end - handler: WSF_STARTS_WITH_HANDLER - uri: READABLE_STRING_8 +feature -- change -feature -- Documentation - - description: STRING_32 = "Starts-With-URI" - -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 + set_handler (h: like handler) do - p := path_from_request (req) - s := based_uri (uri, a_router) - if p.starts_with (s) then - Result := handler - a_router.execute_before (Current) - handler.execute (s, req, res) - a_router.execute_after (Current) - end + handler := h end -feature {NONE} -- Implementation +feature {NONE} -- Execution - 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 + execute_handler (h: like handler; a_start_path: like uri; req: WSF_REQUEST; res: WSF_RESPONSE) + -- Execute handler `h' with `req' and `res' for Current mapping do - if attached a_router.base_url as l_base_url then - create s.make_from_string (l_base_url) - s.append_string (a_uri) - Result := s - else - Result := a_uri - end + h.execute (a_start_path, req, res) end note diff --git a/library/server/wsf/router/support/starts_with/wsf_starts_with_mapping_i.e b/library/server/wsf/router/support/starts_with/wsf_starts_with_mapping_i.e new file mode 100644 index 00000000..6346e9dc --- /dev/null +++ b/library/server/wsf/router/support/starts_with/wsf_starts_with_mapping_i.e @@ -0,0 +1,105 @@ +note + description: "Summary description for WSF_STARTS_WITH_MAPPING_I." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + WSF_STARTS_WITH_MAPPING_I + +inherit + WSF_ROUTER_MAPPING + + WSF_SELF_DOCUMENTED_ROUTER_MAPPING + +feature {NONE} -- Initialization + + make (a_uri: READABLE_STRING_8; h: like handler) + do + set_handler (h) + uri := a_uri + end + +feature -- Access + + associated_resource: READABLE_STRING_8 + -- Associated resource + do + Result := uri + end + + uri: READABLE_STRING_8 + +feature -- Change + + set_handler (h: like handler) + deferred + end + +feature -- Documentation + + description: STRING_32 = "Starts-With-URI" + +feature -- Status + + is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN + -- + local + p: READABLE_STRING_8 + s: like based_uri + do + p := path_from_request (req) + s := based_uri (uri, a_router) + Result := p.starts_with (s) + end + + 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 := path_from_request (req) + s := based_uri (uri, a_router) + if p.starts_with (s) then + Result := handler + a_router.execute_before (Current) + execute_handler (handler, s, req, res) + a_router.execute_after (Current) + end + end + +feature {NONE} -- Execution + + execute_handler (h: like handler; a_start_path: like uri; req: WSF_REQUEST; res: WSF_RESPONSE) + -- Execute handler `h' with `req' and `res' for Current mapping + deferred + end + +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 + if attached a_router.base_url as l_base_url then + create s.make_from_string (l_base_url) + s.append_string (a_uri) + Result := s + else + Result := a_uri + end + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/uri/context_helpers/wsf_uri_agent_context_handler.e b/library/server/wsf/router/support/uri/context_helpers/wsf_uri_agent_context_handler.e new file mode 100644 index 00000000..c1e07dcc --- /dev/null +++ b/library/server/wsf/router/support/uri/context_helpers/wsf_uri_agent_context_handler.e @@ -0,0 +1,31 @@ +note + description: "Summary description for {WSF_URI_AGENT_CONTEXT_HANDLER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_URI_AGENT_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end] + +inherit + WSF_URI_CONTEXT_HANDLER [C] + + WSF_AGENT_CONTEXT_HANDLER [C] + rename + set_action as make + end + +create + make + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/uri/context_helpers/wsf_uri_context_routed_service.e b/library/server/wsf/router/support/uri/context_helpers/wsf_uri_context_routed_service.e new file mode 100644 index 00000000..aed575c7 --- /dev/null +++ b/library/server/wsf/router/support/uri/context_helpers/wsf_uri_context_routed_service.e @@ -0,0 +1,47 @@ +note + description: "Summary description for {WSF_URI_CONTEXT_ROUTED_SERVICE}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + WSF_URI_CONTEXT_ROUTED_SERVICE [C -> WSF_HANDLER_CONTEXT create make end] + +inherit + WSF_ROUTED_SERVICE + +feature -- Mapping helper: uri + + map_uri (a_uri: READABLE_STRING_8; h: WSF_URI_CONTEXT_HANDLER [C]) + do + map_uri_with_request_methods (a_uri, h, Void) + end + + map_uri_with_request_methods (a_uri: READABLE_STRING_8; h: WSF_URI_CONTEXT_HANDLER [C]; rqst_methods: detachable WSF_ROUTER_METHODS) + do + router.map_with_request_methods (create {WSF_URI_CONTEXT_MAPPING [C]}.make (a_uri, h), rqst_methods) + end + +feature -- Mapping helper: uri agent + + map_uri_agent (a_uri: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]]) + do + map_uri_agent_with_request_methods (a_uri, proc, Void) + end + + map_uri_agent_with_request_methods (a_uri: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_ROUTER_METHODS) + do + map_uri_with_request_methods (a_uri, create {WSF_URI_AGENT_CONTEXT_HANDLER [C] }.make (proc), rqst_methods) + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/uri/context_helpers/wsf_uri_routing_context_handler.e b/library/server/wsf/router/support/uri/context_helpers/wsf_uri_routing_context_handler.e new file mode 100644 index 00000000..f76caf41 --- /dev/null +++ b/library/server/wsf/router/support/uri/context_helpers/wsf_uri_routing_context_handler.e @@ -0,0 +1,43 @@ +note + description: "Summary description for {WSF_URI_ROUTING_CONTEXT_HANDLER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_URI_ROUTING_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end] + +inherit + WSF_ROUTING_CONTEXT_HANDLER [C] + + WSF_URI_CONTEXT_HANDLER [C] + rename + execute as uri_execute + select + uri_execute + end + +create + make, + make_with_router + +feature -- Execution + + uri_execute (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE) + -- + --| For such routing handler, the previous context is lost + do + execute_with_context (ctx, req, res) + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/uri/wsf_uri_context_handler.e b/library/server/wsf/router/support/uri/wsf_uri_context_handler.e new file mode 100644 index 00000000..ae78b132 --- /dev/null +++ b/library/server/wsf/router/support/uri/wsf_uri_context_handler.e @@ -0,0 +1,32 @@ +note + description: "Summary description for {WSF_URI_CONTEXT_HANDLER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + WSF_URI_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end] + +inherit + WSF_CONTEXT_HANDLER [C] + + WSF_ROUTER_MAPPING_FACTORY + +feature {WSF_ROUTER} -- Mapping + + new_mapping (a_uri: READABLE_STRING_8): WSF_ROUTER_MAPPING + do + create {WSF_URI_CONTEXT_MAPPING [C]} Result.make (a_uri, Current) + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/uri/wsf_uri_context_mapping.e b/library/server/wsf/router/support/uri/wsf_uri_context_mapping.e new file mode 100644 index 00000000..de4cfa82 --- /dev/null +++ b/library/server/wsf/router/support/uri/wsf_uri_context_mapping.e @@ -0,0 +1,53 @@ +note + description: "Summary description for WSF_URI_CONTEXT_MAPPING." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_URI_CONTEXT_MAPPING [C -> WSF_HANDLER_CONTEXT create make end] + +inherit + WSF_URI_MAPPING_I + undefine + debug_output + end + + WSF_ROUTER_CONTEXT_MAPPING [C] + +create + make, + make_trailing_slash_ignored + +feature -- Access + + handler: WSF_URI_CONTEXT_HANDLER [C] + +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) + local + ctx: C + do + create ctx.make (req, Current) + h.execute (ctx, req, res) + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/uri/wsf_uri_handler.e b/library/server/wsf/router/support/uri/wsf_uri_handler.e index 9d0668fb..c73a3436 100644 --- a/library/server/wsf/router/support/uri/wsf_uri_handler.e +++ b/library/server/wsf/router/support/uri/wsf_uri_handler.e @@ -1,5 +1,5 @@ note - description: "Summary description for {EWF_ROUTER_URI_PATH_HANDLER}." + description: "Summary description for {WSF_URI_HANDLER}." author: "" date: "$Date$" revision: "$Revision$" diff --git a/library/server/wsf/router/support/uri/wsf_uri_mapping.e b/library/server/wsf/router/support/uri/wsf_uri_mapping.e index ce271b9e..849e7d8d 100644 --- a/library/server/wsf/router/support/uri/wsf_uri_mapping.e +++ b/library/server/wsf/router/support/uri/wsf_uri_mapping.e @@ -1,5 +1,5 @@ note - description: "Summary description for EWF_URI_PATH." + description: "Summary description for WSF_URI_MAPPING." author: "" date: "$Date$" revision: "$Revision$" @@ -8,85 +8,28 @@ class WSF_URI_MAPPING inherit - WSF_ROUTER_MAPPING - - WSF_SELF_DOCUMENTED_ROUTER_MAPPING + WSF_URI_MAPPING_I create make, make_trailing_slash_ignored -feature {NONE} -- Initialization - - make (a_uri: READABLE_STRING_8; h: like handler) - do - handler := h - uri := a_uri - end - - make_trailing_slash_ignored (a_uri: READABLE_STRING_8; h: like handler) - do - make (a_uri, h) - trailing_slash_ignored := True - end - feature -- Access - associated_resource: READABLE_STRING_8 - -- Associated resource - do - Result := uri - end - handler: WSF_URI_HANDLER - uri: READABLE_STRING_8 +feature -- Change - trailing_slash_ignored: BOOLEAN - -feature -- Documentation - - description: STRING_32 = "Is-URI" - -feature -- Status - - routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER - local - p: READABLE_STRING_8 - l_uri: like uri + set_handler (h: like handler) do - p := path_from_request (req) - l_uri := based_uri (uri, a_router) - if l_uri.ends_with ("/") then - if not p.ends_with ("/") then - p := p + "/" - end - else - if p.ends_with ("/") then - p := p.substring (1, p.count - 1) - end - end - if p.same_string (l_uri) then - Result := handler - a_router.execute_before (Current) - handler.execute (req, res) - a_router.execute_after (Current) - end + handler := h end -feature {NONE} -- Implementation +feature {NONE} -- Execution - based_uri (a_uri: like uri; a_router: WSF_ROUTER): like uri - local - s: STRING_8 + execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE) do - if attached a_router.base_url as l_base_url then - create s.make_from_string (l_base_url) - s.append_string (a_uri) - Result := s - else - Result := a_uri - end + h.execute (req, res) end note diff --git a/library/server/wsf/router/support/uri/wsf_uri_mapping_i.e b/library/server/wsf/router/support/uri/wsf_uri_mapping_i.e new file mode 100644 index 00000000..cac518fd --- /dev/null +++ b/library/server/wsf/router/support/uri/wsf_uri_mapping_i.e @@ -0,0 +1,117 @@ +note + description: "Summary description for {WSF_URI_MAPPING_I}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + WSF_URI_MAPPING_I + +inherit + WSF_ROUTER_MAPPING + + WSF_SELF_DOCUMENTED_ROUTER_MAPPING + +feature {NONE} -- Initialization + + make (a_uri: READABLE_STRING_8; h: like handler) + do + set_handler (h) + uri := a_uri + end + + make_trailing_slash_ignored (a_uri: READABLE_STRING_8; h: like handler) + do + make (a_uri, h) + trailing_slash_ignored := True + end + +feature -- Access + + associated_resource: READABLE_STRING_8 + -- Associated resource + do + Result := uri + end + + uri: READABLE_STRING_8 + + trailing_slash_ignored: BOOLEAN + +feature -- Change + + set_handler (h: like handler) + deferred + end + +feature -- Documentation + + description: STRING_32 = "Is-URI" + +feature -- Status + + is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN + -- + local + p: READABLE_STRING_8 + l_uri: like uri + do + p := path_from_request (req) + l_uri := based_uri (uri, a_router) + if l_uri.ends_with ("/") then + if not p.ends_with ("/") then + p := p + "/" + end + else + if p.ends_with ("/") then + p := p.substring (1, p.count - 1) + end + end + if p.same_string (l_uri) then + Result := True + end + end + + routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER + do + if is_mapping (req, a_router) then + Result := 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 + deferred + end + +feature {NONE} -- Implementation + + based_uri (a_uri: like uri; a_router: WSF_ROUTER): like uri + local + s: STRING_8 + do + if attached a_router.base_url as l_base_url then + create s.make_from_string (l_base_url) + s.append_string (a_uri) + Result := s + else + Result := a_uri + end + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/uri_template_with_context/helpers/wsf_uri_template_agent_context_handler.e b/library/server/wsf/router/support/uri_template/context_helpers/wsf_uri_template_agent_context_handler.e similarity index 100% rename from library/server/wsf/router/support/uri_template_with_context/helpers/wsf_uri_template_agent_context_handler.e rename to library/server/wsf/router/support/uri_template/context_helpers/wsf_uri_template_agent_context_handler.e diff --git a/library/server/wsf/router/support/uri_template_with_context/helpers/wsf_uri_template_context_routed_service.e b/library/server/wsf/router/support/uri_template/context_helpers/wsf_uri_template_context_routed_service.e similarity index 94% rename from library/server/wsf/router/support/uri_template_with_context/helpers/wsf_uri_template_context_routed_service.e rename to library/server/wsf/router/support/uri_template/context_helpers/wsf_uri_template_context_routed_service.e index 3e639613..46d75538 100644 --- a/library/server/wsf/router/support/uri_template_with_context/helpers/wsf_uri_template_context_routed_service.e +++ b/library/server/wsf/router/support/uri_template/context_helpers/wsf_uri_template_context_routed_service.e @@ -12,7 +12,7 @@ inherit feature -- Mapping helper: uri - map_uri_template (a_tpl: STRING; h: WSF_URI_TEMPLATE_CONTEXT_HANDLER [C]) + map_uri_template (a_tpl: READABLE_STRING_8; h: WSF_URI_TEMPLATE_CONTEXT_HANDLER [C]) do map_uri_template_with_request_methods (a_tpl, h, Void) end diff --git a/library/server/wsf/router/support/uri_template_with_context/helpers/wsf_uri_template_filter_context_handler.e b/library/server/wsf/router/support/uri_template/context_helpers/wsf_uri_template_filter_context_handler.e- similarity index 91% rename from library/server/wsf/router/support/uri_template_with_context/helpers/wsf_uri_template_filter_context_handler.e rename to library/server/wsf/router/support/uri_template/context_helpers/wsf_uri_template_filter_context_handler.e- index b6346fd6..b3d3ff6c 100644 --- a/library/server/wsf/router/support/uri_template_with_context/helpers/wsf_uri_template_filter_context_handler.e +++ b/library/server/wsf/router/support/uri_template/context_helpers/wsf_uri_template_filter_context_handler.e- @@ -1,5 +1,5 @@ note - description : "Objects that ..." + description: "Summary description for {WSF_URI_TEMPLATE_FILTER_CONTEXT_HANDLER}." author : "$Author$" date : "$Date$" revision : "$Revision$" diff --git a/library/server/wsf/router/support/uri_template_with_context/helpers/wsf_uri_template_routing_context_handler.e b/library/server/wsf/router/support/uri_template/context_helpers/wsf_uri_template_routing_context_handler.e similarity index 100% rename from library/server/wsf/router/support/uri_template_with_context/helpers/wsf_uri_template_routing_context_handler.e rename to library/server/wsf/router/support/uri_template/context_helpers/wsf_uri_template_routing_context_handler.e diff --git a/library/server/wsf/router/support/uri_template_with_context/wsf_uri_template_context_handler.e b/library/server/wsf/router/support/uri_template/wsf_uri_template_context_handler.e similarity index 90% rename from library/server/wsf/router/support/uri_template_with_context/wsf_uri_template_context_handler.e rename to library/server/wsf/router/support/uri_template/wsf_uri_template_context_handler.e index f8a76249..20e80998 100644 --- a/library/server/wsf/router/support/uri_template_with_context/wsf_uri_template_context_handler.e +++ b/library/server/wsf/router/support/uri_template/wsf_uri_template_context_handler.e @@ -1,5 +1,5 @@ note - description: "Summary description for EWF_URI_TEMPLATE_WITH_CONTEXT_HANDLER." + description: "Summary description for WSF_URI_TEMPLATE_CONTEXT_HANDLER." author: "" date: "$Date$" revision: "$Revision$" diff --git a/library/server/wsf/router/support/uri_template/wsf_uri_template_context_mapping.e b/library/server/wsf/router/support/uri_template/wsf_uri_template_context_mapping.e new file mode 100644 index 00000000..c32ca08d --- /dev/null +++ b/library/server/wsf/router/support/uri_template/wsf_uri_template_context_mapping.e @@ -0,0 +1,53 @@ +note + description: "Summary description for {WSF_URI_TEMPLATE_CONTEXT_MAPPING}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_URI_TEMPLATE_CONTEXT_MAPPING [C -> WSF_HANDLER_CONTEXT create make end] + +inherit + WSF_URI_TEMPLATE_MAPPING_I + undefine + debug_output + end + + WSF_ROUTER_CONTEXT_MAPPING [C] + +create + make, + make_from_template + +feature -- Access + + handler: WSF_URI_TEMPLATE_CONTEXT_HANDLER [C] + +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) + local + ctx: detachable C + do + create ctx.make (req, Current) + h.execute (ctx, req, res) + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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/support/uri_template/wsf_uri_template_handler.e b/library/server/wsf/router/support/uri_template/wsf_uri_template_handler.e index f6fe1e4e..e049154d 100644 --- a/library/server/wsf/router/support/uri_template/wsf_uri_template_handler.e +++ b/library/server/wsf/router/support/uri_template/wsf_uri_template_handler.e @@ -1,5 +1,5 @@ note - description: "Summary description for EWF_URI_TEMPLATE_HANDLER." + description: "Summary description for WSF_URI_TEMPLATE_HANDLER." author: "" date: "$Date$" revision: "$Revision$" diff --git a/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping.e b/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping.e index eb090784..5fc830fa 100644 --- a/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping.e +++ b/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping.e @@ -1,5 +1,5 @@ note - description: "Summary description for {EWF_ROUTER_URI_TEMPLATE_PATH}." + description: "Summary description for {WSF_URI_TEMPLATE_MAPPING}." author: "" date: "$Date$" revision: "$Revision$" @@ -8,92 +8,30 @@ class WSF_URI_TEMPLATE_MAPPING inherit - WSF_ROUTER_MAPPING - - WSF_SELF_DOCUMENTED_ROUTER_MAPPING + WSF_URI_TEMPLATE_MAPPING_I create make, make_from_template -feature {NONE} -- Initialization - - make (s: READABLE_STRING_8; h: like handler) - do - make_from_template (create {URI_TEMPLATE}.make (s), h) - end - - make_from_template (tpl: URI_TEMPLATE; h: like handler) - do - template := tpl - handler := h - end - feature -- Access - associated_resource: READABLE_STRING_8 - -- Associated resource - do - Result := template.template - end - handler: WSF_URI_TEMPLATE_HANDLER - template: URI_TEMPLATE - -feature -- Documentation - - description: STRING_32 = "Match-URI-Template" - -feature -- Element change +feature -- Change set_handler (h: like handler) do handler := h end -feature -- Status +feature {NONE} -- Execution - routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER - local - tpl: URI_TEMPLATE - p: READABLE_STRING_32 - new_src: detachable WSF_REQUEST_PATH_PARAMETERS_PROVIDER + execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE) do - p := path_from_request (req) - tpl := based_uri_template (template, a_router) - if attached tpl.match (p) as tpl_res then - Result := handler - a_router.execute_before (Current) - --| Applied the context to the request - --| in practice, this will fill the {WSF_REQUEST}.path_parameters - create new_src.make (tpl_res.path_variables.count, tpl_res.path_variables) - new_src.apply (req) - handler.execute (req, res) - --| Revert {WSF_REQUEST}.path_parameters_source to former value - --| In case the request object passed by other handler that alters its values. - new_src.revert (req) - a_router.execute_after (Current) - end - rescue - if new_src /= Void then - new_src.revert (req) - end + h.execute (req, res) end -feature {NONE} -- Implementation - - based_uri_template (a_tpl: like template; a_router: WSF_ROUTER): like template - do - if attached a_router.base_url as l_base_url then - Result := a_tpl.duplicate - Result.set_template (l_base_url + a_tpl.template) - else - Result := a_tpl - end - end - - note copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" diff --git a/library/server/wsf/router/support/uri_template_with_context/wsf_uri_template_context_mapping.e b/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping_i.e similarity index 76% rename from library/server/wsf/router/support/uri_template_with_context/wsf_uri_template_context_mapping.e rename to library/server/wsf/router/support/uri_template/wsf_uri_template_mapping_i.e index 98f27adf..3abf5f66 100644 --- a/library/server/wsf/router/support/uri_template_with_context/wsf_uri_template_context_mapping.e +++ b/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping_i.e @@ -1,23 +1,16 @@ note - description: "Summary description for {WSF_URI_TEMPLATE_CONTEXT_MAPPING}." + description: "Summary description for {WSF_URI_TEMPLATE_MAPPING_I}." author: "" date: "$Date$" revision: "$Revision$" -class - WSF_URI_TEMPLATE_CONTEXT_MAPPING [C -> WSF_HANDLER_CONTEXT create make end] +deferred class + WSF_URI_TEMPLATE_MAPPING_I inherit - WSF_ROUTER_CONTEXT_MAPPING [C] + WSF_ROUTER_MAPPING WSF_SELF_DOCUMENTED_ROUTER_MAPPING - undefine - debug_output - end - -create - make, - make_from_template feature {NONE} -- Initialization @@ -29,7 +22,7 @@ feature {NONE} -- Initialization make_from_template (tpl: URI_TEMPLATE; h: like handler) do template := tpl - handler := h + set_handler (h) end feature -- Access @@ -40,41 +33,47 @@ feature -- Access Result := template.template end - handler: WSF_URI_TEMPLATE_CONTEXT_HANDLER [C] - template: URI_TEMPLATE +feature -- Change + + set_handler (h: like handler) + deferred + end + feature -- Documentation description: STRING_32 = "Match-URI-Template" -feature -- Element change - - set_handler (h: like handler) - do - handler := h - end - feature -- Status + is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN + -- + local + tpl: URI_TEMPLATE + p: READABLE_STRING_32 + do + p := path_from_request (req) + tpl := based_uri_template (template, a_router) + Result := tpl.match (p) /= Void + end + routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER local tpl: URI_TEMPLATE p: READABLE_STRING_32 - ctx: detachable C new_src: detachable WSF_REQUEST_PATH_PARAMETERS_PROVIDER do 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, Current) a_router.execute_before (Current) --| Applied the context to the request --| in practice, this will fill the {WSF_REQUEST}.path_parameters create new_src.make (tpl_res.path_variables.count, tpl_res.path_variables) new_src.apply (req) - handler.execute (ctx, req, res) + execute_handler (handler, req, res) --| Revert {WSF_REQUEST}.path_parameters_source to former value --| In case the request object passed by other handler that alters its values. new_src.revert (req) @@ -86,6 +85,13 @@ feature -- Status 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 + deferred + end + feature {NONE} -- Implementation based_uri_template (a_tpl: like template; a_router: WSF_ROUTER): like template @@ -98,7 +104,6 @@ feature {NONE} -- Implementation end end - note copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" diff --git a/library/server/wsf/router/wsf_router_mapping.e b/library/server/wsf/router/wsf_router_mapping.e index 5cc0efff..de7ae56e 100644 --- a/library/server/wsf/router/wsf_router_mapping.e +++ b/library/server/wsf/router/wsf_router_mapping.e @@ -46,6 +46,11 @@ feature -- Status report feature -- Status + is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN + -- Does Current accept `req'? + deferred + end + 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 diff --git a/library/server/wsf/router/wsf_router_methods.e b/library/server/wsf/router/wsf_router_methods.e index 6861d669..d0577775 100644 --- a/library/server/wsf/router/wsf_router_methods.e +++ b/library/server/wsf/router/wsf_router_methods.e @@ -120,8 +120,6 @@ feature -- Basic operations do create Result.make_from_iterable (Current) Result.add_methods (a_other) - ensure - end feature -- Element change diff --git a/tests/all-safe.ecf b/tests/all-safe.ecf index 98fb312d..d7bfa2c9 100644 --- a/tests/all-safe.ecf +++ b/tests/all-safe.ecf @@ -22,6 +22,7 @@ +