moved wsf_extension inside wsf/extension as wsf/wsf_extension.ecf

added wsf/session as wsf/wsf_session.ecf
In descendants of WSF_HANDLER , we can keep the result of new_mapping as WSF_ROUTER_MAPPING
This commit is contained in:
Jocelyn Fiat
2012-09-28 14:42:31 +02:00
parent 80c1cc1c0d
commit 291bb3a33b
20 changed files with 573 additions and 20 deletions

View File

@@ -0,0 +1,96 @@
note
description: "[
Provides a few helpful feature to respond predefined message to the client
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_HANDLER_HELPER
inherit
ANY
feature -- Helper
execute_content_type_not_allowed (req: WSF_REQUEST; res: WSF_RESPONSE; a_content_types: detachable ARRAY [STRING]; a_uri_formats: detachable ARRAY [STRING])
local
accept_s, uri_s: detachable STRING
i, n: INTEGER
do
if a_content_types /= Void then
create accept_s.make (10)
from
i := a_content_types.lower
n := a_content_types.upper
until
i > n
loop
accept_s.append_string (a_content_types[i])
if i < n then
accept_s.append_character (',')
accept_s.append_character (' ')
end
i := i + 1
end
else
accept_s := "*/*"
end
if a_uri_formats /= Void then
create uri_s.make (10)
from
i := a_uri_formats.lower
n := a_uri_formats.upper
until
i > n
loop
uri_s.append_string (a_uri_formats[i])
if i < n then
uri_s.append_character (',')
uri_s.append_character (' ')
end
i := i + 1
end
end
res.put_header ({HTTP_STATUS_CODE}.unsupported_media_type, << ["Content-Type", "text/plain"], ["Accept", accept_s]>>)
if accept_s /= Void then
res.put_string ("Unsupported request content-type, Accept: " + accept_s + "%N")
end
if uri_s /= Void then
res.put_string ("Unsupported request format from the URI: " + uri_s + "%N")
end
end
execute_request_method_not_allowed (req: WSF_REQUEST; res: WSF_RESPONSE; a_methods: ITERABLE [STRING])
local
s: STRING
do
create s.make (25)
across
a_methods as c
loop
if not s.is_empty then
s.append_character (',')
s.append_character (' ')
end
s.append_string (c.item)
end
res.put_header ({HTTP_STATUS_CODE}.method_not_allowed, <<
["Content-Type", {HTTP_MIME_TYPES}.text_plain],
["Allow", s]
>>)
res.put_string ("Unsupported request method, Allow: " + s + "%N")
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,44 @@
note
description: "[
Summary description for WSF_HANDLER_ROUTES_RECORDER.
You can inherit from this class from any WSF_HANDLER and redefine `on_handler_mapped'
to record the available routes if your handler needs it.
]"
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_HANDLER_ROUTES_RECORDER
feature {WSF_HANDLER} -- Routes access
available_routes: detachable LIST [TUPLE [resource: READABLE_STRING_8; rqst_methods: detachable ARRAY [READABLE_STRING_8]]]
-- Available routes
feature {WSF_ROUTER} -- Routes change
on_handler_mapped (a_resource: READABLE_STRING_8; a_rqst_methods: detachable ARRAY [READABLE_STRING_8])
local
l_routes: like available_routes
do
l_routes := available_routes
if l_routes = Void then
create {ARRAYED_LIST [like available_routes.item]} l_routes.make (3)
available_routes := l_routes
end
l_routes.force ([a_resource, a_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)"
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,112 @@
note
description: "Summary description for {WSF_REQUEST_UTILITY}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_REQUEST_UTILITY
inherit
ANY
WSF_FORMAT_UTILITY
export
{NONE} all
end
WSF_VALUE_UTILITY
feature -- Url Query
script_absolute_url (req: WSF_REQUEST; a_path: STRING): STRING
-- Absolute Url for the script if any, extended by `a_path'
do
Result := req.absolute_script_url (a_path)
end
script_url (req: WSF_REQUEST; a_path: STRING): STRING
-- Url relative to script name if any, extended by `a_path'
require
a_path_attached: a_path /= Void
do
Result := req.script_url (a_path)
end
url (req: WSF_REQUEST; a_path: STRING; args: detachable STRING; abs: BOOLEAN): STRING
-- Associated url based on `path' and `args'
-- if `abs' then return absolute url
local
s,t: detachable STRING
do
s := args
if s /= Void and then s.count > 0 then
create t.make_from_string (a_path)
if s[1] /= '/' and t[t.count] /= '/' then
t.append_character ('/')
t.append (s)
else
t.append (s)
end
s := t
else
s := a_path
end
if abs then
Result := script_absolute_url (req, s)
else
Result := script_url (req, s)
end
ensure
result_attached: Result /= Void
end
feature -- Query
request_accepted_content_type (req: WSF_REQUEST; a_supported_content_types: detachable ARRAY [READABLE_STRING_8]): detachable READABLE_STRING_8
-- Accepted content-type for the request, among the supported content types `a_supported_content_types'
local
s: detachable READABLE_STRING_8
i,n: INTEGER
do
if
attached accepted_content_types (req) as l_accept_lst and then
not l_accept_lst.is_empty
then
from
l_accept_lst.start
until
l_accept_lst.after or Result /= Void
loop
s := l_accept_lst.item
if a_supported_content_types /= Void then
from
i := a_supported_content_types.lower
n := a_supported_content_types.upper
until
i > n or Result /= Void
loop
if a_supported_content_types [i].same_string (s) then
Result := s
end
i := i + 1
end
else
Result := s
end
l_accept_lst.forth
end
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

