From 9ced39239ffcdd806d2d125073e4103f4d9ae91b Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Fri, 22 Nov 2002 14:48:25 +0000 Subject: [PATCH] - catch processing exception which are now reported embedded in html responses - catch parameter exception which are now reported as bad request responses - changed default port from 48085 to 58085 - disabled http debugging --- helm/searchEngine/searchEngine.ml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/helm/searchEngine/searchEngine.ml b/helm/searchEngine/searchEngine.ml index 03c0bb389..38b92fd48 100644 --- a/helm/searchEngine/searchEngine.ml +++ b/helm/searchEngine/searchEngine.ml @@ -24,14 +24,14 @@ * http://cs.unibo.it/helm/. *) -let debug = true;; +let debug = false;; let debug_print s = if debug then prerr_endline s;; Http_common.debug := debug;; open Printf;; let daemon_name = "Search Engine";; -let default_port = 48085;; +let default_port = 58085;; let port_env_var = "SEARCH_ENGINE_PORT";; let port = @@ -48,9 +48,11 @@ let pp_result result = (sprintf "
%s
" result_string) in let pp_error = sprintf "

Error: %s

" in +let bad_request body outchan = + Http_daemon.respond_error ~status:(`Client_error `Bad_request) ~body outchan +in let callback req outchan = try - (* TODO catch exceptions *) (match req#path with | "/execute" -> let query_string = req#param "query" in @@ -60,9 +62,7 @@ let callback req outchan = let result_string = MQueryUtil.text_of_result result "\n" in Http_daemon.respond ~body: - (sprintf - "
%s
" - result_string) + (sprintf "
%s
" result_string) outchan | "/locate" -> let id = req#param "id" in @@ -78,6 +78,7 @@ let callback req outchan = (match dom with | [] -> (* no free variables *) let term = mkterm (fun _ -> None) in + prerr_endline (CicPp.ppterm term); let result = MQueryGenerator.searchPattern [] [] term precision in Http_daemon.respond ~body:(pp_result result) outchan | _ -> @@ -89,14 +90,20 @@ let callback req outchan = Http_daemon.respond_error ~status:(`Client_error `Bad_request) outchan) with | Http_request.Param_not_found attr_name -> - Http_daemon.respond_error - ~status:(`Client_error `Bad_request) - ~body:(sprintf "Parameter '%s' is missing" attr_name) - outchan + bad_request (sprintf "Parameter '%s' is missing" attr_name) outchan + | Failure "int_of_string" -> + bad_request "Invalid 'precision' value, must be an integer" outchan + | exc -> + Http_daemon.respond + ~body:(pp_error ("Uncaught exception: " ^ (Printexc.to_string exc))) + outchan in printf "%s started and listening on port %d\n" daemon_name port; printf "current directory is %s\n" (Sys.getcwd ()); flush stdout; +Mqint.set_database Mqint.postgres_db; +Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli user=helm"; Http_daemon.start' ~port callback; +Mqint.close (); printf "%s is terminating, bye!\n" daemon_name -- 2.39.2