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
## Requirements
* Developped using EiffelStudio 7.0 (on Windows, Linux)
* Tested using EiffelStudio 7.0 with "jenkins" CI server (and v6.8 for time to time)
* Compiling from EiffelStudio 7.0
* Developped using EiffelStudio 7.1 (on Windows, Linux)
* 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) )
## How to get the source code?

View File

@@ -17,7 +17,7 @@ feature {NONE} -- Initialization
local
h: LIBCURL_HTTP_CLIENT
sess: HTTP_CLIENT_SESSION
resp : HTTP_CLIENT_RESPONSE
resp : detachable HTTP_CLIENT_RESPONSE
l_location : detachable READABLE_STRING_8
body : STRING
do
@@ -39,7 +39,7 @@ feature {NONE} -- Initialization
-- 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.replace_substring_all ("takeAway", "in Shop")
print ("%N Update Order %N")
@@ -47,11 +47,10 @@ feature {NONE} -- Initialization
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
context : HTTP_CLIENT_REQUEST_CONTEXT
do
create Result.make
if attached uri as l_uri then
sess.set_base_url (l_uri)
create context.make
@@ -74,9 +73,8 @@ feature {NONE} -- Initialization
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
create Result.make
if attached uri as l_uri then
sess.set_base_url (l_uri)
Result := sess.get ("", Void)

View File

@@ -8,6 +8,7 @@
<exclude>/\.svn$</exclude>
</file_rule>
<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_cgi" location="../connector/cgi-safe.ecf"/>
<cluster name="default_cgi" location="./cgi" recursive="true"/>

View File

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

View File

@@ -8,6 +8,7 @@
<exclude>/\.svn$</exclude>
</file_rule>
<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_libfcgi" location="../connector/libfcgi-safe.ecf"/>
<cluster name="default_libfcgi" location="./libfcgi" recursive="true"/>

View File

@@ -8,6 +8,7 @@
<exclude>/\.svn$</exclude>
</file_rule>
<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_libfcgi" location="../connector/libfcgi.ecf"/>
<cluster name="default_libfcgi" location="./libfcgi" recursive="true"/>

View File

@@ -8,6 +8,7 @@
<exclude>/\.svn$</exclude>
</file_rule>
<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_nino" location="../connector/nino-safe.ecf"/>
<cluster name="default_nino" location="./nino" recursive="true"/>

View File