View File

@@ -0,0 +1,328 @@
note
description: "Work in progress Common abstraction to handle RESTfull methods"
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_RESOURCE_HANDLER_HELPER
feature -- Execute template
execute_methods (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request and dispatch according to the request method
local
m: READABLE_STRING_8
do
m := req.request_method.as_upper
if m.same_string ({HTTP_REQUEST_METHODS}.method_get) then
execute_get (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_put) then
execute_put (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_delete) then
execute_delete (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_post) then
execute_post (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_trace) then
execute_trace (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_options) then
execute_options (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_head) then
execute_head (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_connect) then
execute_connect (req, res)
else
--| Eventually handle other methods...
execute_extension_method (req, res)
end
end
feature -- Method Post
execute_post (req: WSF_REQUEST; res: WSF_RESPONSE)
do
if req.is_chunked_input then
do_post (req, res)
else
if req.content_length_value > 0 then
do_post (req, res)
else
handle_bad_request_response ("Bad request, content_length empty", req, res)
end
end
end
do_post (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method POST not implemented", req, res)
end
feature-- Method Put
execute_put (req: WSF_REQUEST; res: WSF_RESPONSE)
do
if req.is_chunked_input then
do_put (req, res)
else
if req.content_length_value > 0 then
do_put (req, res)
else
handle_bad_request_response ("Bad request, content_length empty", req, res)
end
end
end
do_put (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method PUT not implemented", req, res)
end
feature -- Method Get
execute_get (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_get (req, res)
end
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method GET not implemented", req, res)
end
feature -- Method DELETE
execute_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_delete (req, res)
end
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method DELETE not implemented", req, res)
end
feature -- Method CONNECT
execute_connect (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_connect (req, res)
end
do_connect (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method CONNECT not implemented", req, res)
end
feature -- Method HEAD
execute_head (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_head (req, res)
end
do_head (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method HEAD not implemented", req, res)
end
feature -- Method OPTIONS
execute_options (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_options (req, res)
end
do_options (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method OPTIONS not implemented", req, res)
end
feature -- Method TRACE
execute_trace (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_trace (req, res)
end
do_trace (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method TRACE not implemented", req, res)
end
feature -- Method Extension Method
execute_extension_method (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_extension_method (req, res)
end
do_extension_method (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method extension-method not implemented", req, res)
end
feature -- Retrieve content from WGI_INPUT_STREAM
retrieve_data ( req : WSF_REQUEST) : STRING
-- retrieve the content from the input stream
-- handle differents transfers
local
l_input: WGI_INPUT_STREAM
n: INTEGER
s: STRING
do
if req.is_chunked_input then
l_input := req.input
from
n := 1_024
create Result.make (n)
until
n = 0
loop
l_input.read_string (n)
s := l_input.last_string
if s.count = 0 then
n := 0
else
if s.count < n then
n := 0
end
Result.append (s)
end
end
else
req.input.read_string (req.content_length_value.as_integer_32)
Result := req.input.last_string
end
end
feature -- Handle responses
-- TODO Handle Content negotiation.
-- The option : Server-driven negotiation: uses request headers to select a variant
-- More info : http://www.w3.org/Protocols/rfc2616/rfc2616-sec12.html#sec12
supported_content_types: detachable ARRAY [READABLE_STRING_8]
-- Supported content types
-- Can be redefined
do
Result := Void
end
handle_bad_request_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
local
h : HTTP_HEADER
do
create h.make
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.bad_request)
res.put_header_text (h.string)
res.put_string (a_description)
end
handle_precondition_fail_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
local
h : HTTP_HEADER
do
create h.make
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.precondition_failed)
res.put_header_text (h.string)
res.put_string (a_description)
end
handle_internal_server_error (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
local
h : HTTP_HEADER
do
create h.make
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.internal_server_error)
res.put_header_text (h.string)
res.put_string (a_description)
end
handle_not_implemented (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
local
h : HTTP_HEADER
do
create h.make
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.not_implemented)
res.put_header_text (h.string)
res.put_string (a_description)
end
handle_method_not_allowed_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : HTTP_HEADER
do
create h.make
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.method_not_allowed)
res.put_header_text (h.string)
res.put_string (a_description)
end
handle_resource_not_found_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : HTTP_HEADER
do
create h.make
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.not_found)
res.put_header_text (h.string)
res.put_string (a_description)
end
handle_resource_not_modified_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : HTTP_HEADER
do
res.flush
create h.make
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.not_modified)
res.put_header_text (h.string)
res.put_string (a_description)
end
handle_resource_conflict_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : HTTP_HEADER
do
create h.make
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.conflict)
res.put_header_text (h.string)
res.put_string (a_description)
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,156 @@
note
description: "Summary description for {WSF_VALUE_UTILITY}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_VALUE_UTILITY
feature -- Parameter
item (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
-- Variable value for parameter or variable `a_name'
-- See `{WSF_REQUEST}.item(s)'
do
Result := req.item (a_name)
end
string_item (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
-- String value for any variable of parameter `a_name' if relevant.
do
Result := string_from (item (req, a_name))
end
string_array_item (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable ARRAY [READABLE_STRING_32]
-- Array of string values for query parameter `a_name' if relevant.
do
Result := string_array_for (req, a_name, agent string_item)
end
feature -- Query parameter
query_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
-- Parameter value for query variable `a_name'
--| i.e after the ? character
do
Result := req.query_parameter (a_name)
end
string_query_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
-- String value for query parameter `a_name' if relevant.
do
Result := string_from (query_parameter (req, a_name))
end
string_array_query_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable ARRAY [READABLE_STRING_32]
-- Array of string values for query parameter `a_name' if relevant.
do
Result := string_array_for (req, a_name, agent string_query_parameter)
end
is_integer_query_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): BOOLEAN
-- Is query parameter related to `a_name' an integer value?
do
Result := attached string_query_parameter (req, a_name) as s and then s.is_integer
end
integer_query_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): INTEGER
-- Integer value for query parameter `a_name' if relevant.
require
is_integer_query_parameter: is_integer_query_parameter (req, a_name)
do
Result := integer_from (query_parameter (req, a_name))
end
feature -- Path parameter
path_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
do
Result := req.path_parameter (a_name)
end
string_path_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
-- String value for path parameter `a_name' if relevant.
do
Result := string_from (path_parameter (req, a_name))
end
string_array_path_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable ARRAY [READABLE_STRING_32]
-- Array of string values for path parameter `a_name' if relevant.
do
Result := string_array_for (req, a_name, agent string_path_parameter)
end
is_integer_path_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): BOOLEAN
-- Is path parameter related to `a_name' an integer value?
do
Result := attached string_path_parameter (req, a_name) as s and then s.is_integer
end
integer_path_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): INTEGER
-- Integer value for path parameter `a_name' if relevant.
require
is_integer_path_parameter: is_integer_path_parameter (req, a_name)
do
Result := integer_from (path_parameter (req, a_name))
end
feature -- Convertion
string_from (a_value: detachable WSF_VALUE): detachable READABLE_STRING_32
-- String value from `a_value' if relevant.
do
if attached {WSF_STRING} a_value as val then
Result := val.value
end
end
integer_from (a_value: detachable WSF_VALUE): INTEGER
-- String value from `a_value' if relevant.
do
if attached string_from (a_value) as val then
if val.is_integer then
Result := val.to_integer
end
end
end
feature {NONE} -- Implementation
string_array_for (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL; a_item_fct: FUNCTION [ANY, TUPLE [WSF_REQUEST, READABLE_STRING_GENERAL], detachable READABLE_STRING_32]): detachable ARRAY [READABLE_STRING_32]
-- Array of string values for query parameter `a_name' if relevant.
local
i: INTEGER
n: INTEGER
do
from
i := 1
n := 1
create Result.make_filled ("", 1, 5)
until
i = 0
loop
if attached a_item_fct.item ([req, a_name + "[" + i.out + "]"]) as v then
Result.force (v, n)
n := n + 1
i := i + 1
else
i := 0 -- Exit
end
end
Result.keep_head (n - 1)
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

@@ -18,9 +18,9 @@ feature -- Execution
feature {WSF_ROUTER} -- Mapping
new_mapping (a_uri: READABLE_STRING_8): WSF_STARTS_WITH_MAPPING
new_mapping (a_uri: READABLE_STRING_8): WSF_ROUTER_MAPPING
do
create Result.make (a_uri, Current)
create {WSF_STARTS_WITH_MAPPING} Result.make (a_uri, Current)
end
note

View File

@@ -18,9 +18,9 @@ feature -- Execution
feature {WSF_ROUTER} -- Mapping
new_mapping (a_uri: READABLE_STRING_8): WSF_URI_MAPPING
new_mapping (a_uri: READABLE_STRING_8): WSF_ROUTER_MAPPING
do
create Result.make (a_uri, Current)
create {WSF_URI_MAPPING} Result.make (a_uri, Current)
end
note

View File

@@ -18,9 +18,9 @@ feature -- Execution
feature {WSF_ROUTER} -- Mapping
new_mapping (a_tpl: READABLE_STRING_8): WSF_URI_TEMPLATE_MAPPING
new_mapping (a_tpl: READABLE_STRING_8): WSF_ROUTER_MAPPING
do
create Result.make (a_tpl, Current)
create {WSF_URI_TEMPLATE_MAPPING} Result.make (a_tpl, Current)
end
note

View File

@@ -12,9 +12,9 @@ inherit
feature {WSF_ROUTER} -- Mapping
new_mapping (a_tpl: READABLE_STRING_8): WSF_URI_TEMPLATE_CONTEXT_MAPPING [C]
new_mapping (a_tpl: READABLE_STRING_8): WSF_ROUTER_MAPPING
do
create Result.make (a_tpl, Current)
create {WSF_URI_TEMPLATE_CONTEXT_MAPPING [C]} Result.make (a_tpl, Current)
end
note

View File

@@ -0,0 +1,193 @@
note
description: "Summary description for {WSF_SESSION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_COOKIE_SESSION
inherit
WSF_SESSION
create
make,
make_new
feature {NONE} -- Initialization
make (req: WSF_REQUEST; a_cookie_name: detachable like cookie_name; a_manager: WSF_SESSION_MANAGER)
local
l_uuid: detachable READABLE_STRING_32
do
manager := a_manager
initialize (a_cookie_name)
if attached {WSF_STRING} req.cookie (cookie_name) as c_uuid then
l_uuid := c_uuid.value
elseif attached {WSF_STRING} req.query_parameter (cookie_name) as q_uuid then
l_uuid := q_uuid.value
end
if l_uuid /= Void and then session_exists (l_uuid) then
uuid := l_uuid
load
else
is_pending := True
build
end
end
make_new (a_cookie_name: detachable like cookie_name; a_manager: WSF_SESSION_MANAGER)
do
manager := a_manager
initialize (a_cookie_name)
is_pending := True
build
end
initialize (a_cookie_name: detachable like cookie_name)
do
if a_cookie_name = Void or else a_cookie_name.is_empty then
cookie_name := "_EWF_SESSION_ID"
else
cookie_name := a_cookie_name
end
end
feature -- Cookie
apply_to (h: HTTP_HEADER; a_request: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
local
dt: detachable DATE_TIME
l_domain: detachable READABLE_STRING_8
do
l_domain := a_request.server_name
if l_domain.same_string ("localhost") then
-- Due to limitation of specific handling of local cookies
-- it is recommended to use Void or IP instead of "localhost"
l_domain := Void
end
if is_destroyed then
h.put_cookie (cookie_name, "deleted", "Thu, 01 Jan 1970 00:00:00 GMT", a_path, l_domain, False, True)
else
dt := expiration
if dt = Void then
create dt.make_now_utc
dt.day_add (40)
end
h.put_cookie_with_expiration_date (cookie_name, uuid, dt, a_path, l_domain, False, True)
end
end
cookie_name: READABLE_STRING_8
feature -- Access
uuid: READABLE_STRING_8
data: WSF_SESSION_DATA
expiration: detachable DATE_TIME
feature -- status
is_pending: BOOLEAN
is_destroyed: BOOLEAN
feature -- Control
destroy
do
is_destroyed := True
data.wipe_out
delete
end
commit
do
save
end
set_expiration (dt: like expiration)
do
expiration := dt
end
feature {NONE} -- Storage
manager: WSF_SESSION_MANAGER
session_exists (a_uuid: like uuid): BOOLEAN
do
Result := manager.session_exists (a_uuid)
end
init_data
do
create data.make (0)
data.compare_objects
end
sessions_folder_name: READABLE_STRING_8
local
dn: DIRECTORY_NAME
once
create dn.make_from_string ((create {EXECUTION_ENVIRONMENT}).current_working_directory)
dn.extend ("_sessions_")
Result := dn.string
end
load
do
if manager.session_exists (uuid) then
if attached manager.session_data (uuid) as d then
data := d
set_expiration (data.expiration)
else
init_data
save
end
else
build
end
rescue
print ("ouch")
end
build
do
uuid := uuid_generator.generate_uuid.out
init_data
save
end
save
do
manager.save_session (Current)
end
delete
do
manager.delete_session (Current)
end
feature {NONE} -- Implementation
uuid_generator: UUID_GENERATOR
once
create Result
end
note
copyright: "Copyright (c) 1984-2012, 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,160 @@
note
description: "Summary description for {WSF_FS_SESSION_MANAGER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_FS_SESSION_MANAGER
inherit
WSF_SESSION_MANAGER
create
make,
make_with_folder
feature {NONE} -- Initialization
make
do
make_with_folder ("_WSF_SESSIONS_")
end
make_with_folder (a_folder: like sessions_folder_name)
do
sessions_folder_name := a_folder
end
sessions_folder_name: STRING_8
feature -- Access
session_exists (a_session_uuid: like {WSF_SESSION}.uuid): BOOLEAN
local
f: RAW_FILE
do
create f.make (file_name (a_session_uuid))
Result := f.exists and then f.is_readable
end
session_data (a_session_uuid: like {WSF_SESSION}.uuid): detachable like {WSF_SESSION}.data
local
f: RAW_FILE
do
create f.make (file_name (a_session_uuid))
if f.exists and then f.is_readable then
f.open_read
if attached data_from_file (f) as d then
Result := d
end
f.close
end
rescue
debug
print ("Error occurred in " + generator)
end
end
feature -- Persistence
save_session (a_session: WSF_SESSION)
local
f: RAW_FILE
rescued: BOOLEAN
do
if not rescued then
if a_session.is_destroyed then
delete_session (a_session)
else
ensure_session_folder_exists
create f.make (file_name (a_session.uuid))
if not f.exists or else f.is_writable then
f.create_read_write
a_session.data.set_expiration (a_session.expiration)
f.general_store (a_session.data)
f.close
end
end
end
rescue
debug
io.error.put_string (generator + ": trouble saving session")
end
rescued := True
retry
end
delete_session (a_session: WSF_SESSION)
local
f: RAW_FILE
rescued: BOOLEAN
do
if not rescued then
create f.make (file_name (a_session.uuid))
if f.exists then
f.delete
end
end
rescue
debug
io.error.put_string (generator + ": trouble deleting session")
end
rescued := True
retry
end
feature {NONE} -- Implementation
data_from_file (f: FILE): detachable like session_data
require
f.is_open_read and f.is_readable
local
rescued: BOOLEAN
do
if
not rescued and then
attached {like session_data} f.retrieved as d
then
Result := d
end
rescue
debug
--FIXME
io.error.put_string (generator + ": incompatible session content")
end
rescued := True
retry
end
ensure_session_folder_exists
local
d: DIRECTORY
once
create d.make (sessions_folder_name)
if not d.exists then
d.recursive_create_dir
end
ensure
sessions_folder_exists_and_writable: sessions_folder_exists_and_writable
end
sessions_folder_exists_and_writable: BOOLEAN
local
d: DIRECTORY
do
create d.make (sessions_folder_name)
Result := d.exists and then d.is_writable
end
file_name (a_uuid: like {WSF_SESSION}.uuid): READABLE_STRING_8
local
fn: FILE_NAME
do
create fn.make_from_string (sessions_folder_name)
fn.set_file_name (a_uuid.out)
fn.add_extension ("session")
Result := fn.string
end
end

View File

@@ -0,0 +1,97 @@
note
description: "Summary description for {WSF_SESSION}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_SESSION
feature -- Access
uuid: READABLE_STRING_8
deferred
end
data: WSF_SESSION_DATA
deferred
end
expiration: detachable DATE_TIME
deferred
end
expired: BOOLEAN
do
if attached expiration as e then
Result := e < (create {DATE_TIME}.make_now_utc)
end
end
feature -- status
is_pending: BOOLEAN
-- New session pending to be applied?
-- i.e: sent back to the client
deferred
end
is_destroyed: BOOLEAN
deferred
end
feature -- Entries
table: TABLE_ITERABLE [detachable ANY, READABLE_STRING_32]
do
Result := data
end
item (k: READABLE_STRING_GENERAL): detachable ANY
do
Result := data.item (table_key (k))
end
remember (v: detachable ANY; k: READABLE_STRING_GENERAL)
do
data.force (v, table_key (k))
end
forget (k: READABLE_STRING_GENERAL)
do
data.remove (table_key (k))
end
feature {NONE} -- Implementation
table_key (k: READABLE_STRING_GENERAL): STRING_32
do
Result := k.as_string_32
end
feature -- Control
destroy
deferred
end
commit
deferred
end
apply_to (h: HTTP_HEADER; a_request: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
deferred
end
note
copyright: "Copyright (c) 1984-2012, 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,27 @@
note
description: "Summary description for {WSF_SESSION_DATA}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_SESSION_DATA
inherit
HASH_TABLE [detachable ANY, READABLE_STRING_32]
create
make
feature -- Access
expiration: detachable DATE_TIME
feature -- Element change
set_expiration (dt: like expiration)
do
expiration := dt
end
end

View File

@@ -0,0 +1,16 @@
note
description: "Summary description for {WSF_SESSION_FACTORY}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_SESSION_FACTORY [G -> WSF_SESSION]
feature -- Access
new_session (req: WSF_REQUEST; a_reuse: BOOLEAN; m: WSF_SESSION_MANAGER): G
deferred
end
end

View File

@@ -0,0 +1,30 @@
note
description: "Summary description for {WSF_SESSION_MANAGER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_SESSION_MANAGER
feature -- Access
session_exists (a_uuid: like {WSF_SESSION}.uuid): BOOLEAN
deferred
end
session_data (a_uuid: like {WSF_SESSION}.uuid): detachable like {WSF_SESSION}.data
deferred
end
feature -- Persistence
save_session (a_session: WSF_SESSION)
deferred
end
delete_session (a_session: WSF_SESSION)
deferred
end
end

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="wsf_extension" uuid="11055B92-CBEF-4272-8B50-0450BDA154E5" library_target="wsf_extension">
<target name="wsf_extension">
<root all_classes="true"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard">
</option>
<library name="base" location="$ISE_LIBRARY/library/base/base-safe.ecf"/>
<library name="http" location="../../network/protocol/http/http-safe.ecf"/>
<library name="ewsgi" location="..\ewsgi\ewsgi-safe.ecf"/>
<library name="wsf-safe" location="..\wsf\wsf-safe.ecf"/>
<cluster name="extension" location=".extension" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="wsf_extension" uuid="11055B92-CBEF-4272-8B50-0450BDA154E5" library_target="wsf_extension">
<target name="wsf_extension">
<root all_classes="true"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" void_safety="none" syntax="standard">
</option>
<library name="base" location="$ISE_LIBRARY/library/base/base.ecf"/>
<library name="http" location="../../network/protocol/http/http.ecf"/>
<library name="ewsgi" location="..\ewsgi\ewsgi.ecf"/>
<library name="wsf" location="..\wsf\wsf.ecf"/>
<cluster name="extension" location="./extension" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="wsf_session" uuid="C41D0367-9852-4AA7-9E7E-DEA162A4CBB0" library_target="wsf_session">
<target name="wsf_session">
<root all_classes="true"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard">
</option>
<library name="base" location="$ISE_LIBRARY/library/base/base-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY/library/time/time-safe.ecf"/>
<library name="uuid" location="$ISE_LIBRARY/library/uuid/uuid-safe.ecf"/>
<library name="http" location="../../network/protocol/http/http-safe.ecf"/>
<library name="ewsgi" location="..\ewsgi\ewsgi-safe.ecf"/>
<library name="wsf-safe" location="..\wsf\wsf-safe.ecf"/>
<cluster name="session" location="./session" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="wsf_session" uuid="C41D0367-9852-4AA7-9E7E-DEA162A4CBB0" library_target="wsf_session">
<target name="wsf_session">
<root all_classes="true"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" void_safety="none" syntax="standard">
</option>
<library name="base" location="$ISE_LIBRARY/library/base/base.ecf"/>
<library name="time" location="$ISE_LIBRARY/library/time/time.ecf"/>
<library name="uuid" location="$ISE_LIBRARY/library/uuid/uuid.ecf"/>
<library name="http" location="../../network/protocol/http/http.ecf"/>
<library name="ewsgi" location="..\ewsgi\ewsgi.ecf"/>
<library name="wsf" location="..\wsf\wsf.ecf"/>
<cluster name="session" location="./session" recursive="true"/>
</target>
</system>