diff --git a/examples/tutorial/step_3/hello/src/hello_application.e b/examples/tutorial/step_3/hello/src/hello_application.e index 3595eb36..6220e3f7 100644 --- a/examples/tutorial/step_3/hello/src/hello_application.e +++ b/examples/tutorial/step_3/hello/src/hello_application.e @@ -22,7 +22,7 @@ inherit create make_and_launch -feature {NONE} -- Initialization +feature {NONE} -- Execution response (req: WSF_REQUEST): WSF_HTML_PAGE_RESPONSE -- Computed response message. diff --git a/examples/tutorial/step_4/hello/ewf.ini b/examples/tutorial/step_4/hello/ewf.ini new file mode 100644 index 00000000..fad6acb1 --- /dev/null +++ b/examples/tutorial/step_4/hello/ewf.ini @@ -0,0 +1,4 @@ +# For nino connector, use port 9999 +port=9999 + +#verbose=true diff --git a/examples/tutorial/step_4/hello/hello.ecf b/examples/tutorial/step_4/hello/hello.ecf new file mode 100644 index 00000000..1d54ebf1 --- /dev/null +++ b/examples/tutorial/step_4/hello/hello.ecf @@ -0,0 +1,19 @@ + + + + + + /EIFGENs$ + /CVS$ + /.svn$ + + + + + + + + + diff --git a/examples/tutorial/step_4/hello/src/hello_application.e b/examples/tutorial/step_4/hello/src/hello_application.e new file mode 100644 index 00000000..8797b897 --- /dev/null +++ b/examples/tutorial/step_4/hello/src/hello_application.e @@ -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 + "!
Click here 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 ("[ +
+

Hello, what is your name?

+ + +
+ ]" + ) + 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 + ",
see you soon.

You will be redirected to " + redir.url_location + " in " + redir.delay.out + " second(s) ...

") + 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 diff --git a/examples/upload_image/src/image_uploader.e b/examples/upload_image/src/image_uploader.e index 7b5fc905..0517c6a8 100644 --- a/examples/upload_image/src/image_uploader.e +++ b/examples/upload_image/src/image_uploader.e @@ -31,12 +31,6 @@ feature {NONE} -- Initialization make_and_launch end - create_router - -- Create router - do - create router.make (5) - end - setup_router -- Setup router local diff --git a/library/server/wsf/router/uri/default/wsf_uri_routed_service.e b/library/server/wsf/router/uri/default/wsf_uri_routed_service.e index 105421a6..f5ff1015 100644 --- a/library/server/wsf/router/uri/default/wsf_uri_routed_service.e +++ b/library/server/wsf/router/uri/default/wsf_uri_routed_service.e @@ -13,6 +13,14 @@ inherit router 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 router: WSF_URI_ROUTER diff --git a/library/server/wsf/router/uri_template/default/wsf_uri_template_routed_service.e b/library/server/wsf/router/uri_template/default/wsf_uri_template_routed_service.e index bfc06ec3..af11bf51 100644 --- a/library/server/wsf/router/uri_template/default/wsf_uri_template_routed_service.e +++ b/library/server/wsf/router/uri_template/default/wsf_uri_template_routed_service.e @@ -13,6 +13,15 @@ inherit router 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 router: WSF_URI_TEMPLATE_ROUTER diff --git a/library/server/wsf/src/response/wsf_html_delayed_redirection_response.e b/library/server/wsf/src/response/wsf_html_delayed_redirection_response.e new file mode 100644 index 00000000..231c876c --- /dev/null +++ b/library/server/wsf/src/response/wsf_html_delayed_redirection_response.e @@ -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 diff --git a/library/server/wsf/src/response/wsf_html_page_response.e b/library/server/wsf/src/response/wsf_html_page_response.e index 68edc93d..3c0b33b4 100644 --- a/library/server/wsf/src/response/wsf_html_page_response.e +++ b/library/server/wsf/src/response/wsf_html_page_response.e @@ -114,8 +114,6 @@ feature {WSF_SERVICE, WSF_RESPONSE} -- Output send_to (res: WSF_RESPONSE) local - t: like title - lines: like head_lines b: like body h: like header s: STRING_8 @@ -131,6 +129,32 @@ feature {WSF_SERVICE, WSF_RESPONSE} -- Output end s.append (">%N") + append_html_head_code (s) + append_html_body_code (s) + + + s.append ("%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 lines := head_lines if t /= Void or else lines.count > 0 then @@ -147,25 +171,18 @@ feature {WSF_SERVICE, WSF_RESPONSE} -- Output end s.append ("%N") end + end + append_html_body_code (s: STRING_8) + local + b: like body + do b := body s.append ("%N") if b /= Void then s.append (b) end - s.append ("%N%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) + s.append ("%N") end note diff --git a/library/server/wsf/src/response/wsf_html_redirection_response.e b/library/server/wsf/src/response/wsf_html_redirection_response.e new file mode 100644 index 00000000..9fe8e0e3 --- /dev/null +++ b/library/server/wsf/src/response/wsf_html_redirection_response.e @@ -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 diff --git a/library/server/wsf/src/wsf_response.e b/library/server/wsf/src/wsf_response.e index ba79c7aa..7b0fc271 100644 --- a/library/server/wsf/src/wsf_response.e +++ b/library/server/wsf/src/wsf_response.e @@ -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 to the given url `a_url' 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 feature -- Error reporting