Added WSF_RESPONSE_HANDLER based on WSF_RESPONSE_MESSAGE
The descendant has to implement the function
response (ctx: C; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
Added related features and class in WSF_ROUTER to be able to use agent easily.
This commit is contained in:
@@ -10,12 +10,12 @@ class
|
||||
inherit
|
||||
WSF_URI_ROUTER_I [WSF_HANDLER [WSF_URI_HANDLER_CONTEXT], WSF_URI_HANDLER_CONTEXT]
|
||||
redefine
|
||||
map_agent_with_request_methods
|
||||
map_agent_with_request_methods, map_agent_response_with_request_methods
|
||||
end
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Mapping
|
||||
feature -- Mapping agent
|
||||
|
||||
map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: WSF_URI_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE]];
|
||||
rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||
@@ -26,6 +26,15 @@ feature -- Mapping
|
||||
map_with_request_methods (a_id, h, rqst_methods)
|
||||
end
|
||||
|
||||
map_agent_response_with_request_methods (a_id: READABLE_STRING_8; a_action: FUNCTION [ANY, TUPLE [ctx: WSF_URI_HANDLER_CONTEXT; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE];
|
||||
rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||
local
|
||||
h: WSF_AGENT_RESPONSE_HANDLER [WSF_URI_HANDLER_CONTEXT]
|
||||
do
|
||||
create h.make (a_action)
|
||||
map_with_request_methods (a_id, h, rqst_methods)
|
||||
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)"
|
||||
|
||||
@@ -10,14 +10,15 @@ class
|
||||
inherit
|
||||
WSF_URI_TEMPLATE_ROUTER_I [WSF_HANDLER [WSF_URI_TEMPLATE_HANDLER_CONTEXT], WSF_URI_TEMPLATE_HANDLER_CONTEXT]
|
||||
redefine
|
||||
map_agent_with_request_methods
|
||||
map_agent_with_request_methods,
|
||||
map_agent_response_with_request_methods
|
||||
end
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_base_url
|
||||
|
||||
feature -- Mapping
|
||||
feature -- Mapping agent
|
||||
|
||||
map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE]];
|
||||
rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||
@@ -28,6 +29,15 @@ feature -- Mapping
|
||||
map_with_request_methods (a_id, h, rqst_methods)
|
||||
end
|
||||
|
||||
map_agent_response_with_request_methods (a_id: READABLE_STRING_8; a_action: FUNCTION [ANY, TUPLE [ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE];
|
||||
rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||
local
|
||||
h: WSF_AGENT_RESPONSE_HANDLER [WSF_URI_TEMPLATE_HANDLER_CONTEXT]
|
||||
do
|
||||
create h.make (a_action)
|
||||
map_with_request_methods (a_id, h, rqst_methods)
|
||||
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)"
|
||||
|
||||
43
library/server/wsf/router/wsf_agent_response_handler.e
Normal file
43
library/server/wsf/router/wsf_agent_response_handler.e
Normal file
@@ -0,0 +1,43 @@
|
||||
note
|
||||
description: "Summary description for WSF_AGENT_RESPONSE_HANDLER."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_AGENT_RESPONSE_HANDLER [C -> WSF_HANDLER_CONTEXT]
|
||||
|
||||
inherit
|
||||
WSF_RESPONSE_HANDLER [C]
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make (act: like action)
|
||||
do
|
||||
action := act
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
action: FUNCTION [ANY, TUPLE [ctx: C; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE]
|
||||
|
||||
feature -- Execution
|
||||
|
||||
response (ctx: C; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
|
||||
do
|
||||
Result := action.item ([ctx, req])
|
||||
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
|
||||
48
library/server/wsf/router/wsf_response_handler.e
Normal file
48
library/server/wsf/router/wsf_response_handler.e
Normal file
@@ -0,0 +1,48 @@
|
||||
note
|
||||
description: "[
|
||||
Request handler object which is called by a WSF_ROUTER
|
||||
A response handler should implement the method
|
||||
|
||||
response (ctx: C; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
|
||||
|
||||
|
||||
The class is generic, this way one can use a custom WSF_HANDLER_CONTEXT if needed
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_RESPONSE_HANDLER [C -> WSF_HANDLER_CONTEXT]
|
||||
|
||||
inherit
|
||||
WSF_HANDLER [C]
|
||||
|
||||
feature -- Execution
|
||||
|
||||
response (ctx: C; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
|
||||
require
|
||||
is_valid_context: is_valid_context (req)
|
||||
deferred
|
||||
ensure
|
||||
Result_attached: Result /= Void
|
||||
end
|
||||
|
||||
feature -- Implementation
|
||||
|
||||
execute (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute request handler
|
||||
do
|
||||
response (ctx, req).send_to (res)
|
||||
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
|
||||
@@ -58,6 +58,8 @@ feature -- Mapping
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Mapping agent
|
||||
|
||||
map_agent (a_resource: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]])
|
||||
do
|
||||
map_agent_with_request_methods (a_resource, a_action, Void)
|
||||
@@ -76,6 +78,26 @@ feature -- Mapping
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Mapping response agent
|
||||
|
||||
map_agent_response (a_resource: READABLE_STRING_8; a_action: FUNCTION [ANY, TUPLE [ctx: C; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE])
|
||||
do
|
||||
map_agent_response_with_request_methods (a_resource, a_action, Void)
|
||||
end
|
||||
|
||||
map_agent_response_with_request_methods (a_resource: READABLE_STRING_8; a_action: FUNCTION [ANY, TUPLE [ctx: C; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE];
|
||||
rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||
local
|
||||
rah: WSF_AGENT_RESPONSE_HANDLER [C]
|
||||
do
|
||||
create rah.make (a_action)
|
||||
if attached {H} rah as h then
|
||||
map_with_request_methods (a_resource, h, rqst_methods)
|
||||
else
|
||||
check valid_agent_handler: False end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Base url
|
||||
|
||||
base_url: detachable READABLE_STRING_8
|
||||
|
||||
Reference in New Issue
Block a user