Merge branch 'master' of github.com:EiffelWebFramework/EWF

This commit is contained in:
Jocelyn Fiat
2012-12-03 11:13:59 +01:00
17 changed files with 190 additions and 103 deletions

View File

@@ -15,9 +15,9 @@ For download, check
* https://github.com/EiffelWebFramework/EWF/downloads * https://github.com/EiffelWebFramework/EWF/downloads
## Requirements ## Requirements
* Compiling from EiffelStudio 7.0
* Developped using EiffelStudio 7.0 (on Windows, Linux) * Developped using EiffelStudio 7.1 (on Windows, Linux)
* Tested using EiffelStudio 7.0 with "jenkins" CI server (and v6.8 for time to time) * Tested using EiffelStudio 7.1 with "jenkins" CI server (not anymore compatible with 6.8 due to use of `TABLE_ITERABLE')
* The code have to allow __void-safe__ compilation and non void-safe system (see [more about void-safety](http://docs.eiffel.com/book/method/void-safe-programming-eiffel) ) * The code have to allow __void-safe__ compilation and non void-safe system (see [more about void-safety](http://docs.eiffel.com/book/method/void-safe-programming-eiffel) )
## How to get the source code? ## How to get the source code?

View File

@@ -17,7 +17,7 @@ feature {NONE} -- Initialization
local local
h: LIBCURL_HTTP_CLIENT h: LIBCURL_HTTP_CLIENT
sess: HTTP_CLIENT_SESSION sess: HTTP_CLIENT_SESSION
resp : HTTP_CLIENT_RESPONSE resp : detachable HTTP_CLIENT_RESPONSE
l_location : detachable READABLE_STRING_8 l_location : detachable READABLE_STRING_8
body : STRING body : STRING
do do
@@ -39,7 +39,7 @@ feature {NONE} -- Initialization
-- Update the Order -- Update the Order
if attached resp.body as l_body then if resp /= Void and then attached resp.body as l_body then
body := l_body.as_string_8 body := l_body.as_string_8
body.replace_substring_all ("takeAway", "in Shop") body.replace_substring_all ("takeAway", "in Shop")
print ("%N Update Order %N") print ("%N Update Order %N")
@@ -47,11 +47,10 @@ feature {NONE} -- Initialization
end end
end end
update_order ( sess: HTTP_CLIENT_SESSION; uri : detachable READABLE_STRING_8; a_body : STRING) : HTTP_CLIENT_RESPONSE update_order ( sess: HTTP_CLIENT_SESSION; uri : detachable READABLE_STRING_8; a_body : STRING): detachable HTTP_CLIENT_RESPONSE
local local
context : HTTP_CLIENT_REQUEST_CONTEXT context : HTTP_CLIENT_REQUEST_CONTEXT
do do
create Result.make
if attached uri as l_uri then if attached uri as l_uri then
sess.set_base_url (l_uri) sess.set_base_url (l_uri)
create context.make create context.make
@@ -74,9 +73,8 @@ feature {NONE} -- Initialization
end end
read_order ( sess: HTTP_CLIENT_SESSION; uri : detachable READABLE_STRING_8) : HTTP_CLIENT_RESPONSE read_order ( sess: HTTP_CLIENT_SESSION; uri : detachable READABLE_STRING_8): detachable HTTP_CLIENT_RESPONSE
do do
create Result.make
if attached uri as l_uri then if attached uri as l_uri then
sess.set_base_url (l_uri) sess.set_base_url (l_uri)
Result := sess.get ("", Void) Result := sess.get ("", Void)

View File

@@ -8,6 +8,7 @@
<exclude>/\.svn$</exclude> <exclude>/\.svn$</exclude>
</file_rule> </file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional"/> <option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="wsf" location="../wsf-safe.ecf"/> <library name="wsf" location="../wsf-safe.ecf"/>
<library name="wsf_cgi" location="../connector/cgi-safe.ecf"/> <library name="wsf_cgi" location="../connector/cgi-safe.ecf"/>
<cluster name="default_cgi" location="./cgi" recursive="true"/> <cluster name="default_cgi" location="./cgi" recursive="true"/>

View File

@@ -9,6 +9,7 @@
</file_rule> </file_rule>
<option warning="true" full_class_checking="true" syntax="provisional"> <option warning="true" full_class_checking="true" syntax="provisional">
</option> </option>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="wsf" location="../wsf.ecf"/> <library name="wsf" location="../wsf.ecf"/>
<library name="wsf_cgi" location="../connector/cgi.ecf"/> <library name="wsf_cgi" location="../connector/cgi.ecf"/>
<cluster name="default_cgi" location="./cgi" recursive="true"/> <cluster name="default_cgi" location="./cgi" recursive="true"/>

View File

@@ -8,6 +8,7 @@
<exclude>/\.svn$</exclude> <exclude>/\.svn$</exclude>
</file_rule> </file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional"/> <option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="wsf" location="../wsf-safe.ecf"/> <library name="wsf" location="../wsf-safe.ecf"/>
<library name="wsf_libfcgi" location="../connector/libfcgi-safe.ecf"/> <library name="wsf_libfcgi" location="../connector/libfcgi-safe.ecf"/>
<cluster name="default_libfcgi" location="./libfcgi" recursive="true"/> <cluster name="default_libfcgi" location="./libfcgi" recursive="true"/>

View File

@@ -8,6 +8,7 @@
<exclude>/\.svn$</exclude> <exclude>/\.svn$</exclude>
</file_rule> </file_rule>
<option warning="true" full_class_checking="true" syntax="provisional"/> <option warning="true" full_class_checking="true" syntax="provisional"/>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="wsf" location="../wsf.ecf"/> <library name="wsf" location="../wsf.ecf"/>
<library name="wsf_libfcgi" location="../connector/libfcgi.ecf"/> <library name="wsf_libfcgi" location="../connector/libfcgi.ecf"/>
<cluster name="default_libfcgi" location="./libfcgi" recursive="true"/> <cluster name="default_libfcgi" location="./libfcgi" recursive="true"/>

View File

@@ -8,6 +8,7 @@
<exclude>/\.svn$</exclude> <exclude>/\.svn$</exclude>
</file_rule> </file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional"/> <option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="wsf" location="../wsf-safe.ecf"/> <library name="wsf" location="../wsf-safe.ecf"/>
<library name="wsf_nino" location="../connector/nino-safe.ecf"/> <library name="wsf_nino" location="../connector/nino-safe.ecf"/>
<cluster name="default_nino" location="./nino" recursive="true"/> <cluster name="default_nino" location="./nino" recursive="true"/>

View File

@@ -8,6 +8,7 @@
<exclude>/\.svn$</exclude> <exclude>/\.svn$</exclude>
</file_rule> </file_rule>
<option warning="true" full_class_checking="true" syntax="provisional"/> <option warning="true" full_class_checking="true" syntax="provisional"/>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="wsf" location="../wsf.ecf"/> <library name="wsf" location="../wsf.ecf"/>
<library name="wsf_nino" location="../connector/nino.ecf"/> <library name="wsf_nino" location="../connector/nino.ecf"/>
<cluster name="default_nino" location="./nino" recursive="true"/> <cluster name="default_nino" location="./nino" recursive="true"/>

View File

@@ -0,0 +1,52 @@
note
description: "Summary description for {WSF_ROUTER_MAPPING_DOCUMENTATION}."
date: "$Date$"
revision: "$Revision$"
class
WSF_ROUTER_MAPPING_DOCUMENTATION
create
make
feature {NONE} -- Initialization
make (m: like mapping)
do
mapping := m
create {STRING_32} description.make_empty
end
feature -- Status report
is_hidden: BOOLEAN
-- Hide this mapping from any self documentation?
-- Default=False
is_empty: BOOLEAN
-- Is Current empty?
-- i.e: does not carry any information.
do
Result := description.is_empty
end
feature -- Access
mapping: WSF_ROUTER_MAPPING
-- Associated mapping
description: STRING_32
feature -- Change
set_is_hidden (b: BOOLEAN)
do
is_hidden := b
end
add_description (d: READABLE_STRING_GENERAL)
do
description.append_string_general (d)
end
end

View File

@@ -21,6 +21,7 @@ feature {NONE} -- Initialization
make (req: WSF_REQUEST; a_router: WSF_ROUTER) make (req: WSF_REQUEST; a_router: WSF_ROUTER)
-- Make Current for request `req' and router `a_router' -- Make Current for request `req' and router `a_router'
do do
status_code := {HTTP_STATUS_CODE}.ok
request := req request := req
router := a_router router := a_router
end end
@@ -31,13 +32,21 @@ feature {NONE} -- Initialization
--| note: it could be "/doc" or "/api/doc" or ... --| note: it could be "/doc" or "/api/doc" or ...
do do
make (req, a_router) make (req, a_router)
if a_resource /= Void and then attached a_router.base_url as l_base_url then if a_resource /= Void then
if attached a_router.base_url as l_base_url then
resource := l_base_url + a_resource resource := l_base_url + a_resource
else
resource := a_resource
end
end end
end end
feature -- Access feature -- Access
status_code: INTEGER
-- Associated status code
-- Default is Ok
request: WSF_REQUEST request: WSF_REQUEST
router: WSF_ROUTER router: WSF_ROUTER
@@ -57,6 +66,13 @@ feature -- Properties
feature -- Change feature -- Change
set_status_code (c: like status_code)
require
c_positive_or_zero: c >= 0
do
status_code := c
end
set_header (v: like header) set_header (v: like header)
do do
header := v header := v
@@ -97,8 +113,10 @@ feature {WSF_RESPONSE} -- Output
l_description.append ("[ l_description.append ("[
<style type="text/css"> <style type="text/css">
.mappingresource { color: #00f; } .mappingresource { color: #00f; }
.mappingdoc { color: #900; } .mappingdoc { color: #900; float: right}
.handlerdoc { white-space: pre; } .handlerdoc { white-space: pre; }
ul.mapping { margin: 0; padding: 5px; list-style-type: none; }
ul.mapping>li { margin-bottom: 5px; padding-left: 5px; border-left: solid 3px #ccc; border-top: dotted 1px #ccc; }
div#footer { padding: 10px; width: 100%; margin-top: 20px; border-top: 1px dotted #999; color: #999; text-align: center; } div#footer { padding: 10px; width: 100%; margin-top: 20px; border-top: 1px dotted #999; color: #999; text-align: center; }
</style> </style>
]") ]")
@@ -141,12 +159,12 @@ feature {WSF_RESPONSE} -- Output
l_description.append ("<a href=%""+ doc_url ("") + "%">Index</a><br/>") l_description.append ("<a href=%""+ doc_url ("") + "%">Index</a><br/>")
end end
if attached router.item_associated_with_resource (l_api_resource, Void) as l_api_item then if attached router.item_associated_with_resource (l_api_resource, Void) as l_api_item then
l_description.append ("<h2>Information related to %"" + l_api_resource + "%"</h2><ul>") l_description.append ("<h2>Information related to <code>" + l_api_resource + "</code></h2><ul class=%"mapping%">")
append_documentation_to (l_description, l_api_item.mapping, l_api_item.request_methods) append_documentation_to (l_description, l_api_item.mapping, l_api_item.request_methods)
l_description.append ("</ul>") l_description.append ("</ul>")
end end
else else
l_description.append ("<h2>Router</h2><ul>") l_description.append ("<h2>Router</h2><ul class=%"mapping%">")
across across
router as c router as c
loop loop
@@ -165,9 +183,10 @@ feature {WSF_RESPONSE} -- Output
l_description.append ("</body></html>") l_description.append ("</body></html>")
-- Compute and send the response message
h.put_content_length (l_description.count) h.put_content_length (l_description.count)
h.put_current_date h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.ok) res.set_status_code (status_code)
res.put_header_text (h.string) res.put_header_text (h.string)
res.put_string (l_description) res.put_string (l_description)
end end
@@ -177,7 +196,13 @@ feature {WSF_RESPONSE} -- Output
l_url: detachable STRING_8 l_url: detachable STRING_8
l_base_url: detachable READABLE_STRING_8 l_base_url: detachable READABLE_STRING_8
hdl: WSF_HANDLER hdl: WSF_HANDLER
l_doc: detachable WSF_ROUTER_MAPPING_DOCUMENTATION
do do
if attached {WSF_SELF_DOCUMENTED_ROUTER_MAPPING} m as l_doc_mapping then
l_doc := l_doc_mapping.documentation
end
if l_doc = Void or else not l_doc.is_hidden then
l_base_url := router.base_url l_base_url := router.base_url
if l_base_url = Void then if l_base_url = Void then
l_base_url := "" l_base_url := ""
@@ -197,47 +222,41 @@ feature {WSF_RESPONSE} -- Output
end end
s.append ("</code>") s.append ("</code>")
if attached {WSF_SELF_DOCUMENTED_ROUTER_MAPPING} m as l_doc_mapping then
s.append (" <em class=%"mappingdoc%">" + html_encoder.encoded_string (l_doc_mapping.documentation) + "</em> ")
else
debug
s.append (" <em class=%"mappingdoc%">" + m.generating_type.out + "</em> ")
end
end
if meths /= Void then if meths /= Void then
s.append (" [") s.append (" [")
across across
meths as rq meths as rq
loop loop
s.append (" ") s.append_character (' ')
if l_url /= Void and then rq.item.is_case_insensitive_equal ("GET") then if l_url /= Void and then rq.item.is_case_insensitive_equal ("GET") then
s.append ("<a href=%"" + l_base_url + l_url + "%">" + rq.item + "</a>") s.append ("<a href=%"" + l_base_url + l_url + "%">" + rq.item + "</a>")
else else
s.append (rq.item) s.append (rq.item)
end end
s.append (",") s.append_character (',')
end end
if s[s.count] = ',' then if s[s.count] = ',' then
s.put (' ', s.count) -- Remove last ',' s.put (' ', s.count)
else else
s.append_character (' ') s.append_character (' ')
end end
s.append_character (']') s.append_character (']')
end end
hdl := m.handler s.append (" <em class=%"mappingdoc%">" + html_encoder.encoded_string (m.description) + "</em> ")
if attached {WSF_SELF_DOCUMENTED_HANDLER} hdl as l_doc_handler and then attached l_doc_handler.documentation as l_doc then
if l_doc /= Void and then not l_doc.is_empty then
s.append ("%N<ul class=%"handlerdoc%">") s.append ("%N<ul class=%"handlerdoc%">")
s.append (html_encoder.encoded_string (l_doc)) s.append (html_encoder.encoded_string (l_doc.description))
s.append ("%N</ul>%N") s.append ("%N</ul>%N")
else else
debug debug
s.append ("%N<ul class=%"handlerdoc%">") s.append ("%N<ul class=%"handlerdoc%">")
s.append (hdl.generating_type.out) s.append (m.handler.generating_type.out)
s.append ("%N</ul>%N") s.append ("%N</ul>%N")
end end
end end
if attached {WSF_ROUTING_HANDLER} hdl as l_routing_hdl then if attached {WSF_ROUTING_HANDLER} m.handler as l_routing_hdl then
s.append ("%N<ul>%N") s.append ("%N<ul>%N")
across across
l_routing_hdl.router as c l_routing_hdl.router as c
@@ -247,6 +266,11 @@ feature {WSF_RESPONSE} -- Output
s.append ("%N</ul>%N") s.append ("%N</ul>%N")
end end
s.append ("</li>%N") s.append ("</li>%N")
else
debug
s.append ("<li>" + m.associated_resource + " is HIDDEN</li>%N")
end
end
end end
feature {NONE} -- Implementation feature {NONE} -- Implementation

View File

@@ -9,7 +9,7 @@ deferred class
feature -- Documentation feature -- Documentation
documentation: detachable READABLE_STRING_32 mapping_documentation (m: WSF_ROUTER_MAPPING): WSF_ROUTER_MAPPING_DOCUMENTATION
deferred deferred
end end

View File

@@ -7,10 +7,18 @@ note
deferred class deferred class
WSF_SELF_DOCUMENTED_ROUTER_MAPPING WSF_SELF_DOCUMENTED_ROUTER_MAPPING
inherit
WSF_ROUTER_MAPPING
feature -- Documentation feature -- Documentation
documentation: READABLE_STRING_32 documentation: WSF_ROUTER_MAPPING_DOCUMENTATION
deferred do
if attached {WSF_SELF_DOCUMENTED_HANDLER} handler as obj then
Result := obj.mapping_documentation (Current)
else
create Result.make (Current)
end
end end
end end

View File

@@ -35,7 +35,7 @@ feature -- Access
feature -- Documentation feature -- Documentation
documentation: STRING_32 = "Starts-With-URI" description: STRING_32 = "Starts-With-URI"
feature -- Status feature -- Status

View File

@@ -46,7 +46,7 @@ feature -- Access
feature -- Documentation feature -- Documentation
documentation: STRING_32 = "Is-URI" description: STRING_32 = "Is-URI"
feature -- Status feature -- Status

View File

@@ -12,8 +12,6 @@ inherit
WSF_SELF_DOCUMENTED_ROUTER_MAPPING WSF_SELF_DOCUMENTED_ROUTER_MAPPING
DEBUG_OUTPUT
create create
make, make,
make_from_template make_from_template
@@ -45,15 +43,7 @@ feature -- Access
feature -- Documentation feature -- Documentation
documentation: STRING_32 = "Match-URI-Template" description: STRING_32 = "Match-URI-Template"
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := "URI-template: " + template.template
end
feature -- Element change feature -- Element change

View File

@@ -12,8 +12,6 @@ inherit
WSF_SELF_DOCUMENTED_ROUTER_MAPPING WSF_SELF_DOCUMENTED_ROUTER_MAPPING
DEBUG_OUTPUT
create create
make, make,
make_from_template make_from_template
@@ -45,15 +43,7 @@ feature -- Access
feature -- Documentation feature -- Documentation
documentation: STRING_32 = "Is-URI" description: STRING_32 = "Match-URI-Template"
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := "URI-template: " + template.template
end
feature -- Element change feature -- Element change

View File

@@ -7,9 +7,13 @@ note
deferred class deferred class
WSF_ROUTER_MAPPING WSF_ROUTER_MAPPING
inherit
DEBUG_OUTPUT
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_resource: READABLE_STRING_8; h: like handler) make (a_resource: READABLE_STRING_8; h: like handler)
-- Create mapping based on resource `a_resource' and handler `h'
deferred deferred
end end
@@ -25,6 +29,21 @@ feature -- Access
deferred deferred
end end
feature -- Documentation
description: READABLE_STRING_32
-- Short description of associated mapping.
deferred
end
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := description.as_string_8 + " : " + associated_resource
end
feature -- Status feature -- Status
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER