note description : "Objects that ..." author : "$Author$" date : "$Date$" revision : "$Revision$" class HELLO_ROUTED_WORLD inherit URI_TEMPLATE_ROUTED_SERVICE ROUTED_SERVICE_HELPER create make feature {NONE} -- Initialization make local s: DEFAULT_SERVICE_LAUNCHER do initialize_router create s.make_and_launch_with_options (agent execute, <<["port", 8099]>>) end create_router do create router.make (5) end setup_router local ra: REQUEST_AGENT_HANDLER [REQUEST_URI_TEMPLATE_HANDLER_CONTEXT] hello: REQUEST_URI_TEMPLATE_ROUTING_HANDLER www: REQUEST_FILE_SYSTEM_HANDLER [REQUEST_URI_TEMPLATE_HANDLER_CONTEXT] do router.map_agent ("/refresh", agent execute_refresh) router.map_agent ("/home", agent execute_home) create www.make (document_root) www.set_directory_index (<<"index.html">>) router.map ("/www{/path}{?query}", www) --| Map all "/hello*" using a ROUTING_HANDLER create hello.make (3) router.map ("/hello", hello) create ra.make (agent handle_hello) hello.map ("/hello/{name}.{format}", ra) hello.map ("/hello.{format}/{name}", ra) hello.map ("/hello/{name}", ra) create ra.make (agent handle_anonymous_hello) hello.map ("/hello", ra) hello.map ("/hello.{format}", ra) --| Various various route, directly on the "router" router.map_agent_with_request_methods ("/method/any", agent handle_method_any, Void) router.map_agent_with_request_methods ("/method/guess", agent handle_method_get_or_post, <<"GET", "POST">>) router.map_agent_with_request_methods ("/method/custom", agent handle_method_get, <<"GET">>) router.map_agent_with_request_methods ("/method/custom", agent handle_method_post, <<"POST">>) end document_root: READABLE_STRING_8 local e: EXECUTION_ENVIRONMENT dn: DIRECTORY_NAME once create e create dn.make_from_string (e.current_working_directory) dn.extend ("htdocs") Result := dn.string if Result[Result.count] = Operating_environment.directory_separator then Result := Result.substring (1, Result.count - 1) end end feature -- Execution execute_default (req: WSF_REQUEST; res: WSF_RESPONSE) local l_url: STRING do l_url := req.absolute_script_url ("/home") res.redirect_now_with_content (l_url, "You are now being redirected to " + l_url, {HTTP_MIME_TYPES}.text_html) end execute_refresh (ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE) local h: HTTP_HEADER l_url: STRING e: EXECUTION_ENVIRONMENT n: INTEGER i: INTEGER s: STRING_8 do l_url := req.absolute_script_url ("/home") n := 3 create h.make h.put_refresh (l_url, 5) h.put_location (l_url) h.put_content_type_text_plain h.put_transfer_encoding_chunked -- h.put_content_length (0) -- res.set_status_code ({HTTP_STATUS_CODE}.moved_permanently) res.set_status_code ({HTTP_STATUS_CODE}.ok) res.write_header_text (h.string) from create e create s.make (255) until n = 0 loop if n > 1 then s.append ("%NRedirected to " + l_url + " in " + n.out + " seconds :%N") else s.append ("%NRedirected to " + l_url + " in 1 second :%N") end res.write_chunk (s); s.wipe_out from i := 1 until i = 1001 loop s.append_character ('.') if i \\ 100 = 0 then s.append_character ('%N') end res.write_chunk (s); s.wipe_out e.sleep (1_000_000) i := i + 1 end n := n - 1 end s.append ("%NYou are now being redirected...%N") res.write_chunk (s); s.wipe_out res.write_chunk (Void) end execute_home (ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE) local l_body: STRING_8 do create l_body.make (255) l_body.append ("
Hello World ?!%N") l_body.append ("