Updated workbook Eiffel code to follow new EWF concurrent design.
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
note
|
||||
description : "Basic Service that show how to use common Status Code"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
description: "Basic Service launcher"
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_SERVICE
|
||||
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
@@ -23,25 +21,4 @@ feature {NONE} -- Initialization
|
||||
set_service_option ("port", 9090)
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute the incomming request
|
||||
do
|
||||
-- To send a response we need to setup, the status code and
|
||||
-- the response headers.
|
||||
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/csv"],["Content-Disposition","attachment;filename=Report.xls"],["Content-Length", sheet.count.out]>>)
|
||||
res.put_string (sheet)
|
||||
end
|
||||
|
||||
-- ,["Content-Disposition","attachment;filename=Report.xls"]
|
||||
|
||||
|
||||
sheet: STRING ="[
|
||||
Q1 Q2 Q3 Q4 Total
|
||||
Cherries 78 87 92 29 =SUM(B2:E2)
|
||||
Grapes 77 86 93 30 =SUM(B3:E3)
|
||||
]"
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
note
|
||||
description : "Basic Service that show how to use common Status Code"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
APPLICATION_EXECUTION
|
||||
|
||||
inherit
|
||||
WSF_EXECUTION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Execute the incomming request
|
||||
do
|
||||
-- To send a response we need to setup, the status code and
|
||||
-- the response headers.
|
||||
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/csv"],["Content-Disposition","attachment;filename=Report.xls"],["Content-Length", sheet.count.out]>>)
|
||||
response.put_string (sheet)
|
||||
end
|
||||
|
||||
-- ,["Content-Disposition","attachment;filename=Report.xls"]
|
||||
|
||||
|
||||
sheet: STRING ="[
|
||||
Q1 Q2 Q3 Q4 Total
|
||||
Cherries 78 87 92 29 =SUM(B2:E2)
|
||||
Grapes 77 86 93 30 =SUM(B3:E3)
|
||||
]"
|
||||
|
||||
|
||||
end
|
||||
@@ -1,13 +1,11 @@
|
||||
note
|
||||
description : "Basic Service that build a generic front end for the most used search engines."
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
description: "Basic Service launcher"
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_SERVICE
|
||||
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
@@ -23,46 +21,4 @@ feature {NONE} -- Initialization
|
||||
set_service_option ("port", 9090)
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute the incomming request
|
||||
local
|
||||
l_message: STRING
|
||||
do
|
||||
-- (1) To send a response we need to setup, the status code and the response headers.
|
||||
-- res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>)
|
||||
-- res.put_string (web_page)
|
||||
|
||||
-- (2) Using put_header_line
|
||||
-- res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||
-- res.put_header_line ("Content-Type:text/html")
|
||||
res.put_header_line ("Content-Length:"+ web_page.count.out)
|
||||
res.put_header_line ("Content-Type:text/plain")
|
||||
|
||||
res.put_string (web_page)
|
||||
end
|
||||
|
||||
|
||||
|
||||
feature -- Home Page
|
||||
|
||||
web_page: STRING = "[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>EWF Headers Responses</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="right">
|
||||
<h2>Example Header Response</h2>
|
||||
<p>Response headers</p>
|
||||
|
||||
</div>
|
||||
<div id="footer">
|
||||
<p>EWF Response Header</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
end
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
note
|
||||
description : "Basic Service that build a generic front end for the most used search engines."
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
APPLICATION_EXECUTION
|
||||
|
||||
inherit
|
||||
WSF_EXECUTION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Execute the incomming request
|
||||
local
|
||||
l_message: STRING
|
||||
do
|
||||
-- (1) To send a response we need to setup, the status code and the response headers.
|
||||
-- response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>)
|
||||
-- response.put_string (web_page)
|
||||
|
||||
-- (2) Using put_header_line
|
||||
-- response.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||
-- response.put_header_line ("Content-Type:text/html")
|
||||
response.put_header_line ("Content-Length:"+ web_page.count.out)
|
||||
response.put_header_line ("Content-Type:text/plain")
|
||||
|
||||
response.put_string (web_page)
|
||||
end
|
||||
|
||||
|
||||
|
||||
feature -- Home Page
|
||||
|
||||
web_page: STRING = "[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>EWF Headers Responses</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="right">
|
||||
<h2>Example Header Response</h2>
|
||||
<p>Response headers</p>
|
||||
|
||||
</div>
|
||||
<div id="footer">
|
||||
<p>EWF Response Header</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
end
|
||||
@@ -1,13 +1,11 @@
|
||||
note
|
||||
description : "Basic Service that build a generic front end for the most used search engines."
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
description: "Basic Service launcher"
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_SERVICE
|
||||
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
@@ -23,161 +21,4 @@ feature {NONE} -- Initialization
|
||||
set_service_option ("port", 9090)
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute the incomming request
|
||||
local
|
||||
l_message: STRING
|
||||
do
|
||||
-- To send a response we need to setup, the status code and
|
||||
-- the response headers.
|
||||
if req.is_get_request_method then
|
||||
if req.path_info.same_string ("/") then
|
||||
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>)
|
||||
res.put_string (web_page)
|
||||
else
|
||||
send_resouce_not_found (req, res)
|
||||
end
|
||||
elseif req.is_post_request_method then
|
||||
if req.path_info.same_string ("/search") then
|
||||
if attached {WSF_STRING} req.form_parameter ("query") as l_query then
|
||||
if attached {WSF_STRING} req.form_parameter ("engine") as l_engine then
|
||||
if attached {STRING} map.at (l_engine.value) as l_engine_url then
|
||||
l_engine_url.append (l_query.value)
|
||||
send_redirect (req, res, l_engine_url)
|
||||
-- res.redirect_now (l_engine_url)
|
||||
else
|
||||
send_bad_request (req, res, " <strong>search engine: " + l_engine.value + "</strong> not supported,<br> try with Google or Bing")
|
||||
end
|
||||
else
|
||||
send_bad_request (req, res, " <strong>search engine</strong> not selected")
|
||||
end
|
||||
else
|
||||
send_bad_request (req, res, " form_parameter <strong>query</strong> is not present")
|
||||
end
|
||||
else
|
||||
send_resouce_not_found (req, res)
|
||||
end
|
||||
else
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Method Not Allowed")
|
||||
l_message.replace_substring_all ("$status", "Method Not Allowed 405")
|
||||
-- Method not allowed
|
||||
res.put_header ({HTTP_STATUS_CODE}.method_not_allowed, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
res.put_string (l_message)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature -- Engine Map
|
||||
|
||||
map : STRING_TABLE[STRING]
|
||||
do
|
||||
create Result.make (2)
|
||||
Result.put ("http://www.google.com/search?q=", "Google")
|
||||
Result.put ("http://www.bing.com/search?q=", "Bing")
|
||||
end
|
||||
|
||||
feature -- Redirect
|
||||
|
||||
send_redirect (req: WSF_REQUEST; res: WSF_RESPONSE; a_location: READABLE_STRING_32)
|
||||
-- Redirect to `a_location'
|
||||
local
|
||||
h: HTTP_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_text_html
|
||||
h.put_current_date
|
||||
h.put_location (a_location)
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.see_other)
|
||||
res.put_header_text (h.string)
|
||||
end
|
||||
|
||||
feature -- Bad Request
|
||||
|
||||
send_bad_request (req: WSF_REQUEST; res: WSF_RESPONSE; description: STRING)
|
||||
local
|
||||
l_message: STRING
|
||||
do
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Bad Request")
|
||||
l_message.replace_substring_all ("$status", "Bad Request" + description)
|
||||
res.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
res.put_string (l_message)
|
||||
end
|
||||
|
||||
feature -- Resource not found
|
||||
|
||||
send_resouce_not_found (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
l_message: STRING
|
||||
do
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Resource not found")
|
||||
l_message.replace_substring_all ("$status", "Resource " + req.request_uri + " not found 404")
|
||||
res.put_header ({HTTP_STATUS_CODE}.not_found, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
res.put_string (l_message)
|
||||
end
|
||||
|
||||
feature -- Home Page
|
||||
|
||||
web_page: STRING = "[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Generic Search Engine</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="right">
|
||||
<h2>Generic Search Engine</h2>
|
||||
<form method="POST" action="/search" target="_blank">
|
||||
<fieldset>
|
||||
Search: <input type="search" name="query" placeholder="EWF framework"><br>
|
||||
<div>
|
||||
<input type="radio" name="engine" value="Google" checked><img src="http://ebizmba.ebizmbainc.netdna-cdn.com/images/logos/google.gif" height="24" width="42">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="radio" name="engine" value="Bing"><img src="http://ebizmba.ebizmbainc.netdna-cdn.com/images/logos/bing.gif" height="24" width="42">
|
||||
</div><br>
|
||||
</fieldset>
|
||||
<input type="submit">
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
<div id="footer">
|
||||
<p><a href="http://www.ebizmba.com/articles/search-engines">Top 15 Most Popular Search Engines | March 2015</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
|
||||
feature -- Generic Message
|
||||
|
||||
message_template: STRING="[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>$title</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<p id="name">Use a tool to see the request and header details, for example (Developers tools in Chrome or Firebugs in Firefox)</p>
|
||||
</div>
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<h4>This page is an example of $status</h4>
|
||||
|
||||
<div id="footer">
|
||||
<p><a href="/">Back Home</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
172
doc/workbook/generating_response/search/application_execution.e
Normal file
172
doc/workbook/generating_response/search/application_execution.e
Normal file
@@ -0,0 +1,172 @@
|
||||
note
|
||||
description : "Basic Service that build a generic front end for the most used search engines."
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
APPLICATION_EXECUTION
|
||||
|
||||
inherit
|
||||
WSF_EXECUTION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Execute the incomming request
|
||||
local
|
||||
l_message: STRING
|
||||
do
|
||||
-- To send a response we need to setup, the status code and
|
||||
-- the response headers.
|
||||
if request.is_get_request_method then
|
||||
if request.path_info.same_string ("/") then
|
||||
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>)
|
||||
response.put_string (web_page)
|
||||
else
|
||||
send_resouce_not_found (request, response)
|
||||
end
|
||||
elseif request.is_post_request_method then
|
||||
if request.path_info.same_string ("/search") then
|
||||
if attached {WSF_STRING} request.form_parameter ("query") as l_query then
|
||||
if attached {WSF_STRING} request.form_parameter ("engine") as l_engine then
|
||||
if attached {STRING} map.at (l_engine.value) as l_engine_url then
|
||||
l_engine_url.append (l_query.value)
|
||||
send_redirect (request, response, l_engine_url)
|
||||
-- response.redirect_now (l_engine_url)
|
||||
else
|
||||
send_bad_request (request, response, " <strong>search engine: " + l_engine.value + "</strong> not supported,<br> try with Google or Bing")
|
||||
end
|
||||
else
|
||||
send_bad_request (request, response, " <strong>search engine</strong> not selected")
|
||||
end
|
||||
else
|
||||
send_bad_request (request, response, " form_parameter <strong>query</strong> is not present")
|
||||
end
|
||||
else
|
||||
send_resouce_not_found (request, response)
|
||||
end
|
||||
else
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Method Not Allowed")
|
||||
l_message.replace_substring_all ("$status", "Method Not Allowed 405")
|
||||
-- Method not allowed
|
||||
response.put_header ({HTTP_STATUS_CODE}.method_not_allowed, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
response.put_string (l_message)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature -- Engine Map
|
||||
|
||||
map : STRING_TABLE[STRING]
|
||||
do
|
||||
create Result.make (2)
|
||||
Result.put ("http://www.google.com/search?q=", "Google")
|
||||
Result.put ("http://www.bing.com/search?q=", "Bing")
|
||||
end
|
||||
|
||||
feature -- Redirect
|
||||
|
||||
send_redirect (req: WSF_REQUEST; res: WSF_RESPONSE; a_location: READABLE_STRING_32)
|
||||
-- Redirect to `a_location'
|
||||
local
|
||||
h: HTTP_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_text_html
|
||||
h.put_current_date
|
||||
h.put_location (a_location)
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.see_other)
|
||||
res.put_header_text (h.string)
|
||||
end
|
||||
|
||||
feature -- Bad Request
|
||||
|
||||
send_bad_request (req: WSF_REQUEST; res: WSF_RESPONSE; description: STRING)
|
||||
local
|
||||
l_message: STRING
|
||||
do
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Bad Request")
|
||||
l_message.replace_substring_all ("$status", "Bad Request" + description)
|
||||
res.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
res.put_string (l_message)
|
||||
end
|
||||
|
||||
feature -- Resource not found
|
||||
|
||||
send_resouce_not_found (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
l_message: STRING
|
||||
do
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Resource not found")
|
||||
l_message.replace_substring_all ("$status", "Resource " + req.request_uri + " not found 404")
|
||||
res.put_header ({HTTP_STATUS_CODE}.not_found, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
res.put_string (l_message)
|
||||
end
|
||||
|
||||
feature -- Home Page
|
||||
|
||||
web_page: STRING = "[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Generic Search Engine</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="right">
|
||||
<h2>Generic Search Engine</h2>
|
||||
<form method="POST" action="/search" target="_blank">
|
||||
<fieldset>
|
||||
Search: <input type="search" name="query" placeholder="EWF framework"><br>
|
||||
<div>
|
||||
<input type="radio" name="engine" value="Google" checked><img src="http://ebizmba.ebizmbainc.netdna-cdn.com/images/logos/google.gif" height="24" width="42">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="radio" name="engine" value="Bing"><img src="http://ebizmba.ebizmbainc.netdna-cdn.com/images/logos/bing.gif" height="24" width="42">
|
||||
</div><br>
|
||||
</fieldset>
|
||||
<input type="submit">
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
<div id="footer">
|
||||
<p><a href="http://www.ebizmba.com/articles/search-engines">Top 15 Most Popular Search Engines | March 2015</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
|
||||
feature -- Generic Message
|
||||
|
||||
message_template: STRING="[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>$title</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<p id="name">Use a tool to see the request and header details, for example (Developers tools in Chrome or Firebugs in Firefox)</p>
|
||||
</div>
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<h4>This page is an example of $status</h4>
|
||||
|
||||
<div id="footer">
|
||||
<p><a href="/">Back Home</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
@@ -1,13 +1,11 @@
|
||||
note
|
||||
description : "Basic Service that a simple web page to show the most common status codes"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
description: "Basic Service launcher"
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_SERVICE
|
||||
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
@@ -23,127 +21,4 @@ feature {NONE} -- Initialization
|
||||
set_service_option ("port", 9090)
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute the incomming request
|
||||
local
|
||||
l_message: STRING
|
||||
do
|
||||
-- To send a response we need to setup, the status code and
|
||||
-- the response headers.
|
||||
if req.is_get_request_method then
|
||||
if req.path_info.same_string ("/") then
|
||||
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>)
|
||||
res.put_string (web_page)
|
||||
elseif req.path_info.same_string ("/redirect") then
|
||||
send_redirect (req, res, "https://httpwg.github.io/")
|
||||
elseif req.path_info.same_string ("/bad_request") then
|
||||
-- Here you can do some logic for example log, send emails to register the error, before to send the response.
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Bad Request")
|
||||
l_message.replace_substring_all ("$status", "Bad Request 400")
|
||||
res.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
res.put_string (l_message)
|
||||
elseif req.path_info.same_string ("/internal_error") then
|
||||
-- Here you can do some logic for example log, send emails to register the error, before to send the response.
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Internal Server Error")
|
||||
l_message.replace_substring_all ("$status", "Internal Server Error 500")
|
||||
res.put_header ({HTTP_STATUS_CODE}.internal_server_error, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
res.put_string (l_message)
|
||||
else
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Resource not found")
|
||||
l_message.replace_substring_all ("$status", "Resource not found 400")
|
||||
res.put_header ({HTTP_STATUS_CODE}.not_found, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
res.put_string (l_message)
|
||||
end
|
||||
else
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Method Not Allowed")
|
||||
l_message.replace_substring_all ("$status", "Method Not Allowed 405")
|
||||
-- Method not allowed
|
||||
res.put_header ({HTTP_STATUS_CODE}.method_not_allowed, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
res.put_string (l_message)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature -- Home Page
|
||||
|
||||
send_redirect (req: WSF_REQUEST; res: WSF_RESPONSE; a_location: READABLE_STRING_32)
|
||||
-- Redirect to `a_location'
|
||||
local
|
||||
h: HTTP_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_text_html
|
||||
h.put_current_date
|
||||
h.put_location (a_location)
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.see_other)
|
||||
res.put_header_text (h.string)
|
||||
end
|
||||
|
||||
web_page: STRING = "[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Example showing common status codes</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<p id="name">Use a tool to see the request and header details, for example (Developers tools in Chrome or Firebugs in Firefox)</p>
|
||||
</div>
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<h4>This page is an example of Status Code 200</h4>
|
||||
|
||||
<h4> Redirect Example </h4>
|
||||
<p> Click on the following link will redirect you to the HTTP Specifcation, we can do the redirect from the HTML directly but
|
||||
here we want to show you an exmaple, where you can do something before to send a redirect <a href="/redirect">Redirect</a></p>
|
||||
|
||||
<h4> Bad Request </h4>
|
||||
<p> Click on the following link, the server will answer with a 400 error, check the status code <a href="/bad_request">Bad Request</a></p>
|
||||
|
||||
<h4> Internal Server Error </h4>
|
||||
<p> Click on the following link, the server will answer with a 500 error, check the status code <a href="/internal_error">Internal Error</a></p>
|
||||
|
||||
<h4> Resource not found </h4>
|
||||
<p> Click on the following link or add to the end of the url something like /1030303 the server will answer with a 404 error, check the status code <a href="/not_foundd">Not found</a></p>
|
||||
|
||||
</div>
|
||||
<div id="footer">
|
||||
<p>Useful links for status codes <a href="httpstat.us">httpstat.us</a> and <a href="httpbing.org">httpbin.org</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
|
||||
feature -- Generic Message
|
||||
|
||||
message_template: STRING="[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>$title</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<p id="name">Use a tool to see the request and header details, for example (Developers tools in Chrome or Firebugs in Firefox)</p>
|
||||
</div>
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<h4>This page is an example of $status</h4>
|
||||
|
||||
<div id="footer">
|
||||
<p><a href="/">Back Home</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
138
doc/workbook/generating_response/status/application_execution.e
Normal file
138
doc/workbook/generating_response/status/application_execution.e
Normal file
@@ -0,0 +1,138 @@
|
||||
note
|
||||
description : "Basic Service that a simple web page to show the most common status codes"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
APPLICATION_EXECUTION
|
||||
|
||||
inherit
|
||||
WSF_EXECUTION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Execute the incomming request
|
||||
local
|
||||
l_message: STRING
|
||||
do
|
||||
-- To send a response we need to setup, the status code and
|
||||
-- the response headers.
|
||||
if request.is_get_request_method then
|
||||
if request.path_info.same_string ("/") then
|
||||
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>)
|
||||
response.put_string (web_page)
|
||||
elseif request.path_info.same_string ("/redirect") then
|
||||
send_redirect (request, response, "https://httpwg.github.io/")
|
||||
elseif request.path_info.same_string ("/bad_request") then
|
||||
-- Here you can do some logic for example log, send emails to register the error, before to send the response.
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Bad Request")
|
||||
l_message.replace_substring_all ("$status", "Bad Request 400")
|
||||
response.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
response.put_string (l_message)
|
||||
elseif request.path_info.same_string ("/internal_error") then
|
||||
-- Here you can do some logic for example log, send emails to register the error, before to send the response.
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Internal Server Error")
|
||||
l_message.replace_substring_all ("$status", "Internal Server Error 500")
|
||||
response.put_header ({HTTP_STATUS_CODE}.internal_server_error, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
response.put_string (l_message)
|
||||
else
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Resource not found")
|
||||
l_message.replace_substring_all ("$status", "Resource not found 400")
|
||||
response.put_header ({HTTP_STATUS_CODE}.not_found, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
response.put_string (l_message)
|
||||
end
|
||||
else
|
||||
create l_message.make_from_string (message_template)
|
||||
l_message.replace_substring_all ("$title", "Method Not Allowed")
|
||||
l_message.replace_substring_all ("$status", "Method Not Allowed 405")
|
||||
-- Method not allowed
|
||||
response.put_header ({HTTP_STATUS_CODE}.method_not_allowed, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>)
|
||||
response.put_string (l_message)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature -- Home Page
|
||||
|
||||
send_redirect (req: WSF_REQUEST; res: WSF_RESPONSE; a_location: READABLE_STRING_32)
|
||||
-- Redirect to `a_location'
|
||||
local
|
||||
h: HTTP_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_text_html
|
||||
h.put_current_date
|
||||
h.put_location (a_location)
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.see_other)
|
||||
res.put_header_text (h.string)
|
||||
end
|
||||
|
||||
web_page: STRING = "[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Example showing common status codes</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<p id="name">Use a tool to see the request and header details, for example (Developers tools in Chrome or Firebugs in Firefox)</p>
|
||||
</div>
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<h4>This page is an example of Status Code 200</h4>
|
||||
|
||||
<h4> Redirect Example </h4>
|
||||
<p> Click on the following link will redirect you to the HTTP Specifcation, we can do the redirect from the HTML directly but
|
||||
here we want to show you an exmaple, where you can do something before to send a redirect <a href="/redirect">Redirect</a></p>
|
||||
|
||||
<h4> Bad Request </h4>
|
||||
<p> Click on the following link, the server will answer with a 400 error, check the status code <a href="/bad_request">Bad Request</a></p>
|
||||
|
||||
<h4> Internal Server Error </h4>
|
||||
<p> Click on the following link, the server will answer with a 500 error, check the status code <a href="/internal_error">Internal Error</a></p>
|
||||
|
||||
<h4> Resource not found </h4>
|
||||
<p> Click on the following link or add to the end of the url something like /1030303 the server will answer with a 404 error, check the status code <a href="/not_foundd">Not found</a></p>
|
||||
|
||||
</div>
|
||||
<div id="footer">
|
||||
<p>Useful links for status codes <a href="httpstat.us">httpstat.us</a> and <a href="httpbing.org">httpbin.org</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
|
||||
feature -- Generic Message
|
||||
|
||||
message_template: STRING="[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>$title</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<p id="name">Use a tool to see the request and header details, for example (Developers tools in Chrome or Firebugs in Firefox)</p>
|
||||
</div>
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<h4>This page is an example of $status</h4>
|
||||
|
||||
<div id="footer">
|
||||
<p><a href="/">Back Home</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user