Changeset 17
- Timestamp:
- 03/17/09 10:49:55 (16 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/isidorus.asd ¶
r15 r17 122 122 (:static-file "json_interface.html")) 123 123 :depends-on ("model" "xml")) 124 (:module "threading" 125 :components ((:file "reader-writer")))) 124 ) 125 ;;(:module "threading" 126 ;; :components ((:file "reader-writer")))) 126 127 :depends-on (:cxml 127 128 :drakma -
TabularUnified trunk/src/json/json_interface.html ¶
r15 r17 1 <html> 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 2 3 <head> 3 <title>isidorus</title> 4 <script type="text/javascript"> 5 // --- here we can handle timeouts of the passed XMLHttpRequest-objects 6 // --- this function has to be set and cleared in every XMLHttpRequest-object 7 function ajaxTimeout(xhr){ 8 xhr.abort(); 9 alert("The AJAX request timed out. Did you lose network connectivity for some reason?"); 10 } 4 <title>isidorus with protype and scriptaclous</title> 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 6 <link rel="stylesheet" type="text/css" href="main.css"/> 11 7 12 // --- the timeout interval in seconds 8 <!-- includes the prototype framework --> 9 <script language="JavaScript" type="text/javascript" src="prototype-1.6.0.3.js"></script> 10 11 <!-- own javascript code --> 12 <script language="JavaScript" type="text/javascript"> 13 // --- some constants ----------------------------------------------------- 13 14 const TIMEOUT = 5000; 14 // --- the XMLHttpRequest base url 15 const BASE_URL = "http://localhost:8000/json/psi/"; 15 const GET_PREFIX = "http://localhost:8000/json/get/"; 16 const COMMIT_URL = "http://localhost:8000/json/commit/"; 17 const ALL_PSIS_URL = "http://localhost:8000/json/psis/"; 16 18 const OWN_URL = "http://localhost:8000/isidorus"; 17 19 20 // --- some globals ------------------------------------------------------- 21 var ALL_PSIS = null; 22 var CURRENT_URL = null; 23 var CURRENT_FRAGMENT = null; 18 24 19 function back() 25 26 // --- default error handler for all ajax objects 27 function errorHandler(ajaxReq) 20 28 { 21 window.location.href = OWN_URL;29 alert("Something went wrong ... -> " + ajaxReq.status); 22 30 } 23 31 24 32 25 // --- creates a XMLHttpReques object26 function connect()33 // --- redirects the client to the initial url 34 function goBack() 27 35 { 28 try { return new XMLHttpRequest(); } catch(err){} 29 try { return new AcitveXObject("Msxml2.XMLHTTP"); } catch(err){} 30 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(err){} 31 32 alert("error creating request object"); 33 return null; 36 window.location = OWN_URL; 37 $("textArea").value = ""; 34 38 } 35 39 36 40 37 // ======================================================================== 38 // --- get request -> aks for json-data 39 // ======================================================================== 40 var xhrGet = null; 41 // --- ajax functions ----------------------------------------------------- 42 function commitPut() 43 { 44 function commitPutHandler(ajaxReq) 45 { 46 alert(CURRENT_URL + "\n\n" + $("textArea").value + "\n\n" + ajaxReq.status); 47 } 41 48 42 // --- creates a XMLHttpReques object43 function connectGet()44 {45 // --- firefox46 try{ return new XMLHttpRequest(); } catch(err){}47 49 48 // --- internet explorer 49 try{ return new ActiveXObject("Msxml2.XMLHTTP"); } catch(err){} 50 try{ return new ActiveXObject("Microsoft.XMLHTTP"); } catch(err){} 51 52 alert("error creating request object"); 53 return null; 50 new Ajax.Request(COMMIT_URL, 51 { 52 method: "post", 53 requestHeaders:{ "Content-Type":"application/json"}, 54 onSuccess: commitPutHandler, 55 onFailure: errorHandler, 56 postBody: $("textArea").value 57 }); 54 58 } 55 59 56 60 57 // --- h andles the json response58 function handleJson()61 // --- hides the table with all psis and sends a request to the server for a specific topic-psi 62 function selectTopic(topicIdx, psiIdx) 59 63 { 60 if(xhrGet.readyState == 4){ // state 4 --> response is complete 61 if(xhrGet.status != 200){ 62 alert("error: " + xhrGet.status); 63 return false; 64 if(ALL_PSIS != null && ALL_PSIS.length != 0){ 65 // --- handler for the ajax request aobject - if the request was successful 66 function getFragment(ajaxReq) 67 { 68 var response = ajaxReq.responseText; 69 try{ 70 var jsonObj = CURRENT_FRAGMENT = response.evalJSON(); 71 $("textArea").value = response; 72 }catch(err){ 73 alert("got bad JSON data: " + err); 74 } 64 75 } 65 76 66 // --- resets the timeout 67 clearTimeout(xhrGet.timeout); 68 69 // --- handle the data 70 var json = eval("(" + xhrGet.responseText + ")"); 71 var psis = json.topic.subjectIdentifiers; 72 document.getElementById("psis").innerHTML = ""; 73 for each(var psi in psis) 74 document.getElementById("psis").innerHTML += "psi: " + psi + '<br/>'; 75 76 document.getElementById("real_text").value = xhrGet.responseText; 77 //alert("header: " + xhrGet.getAllResponseHeaders()); 78 } 79 else{ 80 return false; 77 var url = CURRENT_URL = GET_PREFIX + ALL_PSIS[topicIdx][psiIdx].gsub("#", "%23"); 78 $("allPsisTable").remove(); 79 $("allPsisButton").insert({after: '<input id="commitPutButton" style="margin-top:10px; margin-bottom:10px;" type="button" onclick="commitPut()" value="commit fragment"/>'}); 80 // --- ajax request 81 new Ajax.Request(url, 82 { 83 method:'get', 84 onSuccess: getFragment, 85 onFailure: errorHandler 86 }); 81 87 } 82 88 } 83 89 84 90 85 // --- sends a request for the json data86 function get Data(xhr)91 // --- gets all topic psis are currently contained in isidorus 92 function getAllPsis() 87 93 { 88 var topic_psi = document.getElementById("topic_psi").value; 89 var url = BASE_URL + topic_psi; 94 // --- handler for the ajax request aobject - if the request was successful 95 function getAllPsisSuccessHandler(ajaxReq) 96 { 97 var btn= $("commitPutButton"); 98 if(btn)btn.remove(); 90 99 91 // --- sets the timeout for this XMLHttpRequest object; 5 seconds 92 xhrGet.timeout = setTimeout("ajaxTimeout(xhrGet);", TIMEOUT); 100 var response = ajaxReq.responseText; 101 try{ 102 var jsonObj = ALL_PSIS = response.evalJSON(); 103 var htmlStr = '<table id="allPsisTable"><tr><th>topic #</th><th>psis</th></tr>'; 104 105 jsonObj.each(function(topic, idx) 106 { 107 htmlStr += '<tr><td rowspan="' + topic.length + '">' + idx + '</td>'; 108 topic.each(function(psi, innerIdx) 109 { 110 if(innerIdx != 0)htmlStr += "<tr>"; 111 htmlStr += '<td><input id="psiRow" type="radio" name="psi" onclick="selectTopic(' + idx + ',' + innerIdx +')">' + psi + '</input></td>'; 112 htmlStr += "</tr>"; 113 }); 114 if(topic.length != 1)htmlStr += "</tr>"; 115 }); 116 htmlStr += "</table>"; 117 $("allPsisButton").insert({after: htmlStr}); 118 }catch(err){ 119 alert("got bad JSON data: " + err); 120 } 121 } 93 122 94 try{95 xhrGet.open("GET", url, true); // true --> asynchronous call, so the user is able to continue working on other things96 }catch(err) {alert("err: " + err); }97 98 // --- registers a callback handler for the readystatechange event of the XMLHttpRequest/ActiveXObject-Object99 xhrGet.onreadystatechange = handleJson;100 xhrGet.send(null);123 // --- ajax request 124 new Ajax.Request(ALL_PSIS_URL, 125 { 126 method:'get', 127 onSuccess: getAllPsisSuccessHandler, 128 onFailure: errorHandler 129 }); 101 130 } 102 103 104 // --- calls all necessary functions to get a fragment belonging to the105 // --- psi of the topic_psi text field106 function doIt()107 {108 xhrGet = connectGet();109 110 if(xhrGet != null)111 getData(xhrGet);112 }113 114 // ========================================================================115 // --- put request -> commit json-data116 // ========================================================================117 var xhrPut = null;118 119 // --- commits the textarea's json data to the server120 function commitJson()121 {122 xhrPut = connect();123 124 if(xhrPut != null)125 sendData(xhrPut);126 }127 128 129 // --- handles the committing of json data130 function handleCommit()131 {132 alert("readyState: " + xhrPut.readyState + "\nstatus: " + xhrPut.status + "\nresponsetext: " + xhrPut.responseText);133 if(xhrPut.readyState == 4){ // state 4 --> response is complete134 //if(xhrPut.status == 200){135 // alert("error: " + xhrPut.status);136 // return false;137 //}138 139 // --- resets the timeout140 clearTimeout(xhrPut.timeout);141 alert("data commited successfully");142 //doIt();143 }144 else{145 return false;146 }147 }148 149 150 // --- sends the json data to the server151 function sendData(xhr)152 {153 var json = document.getElementById("real_text").value;154 var topicPsi = document.getElementById("topic_psi").value;155 var url = BASE_URL + topicPsi;156 xhrPut.open("PUT", url, true);157 158 // --- sets the timeout for this XMLHttpRequest object; 5 seconds159 xhrPut.timeout = setTimeout("ajaxTimeout(xhrPut);", TIMEOUT);160 161 // --- registers a callback handler for the readystatechange event of the XMLHttpRequest/ActiveXObject-Object162 xhrPut.onreadystatechange = handleCommit;163 xhrPut.setRequestHeader("Content-type", "application/json");164 xhrPut.send(json);165 }166 167 168 // ========================================================================169 // --- post request -> commit json-data170 // ========================================================================171 var xhrPost = null;172 173 174 function commitJsonPost()175 {176 xhrPost = connect();177 178 if(xhrPost != null)179 sendDataPost(xhrPost);180 }181 182 183 function handlePostCommit()184 {185 alert("readyState: " + xhrPost.readyState + "\nstatus: " + xhrPost.status + "\nresponsetext: " + xhrPost.responseText);186 if(xhrPost.readyState == 4){ // state 4 --> response is complete187 //if(xhrPut.status == 200){188 // alert("error: " + xhrPut.status);189 // return false;190 //}191 192 // --- resets the timeout193 clearTimeout(xhrPost.timeout);194 alert("data commited successfully");195 //doIt();196 }197 else{198 return false;199 }200 }201 202 203 function sendDataPost(xhr)204 {205 var json = document.getElementById("real_text").value;206 var topicPsi = document.getElementById("topic_psi").value;207 var url = BASE_URL + topicPsi;208 xhrPost.open("POST", url, true);209 210 // --- sets the timeout for this XMLHttpRequest object; 5 seconds211 xhrPost.timeout = setTimeout("ajaxTimeout(xhrPost);", TIMEOUT);212 213 // --- registers a callback handler for the readystatechange event of the XMLHttpRequest/ActiveXObject-Object214 xhrPost.onreadystatechange = handlePostCommit;215 }216 217 218 131 </script> 219 132 </head> 133 220 134 <body> 221 <div id="content" style="width: 80%; height: 80%; border: dashed 1px;"> 222 <input id="topic_psi" type="text" value="http://psi.egovpt.org/types/topicInTaxonomy" name="topic_psi" style="margin-left:10px; margin-top:10px;"/> 223 <input type="button" onclick="doIt();" value="get json" style="margin-top:10px;"/> 224 <div id="psis" style="background-color: silver; width: 70%; margin: 10px;"></div> 225 <textarea id ="real_text" name="text" cols="120" rows="10" style="margin: 10px;"></textarea><br/> 226 <input type="button" onclick="commitJson()" value="commit json via PUT" style="margin-left: 10px;"/> 227 <input type="button" onclick="commitJsonPost()" value="commit json via POST" style="margin-left: 10px; margin-right: 10px;"/> 228 <input type="button" onclick="back()" value="back"/> 135 <div id="content" style="margin-top:20px; margin-left:auto; margin-right:auto; border:dashed; width:60%;"> 136 <input id="allPsisButton" style="margin:10px;" type="button" onclick="getAllPsis()" value="get all psis"/><br/> 137 <textarea id="textArea" style="margin-left:10px; margin-bottom:10px;" cols="100" rows="10"></textarea><br/> 138 <input id="backButton" style="margin-left:10px; margin-bottom:10px;" type="button" onclick="goBack()" value="clear"/><br/> 229 139 </div> 230 140 </body> -
TabularUnified trunk/src/rest_interface/publish_feeds.lisp ¶
r2 r17 5 5 6 6 (defmacro as-feed (feed) 7 `(setf ( content-type) "application/atom+xml; charset=UTF-8")7 `(setf (hunchentoot:content-type*) "application/atom+xml; charset=UTF-8") 8 8 `(cxml:with-xml-output (cxml:make-string-sink :canonical t) 9 9 (atom:feed-to-elem ,feed))) … … 11 11 (defun overview-feed () 12 12 "Interface function to the corresponding Atom method" 13 (setf ( content-type) "application/atom+xml; charset=UTF-8")13 (setf (hunchentoot:content-type*) "application/atom+xml; charset=UTF-8") 14 14 (as-feed atom:*tm-feed*)) 15 15 … … 17 17 (defmethod publish-feed ((feed atom:feed)) 18 18 (push 19 (create-regex-dispatcher 19 (create-regex-dispatcher 20 20 (format nil "~a~a" (path feed) "/?$") #'overview-feed) 21 21 hunchentoot:*dispatch-table*) … … 27 27 (format nil "~a~a" (path feed) "/?$") 28 28 (lambda () 29 (setf (content-type) "application/atom+xml; charset=UTF-8")29 (setf (hunchentoot:content-type*) "application/atom+xml; charset=UTF-8") 30 30 (as-feed feed))) 31 31 hunchentoot:*dispatch-table*) … … 37 37 (format nil "~a~a" (path feed) "/?$") 38 38 (lambda () 39 (setf (content-type) "application/atom+xml; charset=UTF-8")39 (setf (hunchentoot:content-type*) "application/atom+xml; charset=UTF-8") 40 40 (as-feed feed))) 41 41 hunchentoot:*dispatch-table*) … … 45 45 (format nil "~a~a" (path feed) "/([0-9]+)$") 46 46 (lambda (&optional unique-id) 47 (setf ( content-type) "application/x-tm+xml;version=1.0; charset=utf-8")47 (setf (hunchentoot:content-type*) "application/x-tm+xml;version=1.0; charset=utf-8") 48 48 (let 49 49 ((fragment … … 59 59 (format nil "~a~a" (path feed) "/?$") 60 60 (lambda () 61 (setf (content-type) "application/atom+xml; charset=UTF-8")61 (setf (hunchentoot:content-type*) "application/atom+xml; charset=UTF-8") 62 62 (as-feed feed))) 63 63 hunchentoot:*dispatch-table*) … … 67 67 (format nil "~a~a" (path feed) "/([0-9]+)$") 68 68 (lambda (&optional revision) 69 (setf ( content-type) "application/x-tm+xml;version=1.0; charset=utf-8")69 (setf (hunchentoot:content-type*) "application/x-tm+xml;version=1.0; charset=utf-8") 70 70 (exporter:export-xtm-to-string 71 71 :revision (parse-integer revision) -
TabularUnified trunk/src/rest_interface/rest-interface.lisp ¶
r15 r17 17 17 :start-tm-engine 18 18 :shutdown-tm-engine 19 :*json-rest-prefix* 19 :*json-get-prefix* 20 :*json-commit-url* 21 :*json-get-all-psis* 20 22 :*json-user-interface-url* 21 23 :*json-user-interface-file-path*)) … … 71 73 72 74 73 ;;(defun make-json (&optional uri)74 ;; "returns a json-string of the topic with the passed psi-uri"75 ;; (assert uri)76 ;; ;decodes the url-encoding "%23" to "#" character (only the first which will be found)77 ;; (let ((identifier (let ((pos (search "%23" uri)))78 ;; (if pos79 ;; (let ((str-1 (subseq uri 0 pos))80 ;; (str-2 (if (> (length uri) (+ pos 3))81 ;; (subseq uri (+ pos 3))82 ;; "")))83 ;; (concatenate 'string str-1 "#" str-2))84 ;; uri)))85 ;; (http-method (request-method))86 ;; (external-format (flexi-streams:make-external-format :UTF-8 :eol-style :LF))) ;;is needed to get a string of the put-request87 ;; (if (eq http-method :GET)88 ;; (progn89 ;; (setf (hunchentoot:content-type) "application/json")90 ;; (let ((fragment91 ;; (get-latest-fragment-of-topic identifier)))92 ;; (if fragment93 ;; (handler-case (to-json-string fragment)94 ;; (condition (err) (format nil "{\"fault\":\"~a\"}" err)))95 ;; "{}")))96 ;; (if (eq http-method :PUT)97 ;; (let ((put-data (raw-post-data :external-format external-format :force-text t)))98 ;; (handler-case (json-importer:json-to-elem put-data)99 ;; (condition () (setf (return-code) +http-internal-server-error+))))100 ;; (setf (return-code) +http-internal-server-error+))))) ; for all htt-methods except for get and post101 102 103 75 ;; (push 104 76 ;; (create-regex-dispatcher "/feeds/?$" #'feeds) … … 125 97 ;; hunchentoot:*dispatch-table*) 126 98 127 ;;(push128 ;; (create-regex-dispatcher "/json/psi/(.+)$" #'make-json)129 ;; hunchentoot:*dispatch-table*)130 131 99 132 (defvar *server*) 100 101 (defvar *acceptor*) 133 102 134 103 (defun start-tm-engine (repository-path &key (conffile "atom/conf.lisp") (host-name "localhost") (port 8000)) 135 104 "Start the Topic Map Engine on a given port, assuming a given 136 105 hostname. Use the repository under repository-path" 137 (setf hunchentoot:*show-lisp-errors-p* t) ;for now 138 (setf hunchentoot:*show-lisp-backtraces-p* t)106 (setf hunchentoot:*show-lisp-errors-p* t) ;for now 107 ;(setf hunchentoot:*show-lisp-backtraces-p* t) ;hunchentoot 0.15.7 139 108 (setf hunchentoot:*hunchentoot-default-external-format* 140 109 (flex:make-external-format :utf-8 :eol-style :lf)) … … 145 114 (publish-feed atom:*tm-feed*) 146 115 (set-up-json-interface) 147 (setf *server* (hunchentoot:start-server :address host-name :port port))) 116 (setf *acceptor* (make-instance 'hunchentoot:acceptor :address host-name :port port)) 117 (setf hunchentoot:*lisp-errors-log-level* :info) 118 (setf hunchentoot:*message-log-pathname* "./hunchentoot-errors.log") 119 (hunchentoot:start *acceptor*)) 148 120 149 121 (defun shutdown-tm-engine () 150 122 "Shut down the Topic Map Engine" 151 (hunchentoot:stop -server *server*)123 (hunchentoot:stop *acceptor*) 152 124 (elephant:close-store)) -
TabularUnified trunk/src/rest_interface/set-up-json-interface.lisp ¶
r16 r17 1 1 (in-package :rest-interface) 2 2 3 (defparameter *json-rest-prefix* "/json/psi") ;the prefix to get a fragment by the psis -> localhost:8000/json/psi/<fragment-psi> 4 (defparameter *json-rest-all-psis* "/json/psis") ;the url to get all topic psis of isidorus -> localhost:8000/json/psis 5 (defparameter *json-user-interface-url* "/isidorus") ;the url to the user interface -> localhost:8000/isidorus 3 (defparameter *json-get-prefix* "/json/get/(.+)$") ;the prefix to get a fragment by the psis -> localhost:8000/json/get/<fragment-psi> 4 (defparameter *json-commit-url* "/json/commit/?$") ;the url to commit a json fragment by "put" or "post" 5 (defparameter *json-get-all-psis* "/json/psis/?$") ;the url to get all topic psis of isidorus -> localhost:8000/json/psis 6 (defparameter *json-user-interface-url* "/isidorus/?$") ;the url to the user interface -> localhost:8000/isidorus 6 7 (defparameter *json-user-interface-file-path* "json/json_interface.html") ;the file path to the HTML file implements the user interface 7 8 8 9 9 (defun set-up-json-interface (&key (rest-prefix *json-rest-prefix*) (rest-all-psis *json-rest-all-psis*) 10 (ui-url *json-user-interface-url*) (ui-file-path *json-user-interface-file-path*)) 10 (defun set-up-json-interface (&key (json-get-prefix *json-get-prefix*) (json-get-all-psis *json-get-all-psis*) 11 (json-commit-url *json-commit-url*) (json-user-interface-url *json-user-interface-url*) 12 (json-user-interface-file-path *json-user-interface-file-path*)) 11 13 "registers the json im/exporter to the passed base-url in hunchentoot's dispatch-table 12 14 and also registers a file-hanlder to the html-user-interface" 13 (declare (string rest-prefix ui-url ui-file-path)) 14 (let ((rest-regex (concatenate 'string rest-prefix "/(.+)$")) 15 (ui-regex (concatenate 'string ui-url "/?$")) 16 (all-psis-regex (concatenate 'string rest-all-psis "/?$"))) 17 ;(format t "rest-interface: ~a~%user-interface: ~a~%user-interface-file-path: ~a~%" rest-regex ui-regex ui-file-path) 18 (push 19 (create-regex-dispatcher ui-regex #'(lambda() 20 (hunchentoot:handle-static-file ui-file-path))) 21 hunchentoot:*dispatch-table*) 22 (push 23 (create-regex-dispatcher all-psis-regex #'(lambda() 24 (setf (hunchentoot:content-type) "application/json") ;RFC 4627 25 (get-all-topic-psis))) 26 hunchentoot:*dispatch-table*) 27 (push 28 (create-regex-dispatcher rest-regex 29 #'(lambda (&optional uri) 30 (assert uri) 31 ;decodes the url-encoding "%23" to "#" character (only the first which will be found) 32 (let ((identifier (let ((pos (search "%23" uri))) 33 (if pos 34 (let ((str-1 (subseq uri 0 pos)) 35 (str-2 (if (> (length uri) (+ pos 3)) 36 (subseq uri (+ pos 3)) 37 ""))) 38 (concatenate 'string str-1 "#" str-2)) 39 uri))) 40 (http-method (request-method)) 41 (external-format (flexi-streams:make-external-format :UTF-8 :eol-style :LF))) ;is needed to get a string of the put-request 42 (cond 43 ((eq http-method :GET) 44 (progn 45 (setf (hunchentoot:content-type) "application/json") ;RFC 4627 46 (let ((fragment 47 (get-latest-fragment-of-topic identifier))) 48 (if fragment 49 (handler-case (to-json-string fragment) 50 (condition (err) (progn 51 (setf (hunchentoot:return-code) hunchentoot:+http-internal-server-error+) 52 (format nil "<p style=\"color:red\">Condition: \"~a\"</p>" err)))) 53 "{}")))) 54 ((eq http-method :PUT) 55 (let ((put-data (hunchentoot:raw-post-data :external-format external-format :force-text t))) 56 (handler-case (progn 57 (json-importer:json-to-elem put-data) 58 (setf (hunchentoot:return-code) hunchentoot:+http-ok+) 59 (setf (hunchentoot:content-type) "text") 60 (format nil "~a" hunchentoot:+http-ok+)) 61 (condition (err) (progn 62 (setf (hunchentoot:return-code) hunchentoot:+http-internal-server-error+) 63 (format nil "<p style=\"color:red\">Condition: \"~a\"</p>" err)))))) 64 )))) 65 ;; ((eq http-method :POST) 66 ;; (let ((post-data (hunchentoot:raw-post-data :external-format external-format :force-text t))) 67 ;; (handler-case (progn 68 ;; (json-importer:json-to-elem post-data) 69 ;; (setf (hunchentoot:return-code) hunchentoot:+http-ok+) 70 ;; (setf (hunchentoot:content-type) "text") 71 ;; (format nil "~a" hunchentoot:+http-ok+)) 72 ;; (condition (err) (progn 73 ;; (setf (hunchentoot:return-code) hunchentoot:+http-internal-server-error+) 74 ;; (format nil "<p style=\"color:red\">Condition: \"~a\"</p>" err)))))) 75 ;; (t 76 ;; (progn ;for all htt-methods except for get and post 77 ;; (setf (hunchentoot:return-code) hunchentoot:+http-internal-server-error+) 78 ;; (format nil "<p style=\"color:red\">You have to use either the HTTP-Method \"GET\" or \"PUT\", but you used \"~a\"</p>" http-method))))))) 79 hunchentoot:*dispatch-table*))) 15 (declare (string json-get-prefix json-get-all-psis json-commit-url json-user-interface-url json-user-interface-file-path)) 16 (push ;TODO create a static-file-and-folder-handler for all static files 17 (create-regex-dispatcher json-user-interface-url #'(lambda() 18 (hunchentoot:handle-static-file json-user-interface-file-path))) 19 hunchentoot:*dispatch-table*) 20 (push 21 (create-regex-dispatcher "/prototype-1.6.0.3.js" #'(lambda() 22 (hunchentoot:handle-static-file "json/prototype-1.6.0.3.js"))) 23 hunchentoot:*dispatch-table*) 24 (push 25 (create-regex-dispatcher json-get-all-psis #'return-all-topic-psis) 26 hunchentoot:*dispatch-table*) 27 (push 28 (create-regex-dispatcher json-get-prefix #'return-json-fragment) 29 hunchentoot:*dispatch-table*) 30 (push 31 (create-regex-dispatcher json-commit-url #'json-commit) 32 hunchentoot:*dispatch-table*)) 33 34 35 ;; ============================================================================= 36 ;; --- some handlers for the json-rest-interface ------------------------------- 37 ;; ============================================================================= 38 (defun return-all-topic-psis (&optional param) 39 "return all psis currently existing in isidorus as a list of list. every topic is a list 40 of psis and the entire list contains a list of topics" 41 (declare (ignorable param)) 42 (let ((http-method (hunchentoot:request-method*))) 43 (if (eq http-method :GET) 44 (progn 45 (setf (hunchentoot:content-type*) "application/json") ;RFC 4627 46 (get-all-topic-psis)) 47 (setf (hunchentoot:return-code*) hunchentoot:+http-bad-request+)))) 48 49 50 (defun return-json-fragment(&optional psi) 51 "returns the json-fragmen belonging to the psi passed by the parameter psi" 52 (assert psi) 53 (let ((http-method (hunchentoot:request-method*))) 54 (if (eq http-method :GET) 55 (let ((identifier (let ((pos (search "%23" psi))) 56 (if pos 57 (let ((str-1 (subseq psi 0 pos)) 58 (str-2 (if (> (length psi) (+ pos 3)) 59 (subseq psi (+ pos 3)) 60 ""))) 61 (concatenate 'string str-1 "#" str-2)) 62 psi)))) 63 (setf (hunchentoot:content-type*) "application/json") ;RFC 4627 64 (let ((fragment 65 (get-latest-fragment-of-topic identifier))) 66 (if fragment 67 (handler-case (to-json-string fragment) 68 (condition (err) 69 (progn 70 (setf (hunchentoot:return-code*) hunchentoot:+http-internal-server-error+) 71 (format nil "<p>Condition: \"~a\"</p>" err)))) 72 "{}"))) 73 (setf (hunchentoot:return-code*) hunchentoot:+http-bad-request+)))) 74 75 76 (defun json-commit(&optional param) 77 "calls the json-to-elem method for a json-fragment and imports it to elephant" 78 (declare (ignorable param)) ;param is currently not used 79 (let ((http-method (hunchentoot:request-method*))) 80 (if (or (eq http-method :PUT) 81 (eq http-method :POST)) 82 (let ((external-format (flexi-streams:make-external-format :UTF-8 :eol-style :LF))) 83 (let ((json-data (hunchentoot:raw-post-data :external-format external-format :force-text t))) 84 (handler-case (json-importer:json-to-elem json-data) 85 (condition (err) 86 (progn 87 (setf (hunchentoot:return-code*) hunchentoot:+http-internal-server-error+) 88 (format nil "<p>Condition: \"~a\"</p>" err)))))) 89 (setf (hunchentoot:return-code*) hunchentoot:+http-bad-request+)))) -
TabularUnified trunk/src/threading/reader-writer.lisp ¶
r4 r17 1 1 (defpackage :isidorus-reader-writer 2 (:use :cl :hunchentoot-mp) 2 (:use :cl :hunchentoot-mp) ;hunchentoot 0.15.7 3 3 (:export :current-readers 4 4 :with-reader-lock … … 7 7 (in-package :isidorus-reader-writer) 8 8 9 (defvar *readerlist-mutex* (make-lock "isidorus current-readers lock")) 10 (defvar *writer-mutex* (make-lock "isidorus writer lock")) 9 (defvar *readerlist-mutex* (make-lock "isidorus current-readers lock")) ;hunchentoot 0.15.7 10 (defvar *writer-mutex* (make-lock "isidorus writer lock")) ;hunchentoot 0.15.7 11 ;;(defvar *readerlist-mutex* (hunchentoot::make-lock "isidorus current-readers lock")) ;hunchentoot 1.0.0 12 ;;(defvar *writer-mutex* (hunchentoot::make-lock "isidorus writer lock")) ;hunchentoot 1.0.0 11 13 12 14 (defvar *current-readers* nil) … … 15 17 (let 16 18 ((result nil)) 17 (with-lock (*readerlist-mutex*) 19 ;;(with-lock (*readerlist-mutex*) ;hunchentoot 0.15.7 20 (hunchentoot::with-lock-held (*readerlist-mutex*) ;hunchentoot 1.0.0 18 21 (setf result (copy-list *current-readers*))) 19 22 result)) 20 23 21 24 (defun add-current-to-reader-list () 22 (with-lock (*writer-mutex*) 23 (with-lock (*readerlist-mutex*) 25 (with-lock (*writer-mutex*) ;hunchentoot 0.15.7 26 (with-lock (*readerlist-mutex*) ;hunchentoot 0.15.7 27 ;;(hunchentoot::with-lock-held (*writer-mutex*) ;hunchentoot 1.0.0 28 ;;(hunchentoot::with-lock-held (*readerlist-mutex*) ;hunchentoot 1.0.0 24 29 (push *current-process* *current-readers*)))) 25 30 26 31 (defun remove-current-from-reader-list () 27 (with-lock (*readerlist-mutex*) 32 (with-lock (*readerlist-mutex*) ;hunchentoot 0.15.7 33 ;;(hunchentoot::with-lock-held (*readerlist-mutex*) ;hunchentoot 1.0.0 28 34 (setf *current-readers* 29 35 (delete *current-process* *current-readers*)))) … … 42 48 43 49 (defmacro with-writer-lock (&body body) 44 `(with-lock (*writer-mutex*) 50 `(with-lock (*writer-mutex*) ;hunchentoot 0.15.7 51 ;;`(hunchentoot::with-lock-held (*writer-mutex*) ;hunchetoot 1.0.0 45 52 (do 46 53 ((remaining-readers (current-readers) (current-readers)))
Note: See TracChangeset
for help on using the changeset viewer.