@@ -8,6 +8,7 @@
<exclude>/\.svn$</exclude>
</file_rule>
<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_nino" location="../connector/nino.ecf"/>
<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 Current for request `req' and router `a_router'
do
status_code := {HTTP_STATUS_CODE}.ok
request := req
router := a_router
end
@@ -31,13 +32,21 @@ feature {NONE} -- Initialization
--| note: it could be "/doc" or "/api/doc" or ...
do
make (req, a_router)
if a_resource /= Void and then attached a_router.base_url as l_base_url then
resource := l_base_url + a_resource
if a_resource /= Void then
if attached a_router.base_url as l_base_url then
resource := l_base_url + a_resource
else
resource := a_resource
end
end
end
feature -- Access
status_code: INTEGER
-- Associated status code
-- Default is Ok
request: WSF_REQUEST
router: WSF_ROUTER
@@ -57,6 +66,13 @@ feature -- Properties
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)
do
header := v
@@ -97,8 +113,10 @@ feature {WSF_RESPONSE} -- Output
l_description.append ("[
<style type="text/css">
.mappingresource { color: #00f; }
.mappingdoc { color: #900; }
.mappingdoc { color: #900; float: right}
.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; }
</style>
]")
@@ -141,12 +159,12 @@ feature {WSF_RESPONSE} -- Output
l_description.append ("<a href=%""+ doc_url ("") + "%">Index</a><br/>")
end
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)
l_description.append ("</ul>")
end
else
l_description.append ("<h2>Router</h2><ul>")
l_description.append ("<h2>Router</h2><ul class=%"mapping%">")
across
router as c
loop
@@ -165,9 +183,10 @@ feature {WSF_RESPONSE} -- Output
l_description.append ("</body></html>")
-- Compute and send the response message
h.put_content_length (l_description.count)
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_string (l_description)
end
@@ -177,76 +196,81 @@ feature {WSF_RESPONSE} -- Output
l_url: detachable STRING_8
l_base_url: detachable READABLE_STRING_8
hdl: WSF_HANDLER
l_doc: detachable WSF_ROUTER_MAPPING_DOCUMENTATION
do
l_base_url := router.base_url
if l_base_url = Void then
l_base_url := ""
end
l_url := Void
s.append ("<li>")
s.append ("<code>")
if doc_url_supported then
s.append ("<a class=%"mappingresource%" href=%"")
s.append (doc_url (m.associated_resource))
s.append ("%">")
s.append (m.associated_resource)
s.append ("</a>")
else
s.append (m.associated_resource)
end
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
s.append (" [")
across
meths as rq
loop
s.append (" ")
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>")
else
s.append (rq.item)
end
s.append (",")
end
if s[s.count] = ',' then
s.put (' ', s.count) -- Remove last ','
else
s.append_character (' ')
end
s.append_character (']')
l_doc := l_doc_mapping.documentation
end
if l_doc = Void or else not l_doc.is_hidden then
hdl := m.handler
if attached {WSF_SELF_DOCUMENTED_HANDLER} hdl as l_doc_handler and then attached l_doc_handler.documentation as l_doc then
s.append ("%N<ul class=%"handlerdoc%">")
s.append (html_encoder.encoded_string (l_doc))
s.append ("%N</ul>%N")
else
debug
l_base_url := router.base_url
if l_base_url = Void then
l_base_url := ""
end
l_url := Void
s.append ("<li>")
s.append ("<code>")
if doc_url_supported then
s.append ("<a class=%"mappingresource%" href=%"")
s.append (doc_url (m.associated_resource))
s.append ("%">")
s.append (m.associated_resource)
s.append ("</a>")
else
s.append (m.associated_resource)
end
s.append ("</code>")
if meths /= Void then
s.append (" [")
across
meths as rq
loop
s.append_character (' ')
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>")
else
s.append (rq.item)
end
s.append_character (',')
end
if s[s.count] = ',' then
s.put (' ', s.count)
else
s.append_character (' ')
end
s.append_character (']')
end
s.append (" <em class=%"mappingdoc%">" + html_encoder.encoded_string (m.description) + "</em> ")
if l_doc /= Void and then not l_doc.is_empty then
s.append ("%N<ul class=%"handlerdoc%">")
s.append (hdl.generating_type.out)
s.append (html_encoder.encoded_string (l_doc.description))
s.append ("%N</ul>%N")
else
debug
s.append ("%N<ul class=%"handlerdoc%">")
s.append (m.handler.generating_type.out)
s.append ("%N</ul>%N")
end
end
if attached {WSF_ROUTING_HANDLER} m.handler as l_routing_hdl then
s.append ("%N<ul>%N")
across
l_routing_hdl.router as c
loop
append_documentation_to (s, c.item.mapping, c.item.request_methods)
end
s.append ("%N</ul>%N")
end
end
if attached {WSF_ROUTING_HANDLER} hdl as l_routing_hdl then
s.append ("%N<ul>%N")
across
l_routing_hdl.router as c
loop
append_documentation_to (s, c.item.mapping, c.item.request_methods)
s.append ("</li>%N")
else
debug
s.append ("<li>" + m.associated_resource + " is HIDDEN</li>%N")
end
s.append ("%N</ul>%N")
end
s.append ("</li>%N")
end
feature {NONE} -- Implementation

View File

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

View File

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

View File

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

View File

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

View File

@@ -12,8 +12,6 @@ inherit
WSF_SELF_DOCUMENTED_ROUTER_MAPPING
DEBUG_OUTPUT
create
make,
make_from_template
@@ -45,15 +43,7 @@ feature -- Access
feature -- Documentation
documentation: 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
description: STRING_32 = "Match-URI-Template"
feature -- Element change

View File

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

View File

@@ -7,9 +7,13 @@ note
deferred class
WSF_ROUTER_MAPPING
inherit
DEBUG_OUTPUT
feature {NONE} -- Initialization
make (a_resource: READABLE_STRING_8; h: like handler)
-- Create mapping based on resource `a_resource' and handler `h'
deferred
end
@@ -25,6 +29,21 @@ feature -- Access
deferred
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
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER