Removed pseudo rest library from draft libraries.

This commit is contained in:
Jocelyn Fiat
2012-11-20 13:49:28 +01:00
parent ead896e870
commit 6621da202d
37 changed files with 0 additions and 2406 deletions

View File

@@ -1 +0,0 @@
reference:forum2

View File

@@ -1,29 +0,0 @@
<?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="rest" uuid="97FA9457-7820-4A21-8A13-C8D0E9CCEC62" library_target="rest">
<target name="rest">
<root all_classes="true"/>
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/\.git$</exclude>
<exclude>/\.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all">
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="wsf" location="..\..\..\..\..\library\server\wsf\wsf-safe.ecf" readonly="false"/>
<library name="wsf_extension" location="..\..\..\..\..\library\server\wsf\wsf_extension-safe.ecf" readonly="false"/>
<library name="http" location="../../../../../library/network/protocol/http/http-safe.ecf"/>
<library name="uri_template" location="../../../../../library/text/parser/uri_template/uri_template-safe.ecf"/>
<cluster name="contrib" location=".\src\contrib\" recursive="true">
<file_rule>
<exclude>/html$</exclude>
</file_rule>
<cluster name="html" location="$|doc\html\" recursive="true" hidden="true"/>
</cluster>
<cluster name="src" location=".\src\" recursive="true">
<file_rule>
<exclude>/contrib$</exclude>
</file_rule>
</cluster>
</target>
</system>

View File

@@ -1,28 +0,0 @@
<?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="rest" uuid="97FA9457-7820-4A21-8A13-C8D0E9CCEC62" library_target="rest">
<target name="rest">
<root all_classes="true"/>
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/\.git$</exclude>
<exclude>/\.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true"/>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="wsf" location="..\..\..\..\..\library\server\wsf\wsf.ecf"/>
<library name="wsf_extension" location="..\..\..\..\..\library\server\wsf\wsf_extension.ecf" readonly="false"/>
<library name="http" location="../../../../../library/network/protocol/http/http.ecf"/>
<library name="uri_template" location="../../../../../library/text/parser/uri_template/uri_template.ecf"/>
<cluster name="contrib" location=".\src\contrib\" recursive="true">
<file_rule>
<exclude>/html$</exclude>
</file_rule>
<cluster name="html" location="$|doc\html\" recursive="true" hidden="true"/>
</cluster>
<cluster name="src" location=".\src\" recursive="true">
<file_rule>
<exclude>/contrib$</exclude>
</file_rule>
</cluster>
</target>
</system>

View File

@@ -1,184 +0,0 @@
note
description: "Summary description for {HTML_PAGE}."
date: "$Date$"
revision: "$Revision$"
class
HTML_PAGE
inherit
HTML_UTILITIES
create
make
feature {NONE} -- Initialization
make (a_title: like title)
do
create {ARRAYED_LIST [like html_attributes.item]} html_attributes.make (0)
create head.make (a_title)
create {ARRAYED_LIST [like body_attributes.item]} body_attributes.make (0)
create body.make_empty
initialize
end
initialize
-- Initialize
do
create headers.make
end
feature -- Access
headers: HTTP_HEADER
feature -- Recycle
recycle
do
html_attributes.wipe_out
headers.recycle
head.recycle
body_attributes.wipe_out
body.wipe_out
internal_header_string := Void
internal_message_string := Void
end
feature -- Access
html_attributes: LIST [TUPLE [name: STRING; value: STRING]]
head: HTML_PAGE_HEAD
body_attributes: LIST [TUPLE [name: STRING; value: STRING]]
body: STRING
feature -- Query
title: detachable STRING
do
Result := head.title
end
add_html_ttribute (a: like html_attributes.item)
do
html_attributes.force (a)
end
add_body_attribute (a: like body_attributes.item)
do
body_attributes.force (a)
end
set_body (s: like body)
-- Set `body' to `s'
do
body := s
end
feature -- Element change
set_title (t: like title)
do
head.title := t
end
feature -- Output
compute
-- Compute the string output
local
s, t: STRING
do
--| HTML beginning
create s.make (128)
s.append_string ("<html")
s.append_string (attributes_to_string (html_attributes))
s.append_string (">%N")
--| Head
head.compute --| Be sure to have a fresh string
t := head.string
if not t.is_empty then
s.append_string (t)
s.append_character ('%N')
end
--| Body
s.append_string ("<body")
s.append_string (attributes_to_string (body_attributes))
s.append_string (">%N")
s.append_string (body)
s.append_string ("</body>")
--| End
s.append_string ("</html>")
--| Http headers
headers.put_content_length (s.count)
internal_header_string := headers.string
internal_message_string := s
end
header_string: STRING
local
o: like internal_header_string
do
o := internal_header_string
if o = Void then
compute
o := internal_header_string
if o = Void then
check output_computed: False end
create o.make_empty
end
end
Result := o
end
message_string: STRING
local
o: like internal_message_string
do
o := internal_message_string
if o = Void then
compute
o := internal_message_string
if o = Void then
check output_computed: False end
create o.make_empty
end
end
Result := o
end
send (buf: WSF_RESPONSE)
do
buf.set_status_code (200)
buf.put_header_text (header_string)
buf.put_string (message_string)
end
feature {NONE} -- Implementation: output
internal_header_string: detachable like header_string
internal_message_string: detachable like message_string
invariant
header_attached: headers /= Void
;note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,111 +0,0 @@
note
description: "Summary description for {HTML_PAGE_HEAD}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
HTML_PAGE_HEAD
inherit
HTML_UTILITIES
create
make
feature {NONE} -- Initialization
make (a_title: like title)
do
initialize
title := a_title
end
initialize
do
create text.make_empty
create {ARRAYED_LIST [like attributes.item]} attributes.make (0)
end
feature -- Recycle
recycle
do
attributes.wipe_out
title := Void
text.wipe_out
internal_string := Void
end
feature -- Access
attributes: LIST [TUPLE [name: STRING; value: STRING]]
title: detachable STRING assign set_title
text: STRING
feature -- Element change
set_title (t: like title)
do
title := t
end
feature -- Output
compute
-- Compute the string output
local
s: STRING
do
create s.make_empty
if attached title as t then
s.append_string ("<title>" + t + "</title>%N")
end
if text.count > 0 then
s.append_string (text)
s.append_character ('%N')
end
if s.count > 0 then
internal_string := "<head" + attributes_to_string (attributes) + ">%N" + s + "</head>"
else
internal_string := s
end
end
string: STRING
--
local
o: like internal_string
do
o := internal_string
if o = Void then
compute
o := internal_string
if o = Void then
check output_computed: False end
create o.make_empty
end
end
Result := o
end
feature {NONE} -- Implementation: output
internal_string: detachable like string
invariant
text_attached: text /= Void
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,90 +0,0 @@
note
description: "Summary description for {HTML_UTILITIES}."
date: "$Date$"
revision: "$Revision$"
class
HTML_UTILITIES
feature -- Encoding
html_special_chars_encoded_string (s: STRING): STRING
local
c: CHARACTER
i,n: INTEGER
do
from
i := 1
n := s.count
create Result.make (n + 10)
until
i > n
loop
c := s[i]
inspect c
when '&' then
Result.append_string ("&amp;")
when '%"' then
Result.append_string ("&quot;")
when '%'' then
Result.append_string ("&#039;")
when '<' then
Result.append_string ("&lt;")
when '>' then
Result.append_string ("&gt;")
else
Result.extend (c)
end
i := i + 1
end
end
feature -- Helpers
strings_to_string (lst: LIST [STRING]; sep: STRING): STRING
do
create Result.make_empty
if lst.count > 0 then
from
lst.start
until
lst.after
loop
Result.append_string (lst.item)
Result.append_string (sep)
lst.forth
end
end
end
attributes_to_string (atts: LIST [TUPLE [name: STRING; value: STRING]]): STRING
do
create Result.make_empty
if atts.count > 0 then
from
atts.start
until
atts.after
loop
Result.append_character (' ')
Result.append_string (atts.item.name)
Result.append_character ('=')
Result.append_character ('%"')
Result.append_string (html_special_chars_encoded_string (atts.item.value))
Result.append_character ('%"')
atts.forth
end
end
end
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,124 +0,0 @@
note
description: "Summary description for {REST_API_DOCUMENTATION_HTML_PAGE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
REST_API_DOCUMENTATION_HTML_PAGE
inherit
HTML_PAGE
redefine
head,
initialize,
recycle,
compute
end
create
make
feature {NONE} -- Initialization
initialize
do
Precursor
create {LINKED_LIST [like shortcuts.item]} shortcuts.make
end
feature -- Recyle
recycle
do
Precursor
shortcuts.wipe_out
end
feature -- Access
head: REST_API_DOCUMENTATION_HTML_PAGE_HEAD
big_title: detachable STRING
shortcuts: LIST [TUPLE [name: STRING; anchor: STRING]]
add_shortcut (s: STRING)
local
t: STRING
do
t := s.string
t.replace_substring_all ("/", "-")
shortcuts.force ([s,t])
end
last_added_shortcut: STRING
do
if shortcuts.count > 0 and then attached shortcuts.last as sht then
Result := sht.anchor
else
create Result.make_empty
end
end
shortcuts_to_html: detachable STRING
do
if not shortcuts.is_empty then
from
create Result.make_from_string ("<strong>Shortcuts:</strong> | ")
shortcuts.start
until
shortcuts.after
loop
Result.append_string ("<a href=%"#"+ shortcuts.item.anchor +"%">"+ shortcuts.item.name +"</a> | ")
shortcuts.forth
end
end
end
feature -- Element change
set_big_title (t: like big_title)
do
big_title := t
end
feature -- Basic operation
compute
local
l_old_body: STRING
sh, bt: detachable STRING
do
sh := shortcuts_to_html
bt := big_title
if sh /= Void or bt /= Void then
l_old_body := body
if bt /= Void then
bt := "<h1>" + bt + "</h2>%N"
if sh /= Void then
body := bt + sh + l_old_body
else
body := bt + l_old_body
end
elseif sh /= Void then
body := sh + l_old_body
end
Precursor
body := l_old_body
else
Precursor
end
end
;note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,75 +0,0 @@
note
description: "Summary description for {REST_API_DOCUMENTATION_HTML_PAGE_HEAD}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
REST_API_DOCUMENTATION_HTML_PAGE_HEAD
inherit
HTML_PAGE_HEAD
redefine
initialize,
compute
end
create
make
feature {NONE} -- Initialization
initialize
do
Precursor
style := "[
body {margin: 0px;}
a { text-decoration: none; }
h1 { padding: 10px; border: solid 2px #000; background-color: #009; color: #fff;}
div.api { padding: 5px; margin-bottom: 10px;}
div.api .api-description { padding: 5px 5px 5px 0px; font-style: italic; color: #090;}
div.api div.inner { padding-left: 40px;}
div.api h2>a { color: #009; text-decoration: none;}
div.api a.api-format { color: #009; text-decoration: none;}
div.api a.api-format.selected { padding: 0 4px 0 4px; color: #009; text-decoration: none; border: solid 1px #99c; background-color: #eeeeff;}
div.api>h2 { margin: 2px; padding: 2px 2px 2px 10px; display: inline-block; border: dotted 1px #cce; width: 100%; color: #009; background-color: #E7F3F8; text-decoration: none; font-weight: bold; font-size: 120%;}
div.api span.note { font-style: italic;}
]"
end
feature {REST_API_DOCUMENTATION_HTML_PAGE} -- Access
style: STRING
feature -- Output
compute
-- Compute the string output
local
s: detachable STRING
p: INTEGER
do
Precursor
s := internal_string
if s /= Void then
p := s.substring_index ("</head>", 1)
if p > 0 then
s.insert_string ("<style>%N" + style + "%N</style>%N", p)
else
s.append_string ("<style>%N" + style + "%N</style>%N")
end
end
end
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,47 +0,0 @@
note
description: "Summary description for REST_REQUEST_GROUP_HANDLER."
author: ""
date: "$Date$"
revision: "$Revision$"
class
REST_REQUEST_GROUP_HANDLER [H -> REST_REQUEST_HANDLER [C], C -> REST_REQUEST_HANDLER_CONTEXT]
inherit
REQUEST_ROUTING_HANDLER [H, C]
redefine
execute
end
REST_REQUEST_HANDLER [C]
redefine
execute
select
execute_application
end
create
make
feature -- status
authentication_required: BOOLEAN
feature -- Execution
execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do
Precursor {REST_REQUEST_HANDLER} (ctx, req, res)
end
;note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,56 +0,0 @@
note
description: "Summary description for {REST_RESPONSE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
REST_RESPONSE
inherit
WSF_PAGE_RESPONSE
rename
header as headers,
body as message,
set_body as set_message,
put_string as append_message,
make as page_make,
send_to as send
end
create
make
feature {NONE} -- Initialization
make (a_api: like api)
do
api := a_api
page_make
end
feature -- Recycle
recycle
do
headers.recycle
message := Void
end
feature -- Access
api: STRING
-- Associated api query string.
invariant
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

@@ -1,47 +0,0 @@
class
REST_REQUEST_AGENT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_URI_TEMPLATE_AGENT_CONTEXT_HANDLER [C]
rename
execute as execute_application
end
REST_REQUEST_HANDLER [C]
select
execute
end
create
make
feature -- status
authentication_required (req: WSF_REQUEST): BOOLEAN
do
Result := internal_authentication_required
end
feature -- Element change
set_authentication_required (b: like authentication_required)
do
internal_authentication_required := b
end
feature {NONE} -- Implementation
internal_authentication_required: BOOLEAN
invariant
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

@@ -1,332 +0,0 @@
note
description: "Summary description for {REST_REQUEST_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
REST_REQUEST_HANDLER [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_URI_TEMPLATE_CONTEXT_HANDLER [C]
WSF_HANDLER_HELPER
feature -- Access
authentication_required (req: WSF_REQUEST): BOOLEAN
-- Is authentication required
-- might depend on the request environment
-- or the associated resources
deferred
end
description: detachable STRING
-- Optional description
feature -- Element change
set_description (s: like description)
-- Set `description' to `s'
do
description := s
end
feature -- Execution
execute (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
if request_method_name_supported (req.request_method) then
if authentication_required (req) and then not authenticated (ctx) then
execute_unauthorized (ctx, req, res)
else
pre_execute (ctx, req, res)
execute_application (ctx, req, res)
post_execute (ctx, req, res)
end
else
execute_request_method_not_allowed (req, res, supported_request_method_names)
end
rescue
execute_rescue (ctx, req, res)
end
execute_application (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
deferred
end
pre_execute (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do
end
post_execute (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do
end
execute_rescue (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do
post_execute (ctx, req, res)
rescue
--| Just in case, the rescue is raising other exceptions ...
end
execute_unauthorized (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do
res.put_header ({HTTP_STATUS_CODE}.unauthorized, Void)
res.put_string ("Unauthorized")
end
feature -- Auth
authenticated (ctx: C): BOOLEAN
-- Is authenticated?
do
--| To redefine if needed
end
feature {NONE} -- Implementation
supported_formats: INTEGER
-- Support request format result such as json, xml, ...
feature {NONE} -- Status report
format_id_supported (a_id: INTEGER): BOOLEAN
do
Result := (supported_formats & a_id) = a_id
end
format_name_supported (n: STRING): BOOLEAN
-- Is format `n' supported?
do
Result := format_id_supported (format_constants.format_id (n))
end
format_constants: HTTP_FORMAT_CONSTANTS
once
create Result
end
feature -- Status report
supported_format_names: LIST [STRING]
-- Supported format names ...
do
create {LINKED_LIST [STRING]} Result.make
if format_json_supported then
Result.extend (format_constants.json_name)
end
if format_xml_supported then
Result.extend (format_constants.xml_name)
end
if format_text_supported then
Result.extend (format_constants.text_name)
end
if format_html_supported then
Result.extend (format_constants.html_name)
end
if format_rss_supported then
Result.extend (format_constants.rss_name)
end
if format_atom_supported then
Result.extend (format_constants.atom_name)
end
end
format_json_supported: BOOLEAN
do
Result := format_id_supported ({HTTP_FORMAT_CONSTANTS}.json)
end
format_xml_supported: BOOLEAN
do
Result := format_id_supported ({HTTP_FORMAT_CONSTANTS}.xml)
end
format_text_supported: BOOLEAN
do
Result := format_id_supported ({HTTP_FORMAT_CONSTANTS}.text)
end
format_html_supported: BOOLEAN
do
Result := format_id_supported ({HTTP_FORMAT_CONSTANTS}.html)
end
format_rss_supported: BOOLEAN
do
Result := format_id_supported ({HTTP_FORMAT_CONSTANTS}.rss)
end
format_atom_supported: BOOLEAN
do
Result := format_id_supported ({HTTP_FORMAT_CONSTANTS}.atom)
end
feature -- Element change: formats
reset_supported_formats
do
supported_formats := 0
end
enable_format_json
do
enable_format ({HTTP_FORMAT_CONSTANTS}.json)
end
enable_format_xml
do
enable_format ({HTTP_FORMAT_CONSTANTS}.xml)
end
enable_format_text
do
enable_format ({HTTP_FORMAT_CONSTANTS}.text)
end
enable_format_html
do
enable_format ({HTTP_FORMAT_CONSTANTS}.html)
end
enable_format (f: INTEGER)
do
supported_formats := supported_formats | f
end
feature {NONE} -- Implementation
supported_request_methods: INTEGER
-- Support request method such as GET, POST, ...
feature {NONE} -- Status report
request_method_id_supported (a_id: INTEGER): BOOLEAN
do
Result := (supported_request_methods & a_id) = a_id
end
request_method_name_supported (n: STRING): BOOLEAN
-- Is request method `n' supported?
do
Result := request_method_id_supported (request_method_constants.method_id (n))
end
request_method_constants: HTTP_REQUEST_METHOD_CONSTANTS
once
create Result
end
feature -- Status report
supported_request_method_names: LIST [STRING]
-- Support request method such as GET, POST, ...
do
create {LINKED_LIST [STRING]} Result.make
if method_get_supported then
Result.extend (request_method_constants.method_get)
end
if method_post_supported then
Result.extend (request_method_constants.method_post)
end
if method_put_supported then
Result.extend (request_method_constants.method_put)
end
if method_patch_supported then
Result.extend (request_method_constants.method_patch)
end
if method_delete_supported then
Result.extend (request_method_constants.method_delete)
end
if method_head_supported then
Result.extend (request_method_constants.method_head)
end
end
method_get_supported: BOOLEAN
do
Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.get)
end
method_post_supported: BOOLEAN
do
Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.post)
end
method_put_supported: BOOLEAN
do
Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.put)
end
method_patch_supported: BOOLEAN
do
Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.patch)
end
method_delete_supported: BOOLEAN
do
Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.delete)
end
method_head_supported: BOOLEAN
do
Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.head)
end
feature -- Element change: request methods
reset_supported_request_methods
do
supported_request_methods := 0
end
enable_request_method_get
do
enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.get)
end
enable_request_method_post
do
enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.post)
end
enable_request_method_put
do
enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.put)
end
enable_request_method_patch
do
enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.patch)
end
enable_request_method_delete
do
enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.delete)
end
enable_request_method_head
do
enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.head)
end
enable_request_method (m: INTEGER)
do
supported_request_methods := supported_request_methods | m
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

@@ -1,133 +0,0 @@
note
description: "Summary description for {REST_REQUEST_HANDLER_CONTEXT}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
REST_REQUEST_HANDLER_CONTEXT
inherit
WSF_HANDLER_CONTEXT
WSF_REQUEST_UTILITY_PROXY
feature -- Accept: Content-Type
accepted_content_type: detachable READABLE_STRING_8
do
if internal_accepted_content_type = Void then
get_accepted_content_type (Void)
end
Result := internal_accepted_content_type
end
get_accepted_content_type (a_supported_content_types: detachable ARRAY [STRING_8])
do
if internal_accepted_content_type = Void then
internal_accepted_content_type := request_accepted_content_type (a_supported_content_types)
end
end
feature -- Format name
accepted_format_name: detachable READABLE_STRING_8
do
if internal_accepted_format_name = Void then
get_accepted_format_name (Void, Void)
end
Result := internal_accepted_format_name
end
get_accepted_format_name (a_format_variable_name: detachable READABLE_STRING_8; a_supported_content_types: detachable ARRAY [STRING_8])
do
if internal_accepted_format_name = Void then
internal_accepted_format_name := request_accepted_format (a_format_variable_name, a_supported_content_types)
end
end
feature -- Format id
accepted_format_id: INTEGER
do
if internal_accepted_format_id = 0 then
get_accepted_format_id (Void, Void)
end
Result := internal_accepted_format_id
end
get_accepted_format_id (a_format_variable_name: detachable READABLE_STRING_8; a_supported_content_types: detachable ARRAY [STRING_8])
do
if internal_accepted_format_id = 0 then
internal_accepted_format_id := request_accepted_format_id (a_format_variable_name, a_supported_content_types)
end
end
feature {NONE} -- Constants
Format_constants: HTTP_FORMAT_CONSTANTS
once
create Result
end
feature -- Format
request_accepted_format (a_format_variable_name: detachable READABLE_STRING_8; a_supported_content_types: detachable ARRAY [READABLE_STRING_8]): detachable READABLE_STRING_8
-- Format id for the request based on {HTTP_FORMAT_CONSTANTS}
do
if a_format_variable_name /= Void and then attached {WSF_STRING} request.item (a_format_variable_name) as ctx_format then
Result := ctx_format.value
else
Result := request_format_from_content_type (request_accepted_content_type (a_supported_content_types))
end
end
request_accepted_format_id (a_format_variable_name: detachable READABLE_STRING_8; a_supported_content_types: detachable ARRAY [READABLE_STRING_8]): INTEGER
-- Format id for the request based on {HTTP_FORMAT_CONSTANTS}
do
if attached request_accepted_format (a_format_variable_name, a_supported_content_types) as l_format then
Result := Format_constants.format_id (l_format)
else
Result := 0
end
end
feature {NONE} -- Format/Content type implementation
request_format_from_content_type (a_content_type: detachable READABLE_STRING_8): detachable READABLE_STRING_8
-- `a_content_type' converted into a request format name
do
if a_content_type /= Void then
if a_content_type.same_string ({HTTP_MIME_TYPES}.text_json) then
Result := {HTTP_FORMAT_CONSTANTS}.json_name
elseif a_content_type.same_string ({HTTP_MIME_TYPES}.application_json) then
Result := {HTTP_FORMAT_CONSTANTS}.json_name
elseif a_content_type.same_string ({HTTP_MIME_TYPES}.text_xml) then
Result := {HTTP_FORMAT_CONSTANTS}.xml_name
elseif a_content_type.same_string ({HTTP_MIME_TYPES}.text_html) then
Result := {HTTP_FORMAT_CONSTANTS}.html_name
elseif a_content_type.same_string ({HTTP_MIME_TYPES}.text_plain) then
Result := {HTTP_FORMAT_CONSTANTS}.text_name
end
end
end
feature {NONE} -- Internal
internal_accepted_content_type: like accepted_content_type
internal_accepted_format_id: like accepted_format_id
internal_accepted_format_name: like accepted_format_name
;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

@@ -1,23 +0,0 @@
note
description: "Summary description for {DEFAULT_REST_SERVICE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
REST_SERVICE [C -> WSF_HANDLER_CONTEXT create make end]
inherit
REST_SERVICE_I [C]
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

@@ -1,23 +0,0 @@
note
description: "Summary description for {REST_SERVICE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
REST_SERVICE_I [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_URI_TEMPLATE_CONTEXT_ROUTED_SERVICE [C]
;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

@@ -1,24 +0,0 @@
note
description: "Summary description for {DEFAULT_REST_REQUEST_URI_TEMPLATE_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
REST_REQUEST_URI_TEMPLATE_HANDLER [C -> WSF_HANDLER_CONTEXT create make end]
inherit
REST_REQUEST_HANDLER [C]
;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

@@ -1,28 +0,0 @@
note
description: "Summary description for {WSF_URI_TEMPLATE_HANDLER_CONTEXT}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
REST_REQUEST_URI_TEMPLATE_HANDLER_CONTEXT
inherit
WSF_HANDLER_CONTEXT
REST_REQUEST_HANDLER_CONTEXT
create
make
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

@@ -1,67 +0,0 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
class
REST_URI_TEMPLATE_ROUTING_HANDLER [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_URI_TEMPLATE_ROUTING_CONTEXT_HANDLER [C]
rename
execute as old_execute,
uri_template_execute as execute
redefine
execute
end
REST_REQUEST_HANDLER [C]
undefine
execute
end
create
make,
make_with_router
feature -- Status report
authentication_required (req: WSF_REQUEST): BOOLEAN
do
Result := internal_authentication_required
end
feature {NONE} -- Implementation
internal_authentication_required: BOOLEAN
feature -- Execution
execute (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do
pre_execute (ctx, req, res)
Precursor {WSF_URI_TEMPLATE_ROUTING_CONTEXT_HANDLER} (ctx, req, res)
post_execute (ctx, req, res)
end
execute_application (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do
check should_not_occur: False end
end
invariant
-- invariant_clause: True
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

@@ -1,23 +0,0 @@
note
description: "Summary description for {DEFAULT_URI_TEMPLATE_REST_SERVICE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
REST_URI_TEMPLATE_SERVICE [C -> WSF_HANDLER_CONTEXT create make end]
inherit
REST_SERVICE_I [C]
;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

@@ -1,26 +0,0 @@
Options Indexes FollowSymLinks ExecCGI
<IfModule mod_fcgid.c>
AddHandler fcgid-script .eapp
FcgidWrapper c:/_dev/Dev-Process/web-framework/library/server/request/rest/tests/htdocs/../EIFGENs/rest_sample_cgi/W_code/sample.exe .eapp
</IfModule>
Options +ExecCGI
AddHandler cgi-script exe
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /REST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ sample.eapp/$1
# To let CGI app knows about HTTP_AUTHORIZATION
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

View File

@@ -1,31 +0,0 @@
= How to make this works with Apache =
* In the apache's configuration file, be sure to add the following, or similar
LoadModule fcgid_module modules/mod_fcgid.so
<IfModule mod_fcgid.c>
FcgidIdleTimeout 60
FcgidBusyScanInterval 120
FcgidProcessLifeTime 1600
#7200
FcgidMaxProcesses 5
FcgidMaxProcessesPerClass 100
FcgidMinProcessesPerClass 100
FcgidConnectTimeout 8
FcgidIOTimeout 3000
FcgidBusyTimeout 3200
FcgidMaxRequestLen 10000000
FcgidPassHeader Authorization
</IfModule>
alias /REST/ "c:/_dev/Dev-Process/src/server/htdocs/"
<directory "c:/_dev/Dev-Process/src/server/htdocs/">
AllowOverride All
Order allow,deny
Allow from all
</directory>
* You can use <Location>, but then the AllowOverride All, should be somewhere else, since <Location> does not allow it.
* And then, check the .htaccess from this folder for additional settings (but required)

View File

@@ -1,24 +0,0 @@
<?xml version="1.0"?>
<project name="update_htdocs" default="menu">
<target name="menu">
<echo message="1 - update_cgi_link" />
<echo message="2 - update_htaccess" />
<echo message="0 - quit" />
<input message="Your choice :" variable="answer" defaultvalue="0" validargs="1,2,0" answer_required="true" />
<geant target="update_cgi_link" if="$answer=1" />
<geant target="update_htaccess" if="$answer=2" />
</target>
<target name="update_cgi_link">
<echo message="Update CGI link" />
<exec executable="junction CGI ..\EIFGENs\rest_sample_cgi\W_code" accept_errors="true" exit_code_variable="return_code" dir="$cwd" />
</target>
<target name="update_htaccess">
<replace file="htaccess" to_file=".htaccess" token="##SAMPLE-CGI-DIR##" replace="$cwd/../EIFGENs/rest_sample_cgi/W_code" flags="g" />
<replace file=".htaccess" to_file=".htaccess" token="\" replace="/" flags="g" />
</target>
</project>

View File

@@ -1,26 +0,0 @@
Options Indexes FollowSymLinks ExecCGI
<IfModule mod_fcgid.c>
AddHandler fcgid-script .eapp
FcgidWrapper ##SAMPLE-CGI-DIR##/sample.exe .eapp
</IfModule>
Options +ExecCGI
AddHandler cgi-script exe
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /REST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ sample.eapp/$1
# To let CGI app knows about HTTP_AUTHORIZATION
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

View File

@@ -1,56 +0,0 @@
<?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="common" uuid="4E02DF53-9DF0-44B6-B8A8-7554E0B94957">
<target name="common">
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/\.git$</exclude>
<exclude>/\.svn$</exclude>
</file_rule>
<option cat_call_detection="false" is_attached_by_default="true" void_safety="all" syntax="provisional">
</option>
<setting name="console_application" value="true"/>
<setting name="concurrency" value="thread"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="rest" location="..\rest-safe.ecf" readonly="false"/>
<library name="wsf" location="..\..\..\..\..\..\library\server\wsf\wsf-safe.ecf" readonly="false"/>
<library name="wsf_extension" location="..\..\..\..\..\..\library\server\wsf\wsf_extension-safe.ecf" readonly="false"/>
<library name="http" location="../../../../../../library/network/protocol/http/http-safe.ecf" readonly="false"/>
</target>
<target name="sample_fcgi" extends="common">
<root class="APP_SERVER" feature="make"/>
<setting name="executable_name" value="sample"/>
<library name="ewsgi_fcgi" location="..\..\..\..\..\..\library\server\ewsgi\connectors\libfcgi\libfcgi-safe.ecf" readonly="false"/>
<cluster name="src" location=".\src\" recursive="true">
<file_rule>
<exclude>/gateway$</exclude>
</file_rule>
</cluster>
<cluster name="gateway" location=".\src\gateway\fcgi\" recursive="true"/>
</target>
<target name="sample_cgi" extends="common">
<root class="APP_SERVER" feature="make"/>
<setting name="executable_name" value="sample"/>
<library name="ewsgi_cgi" location="..\..\..\..\..\..\library\server\ewsgi\connectors\cgi\cgi-safe.ecf" readonly="false"/>
<cluster name="src" location=".\src\" recursive="true">
<file_rule>
<exclude>/gateway$</exclude>
</file_rule>
</cluster>
<cluster name="gateway" location=".\src\gateway\cgi\" recursive="true"/>
</target>
<target name="sample_nino" extends="common">
<root class="APP_SERVER" feature="make"/>
<setting name="executable_name" value="sample"/>
<library name="ewsgi_nino" location="..\..\..\..\..\..\library\server\ewsgi\connectors\nino\nino-safe.ecf" readonly="false"/>
<library name="default_nino" location="..\..\..\..\..\..\library\server\wsf\default\nino-safe.ecf" readonly="false"/>
<cluster name="src" location=".\src\" recursive="true">
<file_rule>
<exclude>/gateway$</exclude>
</file_rule>
</cluster>
<cluster name="gateway" location=".\src\gateway\nino\" recursive="true"/>
</target>
</system>

View File

@@ -1,112 +0,0 @@
note
description: "Summary description for {APP_ACCOUNT_VERIFY_CREDENTIAL}."
date: "$Date$"
revision: "$Revision$"
class
APP_ACCOUNT_VERIFY_CREDENTIAL
inherit
APP_REQUEST_HANDLER
redefine
initialize,
execute_unauthorized
end
create
make
feature {NONE} -- Initialization
make
do
description := "Verify credentials"
initialize
end
initialize
do
Precursor
enable_request_method_get
enable_format_json
enable_format_xml
enable_format_text
end
feature -- Access
authentication_required (req: WSF_REQUEST): BOOLEAN
do
Result := True
end
feature -- Execution
execute_unauthorized (a_hdl_context: APP_REQUEST_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
local
s: STRING
lst: LIST [STRING]
do
res.set_status_code ({HTTP_STATUS_CODE}.unauthorized)
res.put_header ({HTTP_STATUS_CODE}.unauthorized, <<["WWW-Authenticate", "Basic realm=%"My Silly demo auth, password must be the same as login such as foo:foo%""]>>)
res.put_string ("Unauthorized")
end
execute_application (ctx: APP_REQUEST_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
local
l_full: BOOLEAN
h: HTTP_HEADER
l_login: STRING_8
s: STRING
content_type_supported: ARRAY [STRING]
l_format_id: INTEGER
do
content_type_supported := <<{HTTP_CONSTANTS}.application_json, {HTTP_CONSTANTS}.text_xml, {HTTP_CONSTANTS}.text_plain>>
l_format_id := ctx.request_accepted_format_id ("format", content_type_supported)
if authenticated (ctx) then
l_full := attached req.query_parameter ("details") as v and then v.is_case_insensitive_equal ("true")
if attached authenticated_identifier (ctx) as log then
l_login := log.as_string_8
create h.make
create s.make_empty
inspect l_format_id
when {HTTP_FORMAT_CONSTANTS}.json then
h.put_content_type_text_plain
s.append_string ("{ %"login%": %"" + l_login + "%" }%N")
when {HTTP_FORMAT_CONSTANTS}.xml then
h.put_content_type_text_xml
s.append_string ("<login>" + l_login + "</login>%N")
when {HTTP_FORMAT_CONSTANTS}.text then -- Default
h.put_content_type_text_plain
s.append_string ("login: " + l_login + "%N")
else
execute_content_type_not_allowed (req, res, content_type_supported,
<<{HTTP_FORMAT_CONSTANTS}.json_name, {HTTP_FORMAT_CONSTANTS}.html_name, {HTTP_FORMAT_CONSTANTS}.xml_name, {HTTP_FORMAT_CONSTANTS}.text_name>>
)
end
if not s.is_empty then
res.set_status_code ({HTTP_STATUS_CODE}.ok)
res.put_header_text (h.string)
res.put_string (s)
end
else
send_error (req.path_info, 0, "User/password unknown", Void, ctx, req, res)
end
else
send_error (req.path_info, 0, "Authentication rejected", Void, ctx, req, res)
end
end
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,97 +0,0 @@
note
description: "Summary description for {APP_TEST}."
date: "$Date$"
revision: "$Revision$"
class
APP_TEST
inherit
APP_REQUEST_HANDLER
redefine
initialize
end
create
make
feature {NONE} -- Initialization
make
do
description := "Return a simple test output "
initialize
end
initialize
do
Precursor
enable_request_method_get
enable_format_text
end
feature -- Access
authentication_required (req: WSF_REQUEST): BOOLEAN
do
end
feature -- Execution
execute_application (ctx: APP_REQUEST_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
local
s: STRING
h: HTTP_HEADER
do
create h.make
h.put_content_type_text_plain
create s.make_empty
s.append_string ("test")
if attached {WSF_STRING} req.meta_variable ("REQUEST_COUNT") as l_request_count_val then
s.append_string ("(request_count="+ l_request_count_val.string +")%N")
end
-- ctx.request_format_id ("format", Void)
if attached ctx.request_accepted_format ("format", Void) as l_format then
s.append_string (" format=" + l_format + "%N")
end
if attached ctx.string_item (req, "op") as l_op then
s.append_string (" op=" + l_op)
if l_op.same_string ("crash") then
(create {DEVELOPER_EXCEPTION}).raise
elseif l_op.starts_with ("env") then
s.append_string ("%N%NAll variables:")
s.append (wgi_value_iteration_to_string (req.items, False))
s.append_string ("<br/>script_url(%"" + req.path_info + "%")=" + req.script_url (req.path_info) + "%N")
-- if attached ctx.http_authorization_login_password as t then
-- s.append_string ("Check login=" + t.login + "<br/>%N")
-- end
if authenticated (ctx) and then attached authenticated_identifier (ctx) as l_login then
s.append_string ("Authenticated: login=" + l_login.as_string_8 + "<br/>%N")
end
end
else
s.append ("%N Try " + ctx.script_absolute_url (req, req.path_info + "?op=env") + " to display all variables%N")
s.append ("%N Try " + ctx.script_absolute_url (req, req.path_info + "?op=crash") + " to demonstrate exception trace%N")
end
res.set_status_code (200)
res.put_header_text (h.string)
res.put_string (s)
end
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,150 +0,0 @@
note
description: "Summary description for {APP_SERVER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
APP_SERVER
inherit
APP_SERVICE
redefine
create_router,
execute
end
REST_SERVICE_GATEWAY
WSF_REQUEST_UTILITY
create
make
feature {NONE} -- Initialization
make
-- Initialize `Current'.
do
initialize_router
build_gateway_and_launch
end
feature {NONE} -- Handlers
create_router
-- Create `router'
do
create router.make (5)
end
setup_router
local
h: APP_REQUEST_HANDLER
rah: APP_REQUEST_AGENT_HANDLER
gh: APP_REQUEST_ROUTING_HANDLER
do
create {APP_ACCOUNT_VERIFY_CREDENTIAL} h.make
router.handle ("/account/verify_credentials.{format}", h)
create {APP_TEST} h.make
create gh.make (4)
router.handle ("/test", gh)
-- gh.map ("/test", h)
gh.router.handle ("/test/{op}", h)
gh.router.handle ("/test.{format}", h)
gh.router.handle ("/test.{format}/{op}", h)
create rah.make (agent execute_exit_application)
h := rah
h.set_description ("tell the REST server to exit (in FCGI context, this is used to reload the FCGI server)")
h.enable_request_method_get
h.enable_format_text
router.handle ("/debug/exit", h)
router.handle ("/debug/exit.{format}", h)
end
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
do
request_count := request_count + 1
Precursor (req, res)
end
execute_default (req: WSF_REQUEST; res: WSF_RESPONSE)
local
rqst_uri: detachable STRING
l_path_info: detachable STRING
h: HTTP_HEADER
s: STRING
l_redir_url: STRING
do
create h.make
-- h.put_refresh (ctx.script_url ("/doc"), 2)
l_redir_url := "/doc"
h.put_refresh (l_redir_url, 2)
h.put_content_type_text_html
create s.make_empty
s := "Request [" + req.path_info + "] is not available. <br/>%N";
s.append ("You are being redirected to <a href=%"" + l_redir_url + "%">/doc</a> in 2 seconds ...%N")
h.put_content_length (s.count)
res.set_status_code ({HTTP_STATUS_CODE}.temp_redirect)
res.put_header_text (h.string)
res.put_string (s)
end
request_count: INTEGER
-- execute_rescue (ctx: like new_request_context)
-- -- Execute the default rescue behavior
-- do
-- execute_exception_trace (ctx)
-- end
feature -- Implementation
-- execute_exception_trace (ctx: like new_request_context)
-- local
-- h: HTTP_HEADER
-- s: STRING
-- do
-- create h.make
-- h.put_content_type_text_plain
-- ctx.output.put_string (h.string)
-- ctx.output.put_string ("Error occurred .. rq="+ request_count.out +"%N")
-- if attached (create {EXCEPTIONS}).exception_trace as l_trace then
-- ctx.output.put_string ("<pre>" + l_trace + "</pre>")
-- end
-- h.recycle
-- exit_with_code (-1)
-- end
execute_exit_application (ctx: APP_REQUEST_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
local
s: STRING
do
res.set_status_code (200)
res.put_header (200, <<["Content-Type", "text/html"]>>)
create s.make_empty
s.append_string ("Exited")
s.append_string (" <a href=%"" + req.script_url ("/") + "%">start again</a>%N")
res.put_string (s)
exit_with_code (0)
end
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,24 +0,0 @@
deferred class
REST_SERVICE_GATEWAY
inherit
WSF_SERVICE
feature -- Access
build_gateway_and_launch
local
cgi: WGI_CGI_CONNECTOR
do
create cgi.make (to_wgi_service)
cgi.launch
end
gateway_name: STRING = "CGI"
exit_with_code (a_code: INTEGER)
do
(create {EXCEPTIONS}).die (a_code)
end
end

View File

@@ -1,35 +0,0 @@
deferred class
REST_SERVICE_GATEWAY
inherit
WSF_SERVICE
feature -- Access
build_gateway_and_launch
local
libfcgi: WGI_LIBFCGI_CONNECTOR
do
create libfcgi.make (to_wgi_service)
libfcgi.launch
end
gateway_name: STRING = "libFCGI"
exit_with_code (a_code: INTEGER)
do
(create {EXCEPTIONS}).die (a_code)
end
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,44 +0,0 @@
deferred class
REST_SERVICE_GATEWAY
inherit
WSF_SERVICE
feature -- Access
build_gateway_and_launch
local
app: NINO_SERVICE
port_number: INTEGER
base_url: STRING
do
port_number := 8080
base_url := ""
debug ("nino")
print ("Example: start a Nino web server on port " + port_number.out +
", %Nand reply Hello World for any request such as http://localhost:" + port_number.out + "/" + base_url + "%N")
end
create app.make_custom (to_wgi_service, base_url)
app.force_single_threaded
app.listen (port_number)
end
gateway_name: STRING = "NINO"
exit_with_code (a_code: INTEGER)
do
(create {EXCEPTIONS}).die (a_code)
end
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,51 +0,0 @@
note
description: "Summary description for REST_REQUEST_AGENT_HANDLER."
author: ""
date: "$Date$"
revision: "$Revision$"
class
APP_REQUEST_AGENT_HANDLER
inherit
APP_REQUEST_HANDLER
-- undefine
-- execute, pre_execute, post_execute
-- end
REST_REQUEST_AGENT_HANDLER [APP_REQUEST_HANDLER_CONTEXT]
undefine
execute
-- authenticated
end
create
make
feature -- Access
execute_application (ctx: APP_REQUEST_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
do
execute (ctx, req, res)
end
authentication_required (req: WSF_REQUEST): BOOLEAN
-- Is authentication required
-- might depend on the request environment
-- or the associated resources
do
Result := False
end
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,85 +0,0 @@
note
description : "Objects that ..."
date : "$Date$"
revision : "$Revision$"
deferred class
APP_REQUEST_HANDLER
inherit
REST_REQUEST_HANDLER [APP_REQUEST_HANDLER_CONTEXT]
redefine
authenticated
end
APP_REQUEST_HELPER
feature {NONE} -- Initialization
initialize
-- Initialize various attributes
do
end
feature {NONE} -- Implementation
wgi_value_iteration_to_string (v: ITERABLE [WSF_VALUE]; using_pre: BOOLEAN): STRING_8
do
create Result.make (100)
if using_pre then
Result.append ("<pre>")
end
across
v as cur
loop
Result.append_string (cur.item.name.as_string_8 + " = " + cur.item.string_representation.as_string_8 + "%N")
end
if using_pre then
Result.append ("</pre>")
end
end
feature -- Auth
authenticated (ctx: APP_REQUEST_HANDLER_CONTEXT): BOOLEAN
-- Is authenticated?
do
--| To redefine if needed
if attached ctx.request.http_authorization as l_http_authorization then
Result := True
end
end
authenticated_identifier (ctx: APP_REQUEST_HANDLER_CONTEXT): detachable READABLE_STRING_32
do
if attached ctx.request.http_authorization as l_http_authorization then
Result := "foo" -- Implement it as you want
end
end
feature -- Helpers
format_id (s: detachable STRING): INTEGER
do
Result := {HTTP_FORMAT_CONSTANTS}.text
if s /= Void then
Result := format_constants.format_id (s)
end
end
exit_with_code (a_code: INTEGER)
do
(create {EXCEPTIONS}).die (a_code)
end
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,26 +0,0 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
class
APP_REQUEST_HANDLER_CONTEXT
inherit
REST_REQUEST_URI_TEMPLATE_HANDLER_CONTEXT
create
make
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,101 +0,0 @@
note
description: "Summary description for {APP_REQUEST_HELPER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
APP_REQUEST_HELPER
feature -- Helpers
send_error (a_path: STRING; a_error_id: INTEGER; a_error_name: STRING; a_error_message: detachable STRING; ctx: APP_REQUEST_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
local
s: STRING
i,nb: INTEGER
rep_data: REST_RESPONSE
do
res.set_status_code ({HTTP_STATUS_CODE}.expectation_failed)
create rep_data.make (a_path)
rep_data.headers.put_content_type_text_plain
create s.make_empty
inspect ctx.accepted_format_id
when {HTTP_FORMAT_CONSTANTS}.json then
rep_data.headers.put_content_type_text_plain
s := "{%"application%": %"" + a_path + "%""
s.append_string (", %"error%": {")
s.append_string ("%"id%": " + a_error_id.out)
s.append_string (",%"name%": %"" + a_error_name + "%"")
if a_error_message /= Void then
s.append_string (",%"message%": %"")
if a_error_message.has ('%N') then
from
i := s.count
s.append_string (a_error_message)
nb := s.count
until
i > nb
loop
inspect s[i]
when '%R' then
if s.valid_index (i+1) and then s[i+1] = '%N' then
s[i] := '\'
s[i+1] := 'n'
i := i + 1
end
when '%N' then
s.insert_character ('\', i)
s[i] := 'n'
else
end
i := i + 1
end
else
s.append_string (a_error_message)
end
s.append_string ("%"")
end
s.append_string ("}") -- end error
s.append_string ("}") -- end global object
rep_data.set_message (s)
when {HTTP_FORMAT_CONSTANTS}.xml then
rep_data.headers.put_content_type_text_xml
s := "<application path=%"" + a_path + "%"><error id=%"" + a_error_id.out + "%" name=%""+ a_error_name +"%">"
if a_error_message /= Void then
s.append_string (a_error_message)
end
s.append_string ("</error></application>")
rep_data.set_message (s)
when {HTTP_FORMAT_CONSTANTS}.html then
rep_data.headers.put_content_type_text_html
s := "<strong>application</strong>: " + a_path + "<br/>%N<strong>Error</strong> (" + a_error_id.out + ") %"" + a_error_name + "%"<br/>%N"
if a_error_message /= Void then
s.append_string ("<blockquote>" + a_error_message + "</blockquote>")
end
rep_data.set_message (s)
when {HTTP_FORMAT_CONSTANTS}.text then -- Default
s := "Application: " + a_path + "<br/>%N"
s.append_string ("Error (" + a_error_id.out + ") %"" + a_error_name + "%"%N")
if a_error_message /= Void then
s.append_string ("%T" + a_error_message + "%N")
end
rep_data.set_message (s)
end
res.send (rep_data)
rep_data.recycle
end
note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,49 +0,0 @@
note
description: "Summary description for {APP_REQUEST_ROUTING_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
APP_REQUEST_ROUTING_HANDLER
inherit
APP_REQUEST_HANDLER
rename
execute as uri_template_execute
undefine
uri_template_execute
end
WSF_URI_TEMPLATE_ROUTING_CONTEXT_HANDLER [APP_REQUEST_HANDLER_CONTEXT]
create
make
feature -- Access
authentication_required (req: WSF_REQUEST): BOOLEAN
-- Is authentication required
-- might depend on the request environment
-- or the associated resources
do
end
feature -- Execution
execute_application (ctx: APP_REQUEST_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
do
uri_template_execute (ctx, req, res)
end
;note
copyright: "Copyright (c) 1984-2011, 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

@@ -1,24 +0,0 @@
note
description: "Summary description for {APP_SERVICE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
APP_SERVICE
inherit
REST_SERVICE_I [APP_REQUEST_HANDLER_CONTEXT]
;note
copyright: "Copyright (c) 1984-2011, 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