Now inherit create_router ; but it is still possible to redefine it.
Added some wsf_reponse_message for redirection Use "found" for the redirec_now ... Added content to the tutorial
This commit is contained in:
@@ -22,7 +22,7 @@ inherit
|
|||||||
create
|
create
|
||||||
make_and_launch
|
make_and_launch
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Execution
|
||||||
|
|
||||||
response (req: WSF_REQUEST): WSF_HTML_PAGE_RESPONSE
|
response (req: WSF_REQUEST): WSF_HTML_PAGE_RESPONSE
|
||||||
-- Computed response message.
|
-- Computed response message.
|
||||||
|
|||||||
4
examples/tutorial/step_4/hello/ewf.ini
Normal file
4
examples/tutorial/step_4/hello/ewf.ini
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# For nino connector, use port 9999
|
||||||
|
port=9999
|
||||||
|
|
||||||
|
#verbose=true
|
||||||
19
examples/tutorial/step_4/hello/hello.ecf
Normal file
19
examples/tutorial/step_4/hello/hello.ecf
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="hello" uuid="5F5ED8A1-AD1C-41BD-878A-BE45A9B28739">
|
||||||
|
<target name="hello">
|
||||||
|
<root class="HELLO_APPLICATION" feature="make_and_launch"/>
|
||||||
|
<file_rule>
|
||||||
|
<exclude>/EIFGENs$</exclude>
|
||||||
|
<exclude>/CVS$</exclude>
|
||||||
|
<exclude>/.svn$</exclude>
|
||||||
|
</file_rule>
|
||||||
|
<option warning="true" is_attached_by_default="true" void_safety="all" syntax="transitional">
|
||||||
|
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||||
|
</option>
|
||||||
|
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||||
|
<library name="default_nino" location="..\..\..\..\library\server\wsf\default\nino-safe.ecf"/>
|
||||||
|
<library name="wsf" location="..\..\..\..\library\server\wsf\wsf-safe.ecf" readonly="false"/>
|
||||||
|
<library name="http" location="..\..\..\..\library\protocol\http\http-safe.ecf" readonly="false"/>
|
||||||
|
<cluster name="src" location=".\src\" recursive="true"/>
|
||||||
|
</target>
|
||||||
|
</system>
|
||||||
116
examples/tutorial/step_4/hello/src/hello_application.e
Normal file
116
examples/tutorial/step_4/hello/src/hello_application.e
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
note
|
||||||
|
description: "[
|
||||||
|
This class implements the `Hello World' service.
|
||||||
|
|
||||||
|
It inherits from WSF_DEFAULT_SERVICE to get default EWF connector ready
|
||||||
|
only `response' needs to be implemented.
|
||||||
|
In this example, it is redefined and specialized to be WSF_PAGE_RESPONSE
|
||||||
|
|
||||||
|
`initialize' can be redefine to provide custom options if needed.
|
||||||
|
|
||||||
|
]"
|
||||||
|
|
||||||
|
class
|
||||||
|
HELLO_APPLICATION
|
||||||
|
|
||||||
|
inherit
|
||||||
|
WSF_URI_TEMPLATE_ROUTED_SERVICE
|
||||||
|
|
||||||
|
WSF_DEFAULT_SERVICE
|
||||||
|
redefine
|
||||||
|
initialize
|
||||||
|
end
|
||||||
|
|
||||||
|
create
|
||||||
|
make_and_launch
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
setup_router
|
||||||
|
do
|
||||||
|
router.map_agent ("/hello", agent execute_hello)
|
||||||
|
router.map_agent_response_with_request_methods ("/{user}/bye", agent response_bye, <<"GET">>)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Execution
|
||||||
|
|
||||||
|
execute_default (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
-- Default request handler if no other are relevant
|
||||||
|
do
|
||||||
|
res.redirect_now_with_content (req.script_url ("/hello"), "Redirection to " + req.script_url ("/hello"), "text/html")
|
||||||
|
end
|
||||||
|
|
||||||
|
execute_hello (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
-- Computed response message.
|
||||||
|
local
|
||||||
|
mesg: WSF_HTML_PAGE_RESPONSE
|
||||||
|
do
|
||||||
|
--| It is now returning a WSF_HTML_PAGE_RESPONSE
|
||||||
|
--| Since it is easier for building html page
|
||||||
|
create mesg.make
|
||||||
|
mesg.set_title ("EWF tutorial / Hello World!")
|
||||||
|
--| Check if the request contains a parameter named "user"
|
||||||
|
--| this could be a query, or a form parameter
|
||||||
|
if attached req.string_item ("user") as u then
|
||||||
|
--| If yes, say hello world #name
|
||||||
|
mesg.set_body ("Hello " + u + "!<br/>Click <a href=%"/" + u + "/bye%">here</a> to quit.")
|
||||||
|
--| We should html encode this name
|
||||||
|
--| but to keep the example simple, we don't do that for now.
|
||||||
|
else
|
||||||
|
--| Otherwise, ask for name
|
||||||
|
mesg.set_body ("[
|
||||||
|
<form action="/hello" method="POST">
|
||||||
|
<p>Hello, what is your name?</p>
|
||||||
|
<input type="text" name="user"/>
|
||||||
|
<input type="submit" value="Validate"/>
|
||||||
|
</form>
|
||||||
|
]"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
--| note:
|
||||||
|
--| 1) Source of the parameter, we could have used
|
||||||
|
--| req.query_parameter ("user") to search only in the query string
|
||||||
|
--| req.form_parameter ("user") to search only in the form parameters
|
||||||
|
--| 2) response type
|
||||||
|
--| it could also have used WSF_PAGE_REPONSE, and build the html in the code
|
||||||
|
--|
|
||||||
|
|
||||||
|
res.send (mesg)
|
||||||
|
end
|
||||||
|
|
||||||
|
response_bye (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
|
||||||
|
-- Computed response message.
|
||||||
|
local
|
||||||
|
html: WSF_HTML_PAGE_RESPONSE
|
||||||
|
redir: WSF_HTML_DELAYED_REDIRECTION_RESPONSE
|
||||||
|
do
|
||||||
|
if attached ctx.string_path_parameter ("user") as u then
|
||||||
|
create redir.make (req.script_url ("/hello"), 5)
|
||||||
|
redir.set_title ("Bye " + u)
|
||||||
|
redir.set_body ("Bye " + u + ",<br/> see you soon.<p>You will be redirected to " + redir.url_location + " in " + redir.delay.out + " second(s) ...</p>")
|
||||||
|
Result := redir
|
||||||
|
else
|
||||||
|
create html.make
|
||||||
|
html.set_title ("Bad request")
|
||||||
|
html.set_body ("Bad request: missing user parameter")
|
||||||
|
Result := html
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
initialize
|
||||||
|
do
|
||||||
|
--| The following line is to be able to load options from the file ewf.ini
|
||||||
|
create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI} service_options.make_from_file ("ewf.ini")
|
||||||
|
|
||||||
|
--| If you don't need any custom options, you are not obliged to redefine `initialize'
|
||||||
|
Precursor
|
||||||
|
|
||||||
|
--| Initialize router
|
||||||
|
initialize_router
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
@@ -31,12 +31,6 @@ feature {NONE} -- Initialization
|
|||||||
make_and_launch
|
make_and_launch
|
||||||
end
|
end
|
||||||
|
|
||||||
create_router
|
|
||||||
-- Create router
|
|
||||||
do
|
|
||||||
create router.make (5)
|
|
||||||
end
|
|
||||||
|
|
||||||
setup_router
|
setup_router
|
||||||
-- Setup router
|
-- Setup router
|
||||||
local
|
local
|
||||||
|
|||||||
@@ -13,6 +13,14 @@ inherit
|
|||||||
router
|
router
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
create_router
|
||||||
|
-- Create router
|
||||||
|
--| it can be redefine to create with precise count if needed.
|
||||||
|
do
|
||||||
|
create router.make (0)
|
||||||
|
end
|
||||||
feature -- Router
|
feature -- Router
|
||||||
|
|
||||||
router: WSF_URI_ROUTER
|
router: WSF_URI_ROUTER
|
||||||
|
|||||||
@@ -13,6 +13,15 @@ inherit
|
|||||||
router
|
router
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
create_router
|
||||||
|
-- Create router
|
||||||
|
--| it can be redefine to create with precise count if needed.
|
||||||
|
do
|
||||||
|
create router.make (0)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Router
|
feature -- Router
|
||||||
|
|
||||||
router: WSF_URI_TEMPLATE_ROUTER
|
router: WSF_URI_TEMPLATE_ROUTER
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
note
|
||||||
|
description: "[
|
||||||
|
Delayed redirection with HTML content using META tag
|
||||||
|
]"
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
WSF_HTML_DELAYED_REDIRECTION_RESPONSE
|
||||||
|
|
||||||
|
inherit
|
||||||
|
WSF_HTML_PAGE_RESPONSE
|
||||||
|
rename
|
||||||
|
make as make_html
|
||||||
|
redefine
|
||||||
|
append_html_head_code
|
||||||
|
end
|
||||||
|
|
||||||
|
create
|
||||||
|
make
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
make (a_url_location: like url_location; a_delay_in_seconds: INTEGER)
|
||||||
|
do
|
||||||
|
url_location := a_url_location
|
||||||
|
delay := a_delay_in_seconds
|
||||||
|
make_html
|
||||||
|
set_status_code ({HTTP_STATUS_CODE}.found)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Header
|
||||||
|
|
||||||
|
url_location: STRING_8
|
||||||
|
-- New url location after redirection
|
||||||
|
|
||||||
|
delay: INTEGER
|
||||||
|
|
||||||
|
feature -- Element change
|
||||||
|
|
||||||
|
set_url_location (a_url_location: like url_location)
|
||||||
|
-- Set `url_location' to `a_url_location'
|
||||||
|
do
|
||||||
|
url_location := a_url_location
|
||||||
|
end
|
||||||
|
|
||||||
|
set_delay (a_seconds: INTEGER)
|
||||||
|
do
|
||||||
|
delay := a_seconds
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Output
|
||||||
|
|
||||||
|
append_html_head_code (s: STRING_8)
|
||||||
|
local
|
||||||
|
h_lines: like head_lines
|
||||||
|
l_lines: like head_lines
|
||||||
|
do
|
||||||
|
h_lines := head_lines
|
||||||
|
l_lines := head_lines.twin
|
||||||
|
head_lines := l_lines
|
||||||
|
add_meta_http_equiv ("refresh", delay.out + ";url=" + url_location)
|
||||||
|
Precursor (s)
|
||||||
|
head_lines := h_lines
|
||||||
|
end
|
||||||
|
|
||||||
|
note
|
||||||
|
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
|
source: "[
|
||||||
|
Eiffel Software
|
||||||
|
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||||
|
Telephone 805-685-1006, Fax 805-685-6869
|
||||||
|
Website http://www.eiffel.com
|
||||||
|
Customer support http://support.eiffel.com
|
||||||
|
]"
|
||||||
|
end
|
||||||
@@ -114,8 +114,6 @@ feature {WSF_SERVICE, WSF_RESPONSE} -- Output
|
|||||||
|
|
||||||
send_to (res: WSF_RESPONSE)
|
send_to (res: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
t: like title
|
|
||||||
lines: like head_lines
|
|
||||||
b: like body
|
b: like body
|
||||||
h: like header
|
h: like header
|
||||||
s: STRING_8
|
s: STRING_8
|
||||||
@@ -131,6 +129,32 @@ feature {WSF_SERVICE, WSF_RESPONSE} -- Output
|
|||||||
end
|
end
|
||||||
s.append (">%N")
|
s.append (">%N")
|
||||||
|
|
||||||
|
append_html_head_code (s)
|
||||||
|
append_html_body_code (s)
|
||||||
|
|
||||||
|
|
||||||
|
s.append ("</html>%N")
|
||||||
|
|
||||||
|
h := header
|
||||||
|
res.set_status_code (status_code)
|
||||||
|
|
||||||
|
if not h.has_content_length then
|
||||||
|
h.put_content_length (s.count)
|
||||||
|
end
|
||||||
|
if not h.has_content_type then
|
||||||
|
h.put_content_type_text_html
|
||||||
|
end
|
||||||
|
res.put_header_text (h.string)
|
||||||
|
res.put_string (s)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- HTML Generation
|
||||||
|
|
||||||
|
append_html_head_code (s: STRING_8)
|
||||||
|
local
|
||||||
|
t: like title
|
||||||
|
lines: like head_lines
|
||||||
|
do
|
||||||
t := title
|
t := title
|
||||||
lines := head_lines
|
lines := head_lines
|
||||||
if t /= Void or else lines.count > 0 then
|
if t /= Void or else lines.count > 0 then
|
||||||
@@ -147,25 +171,18 @@ feature {WSF_SERVICE, WSF_RESPONSE} -- Output
|
|||||||
end
|
end
|
||||||
s.append ("</head>%N")
|
s.append ("</head>%N")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
append_html_body_code (s: STRING_8)
|
||||||
|
local
|
||||||
|
b: like body
|
||||||
|
do
|
||||||
b := body
|
b := body
|
||||||
s.append ("<body>%N")
|
s.append ("<body>%N")
|
||||||
if b /= Void then
|
if b /= Void then
|
||||||
s.append (b)
|
s.append (b)
|
||||||
end
|
end
|
||||||
s.append ("%N</body></html>%N")
|
s.append ("%N</body>")
|
||||||
|
|
||||||
h := header
|
|
||||||
res.set_status_code (status_code)
|
|
||||||
|
|
||||||
if not h.has_content_length then
|
|
||||||
h.put_content_length (s.count)
|
|
||||||
end
|
|
||||||
if not h.has_content_type then
|
|
||||||
h.put_content_type_text_html
|
|
||||||
end
|
|
||||||
res.put_header_text (h.string)
|
|
||||||
res.put_string (s)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
note
|
||||||
|
description: "[
|
||||||
|
Immediate redirection with HTML content
|
||||||
|
]"
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
WSF_HTML_REDIRECTION_RESPONSE
|
||||||
|
|
||||||
|
inherit
|
||||||
|
WSF_HTML_PAGE_RESPONSE
|
||||||
|
rename
|
||||||
|
make as make_html
|
||||||
|
redefine
|
||||||
|
send_to
|
||||||
|
end
|
||||||
|
|
||||||
|
create
|
||||||
|
make
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
make (a_url_location: like url_location)
|
||||||
|
do
|
||||||
|
url_location := a_url_location
|
||||||
|
make_html
|
||||||
|
set_status_code ({HTTP_STATUS_CODE}.found)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Header
|
||||||
|
|
||||||
|
url_location: STRING_8
|
||||||
|
-- New url location after redirection
|
||||||
|
|
||||||
|
feature -- Element change
|
||||||
|
|
||||||
|
set_url_location (a_url_location: like url_location)
|
||||||
|
-- Set `url_location' to `a_url_location'
|
||||||
|
do
|
||||||
|
url_location := a_url_location
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {WSF_SERVICE, WSF_RESPONSE} -- Output
|
||||||
|
|
||||||
|
send_to (res: WSF_RESPONSE)
|
||||||
|
local
|
||||||
|
h,rh: like header
|
||||||
|
do
|
||||||
|
h := header
|
||||||
|
create rh.make_with_count (1)
|
||||||
|
|
||||||
|
rh.put_location (url_location)
|
||||||
|
rh.append_header_object (h)
|
||||||
|
|
||||||
|
header := rh
|
||||||
|
Precursor (res)
|
||||||
|
header := h
|
||||||
|
end
|
||||||
|
|
||||||
|
note
|
||||||
|
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
|
source: "[
|
||||||
|
Eiffel Software
|
||||||
|
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||||
|
Telephone 805-685-1006, Fax 805-685-6869
|
||||||
|
Website http://www.eiffel.com
|
||||||
|
Customer support http://support.eiffel.com
|
||||||
|
]"
|
||||||
|
end
|
||||||
@@ -329,7 +329,7 @@ feature -- Redirect
|
|||||||
redirect_now_with_content (a_url: READABLE_STRING_8; a_content: READABLE_STRING_8; a_content_type: READABLE_STRING_8)
|
redirect_now_with_content (a_url: READABLE_STRING_8; a_content: READABLE_STRING_8; a_content_type: READABLE_STRING_8)
|
||||||
-- Redirect to the given url `a_url'
|
-- Redirect to the given url `a_url'
|
||||||
do
|
do
|
||||||
redirect_now_custom (a_url, {HTTP_STATUS_CODE}.temp_redirect, Void, [a_content, a_content_type])
|
redirect_now_custom (a_url, {HTTP_STATUS_CODE}.found, Void, [a_content, a_content_type])
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Error reporting
|
feature -- Error reporting
|
||||||
|
|||||||
Reference in New Issue
Block a user