<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span class="Apple-tab-span" style="white-space:pre"> </span>Hmm. Here’s a full working example:<div><br></div><div><font face="Consolas">(in-package :common-lisp-user)<br><br>(ql:quickload :hunchentoot)<br>(ql:quickload :drakma)<br>(ql:quickload :cl-who)<br><br>(defpackage :org.softwarematters.hunchentoot-test<br> (:nicknames :hunchentoot-test :web-test)<br> (:use :common-lisp<br> :cl-who))<br><br>(in-package :web-test)<br><br>;;; Define the web server acceptor<br><br>(defparameter *test-acceptor*<br> (make-instance 'hunchentoot:easy-acceptor<br> :port 8081<br> :document-root #p"/Users/Patrick/src/lisp/web/"<br> :access-log-destination "/tmp/web-test-access.log"<br> :message-log-destination "/tmp/web-test-message.log"))<br><br>;;; A couple of macros for encapsulating the details of a standard page.<br>;;; This came from Stack Overflow (How to connect a web app to Hunchentoot)<br>;;; and <a href="http://www.adampetersen.se/articles/lispweb.htm">http://www.adampetersen.se/articles/lispweb.htm</a>.</font></div><div><font face="Consolas"><br>(defmacro standard-page ((&key title) &body body)<br> "Abstract away the placing of standard page stuff."<br> `(with-html-output-to-string (*standard-output* nil :prologue t :indent t)<br> (:html :xmlns "<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>"<br><span class="Apple-tab-span" style="white-space:pre"> </span> :xml\:lang "en" <br><span class="Apple-tab-span" style="white-space:pre"> </span> :lang "en"<br><span class="Apple-tab-span" style="white-space:pre"> </span> (:head <br><span class="Apple-tab-span" style="white-space:pre"> </span> (:meta :http-equiv "content-type" <br><span class="Apple-tab-span" style="white-space:pre"> </span> :content "text/html;charset=UTF-8")<br><span class="Apple-tab-span" style="white-space:pre"> </span> (:title ,title)<br><span class="Apple-tab-span" style="white-space:pre"> </span> (:link :type "text/css" <br><span class="Apple-tab-span" style="white-space:pre"> </span> :rel "stylesheet"<br><span class="Apple-tab-span" style="white-space:pre"> </span> :href "/test.css"))<br><span class="Apple-tab-span" style="white-space:pre"> </span> (:body <br><span class="Apple-tab-span" style="white-space:pre"> </span> (:div :id "header")<br><span class="Apple-tab-span" style="white-space:pre"> </span> ,@body<br><span class="Apple-tab-span" style="white-space:pre"> </span> (:div :id "footer")))))<br><br>(defmacro defpage (name (title) &body body)<br> `(progn<br> (defmethod ,name ()<br> (standard-page (,title)<br> ,@body))<br> (push (create-prefix-dispatcher ,(format nil "/~(~a~).html" name) ',name)<br> *dispatch-table*)))<br><br>;;; URI implementations<br><br>(defun display-home-page ()<br> "Display the home page."<br> (hunchentoot:redirect "/index.html"))<br><br>(push (hunchentoot:create-regex-dispatcher "^/$" 'display-home-page)<br> hunchentoot:*dispatch-table*)<br><br>(hunchentoot:define-easy-handler (home-page-handler<br> :uri "/index.html"<br> :default-request-type :GET)<br> ()<br> "Return the home page."<br> (standard-page (:title "Web Test Home Page")<br> (:h1 "Web Test")<br> (:p "remote IP address: "<br> (format t "~A" (hunchentoot:remote-addr*)))<br> (:p "real remote IP address: "<br> (format t "~A" (hunchentoot:real-remote-addr)))<br> (:p "headers: "<br> (:br)<br> (dolist (header (hunchentoot:headers-in*))<br> (format t "~A: ~A<br/>" (car header) (cdr header))))<br> (:p "GET parameters: "<br> (format t "~A" (hunchentoot:get-parameters*)))))<br><br>;;; Override 404 handling<br><br>(defun display-404-page ()<br> (standard-page (:title "Web Test 404 Page") (:h1 "404")))<br><br>(defmethod acceptor-status-message (acceptor (http-status-code (eql 404)) &key)<br> (display-404-page))<br><br>;(defmethod hunchentoot:acceptor-status-message (acceptor (http-status-code (eql 404)) &key) "NOT FOUND")<br><br>;;; Start the web server<br><br>(hunchentoot:start *test-acceptor*)<br></font><br></div><div>I tried calling (display-404-page) in an easy-handler and it works fine.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Thanks for any help.</div><div><br></div><div>Regards,</div><div><br></div><div>Patrick</div><div><br><div><div>On May 8, 2014, at 9:12 AM, Hans Hübner <<a href="mailto:hans.huebner@gmail.com">hans.huebner@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2014-05-08 15:07 GMT+02:00 Patrick May <span dir="ltr"><<a href="mailto:patrick.may@mac.com" target="_blank">patrick.may@mac.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><span style="white-space:pre-wrap"> </span>Removing the incorrect eql specialization still doesn’t result in my 404 page being displayed. Do I have to subclass acceptor to get it to work?</div>
</div></blockquote><div><br></div><div>No, it works just fine without an extra subclass, e.g.:</div><div><br></div><div>(defmethod hunchentoot:acceptor-status-message (acceptor (http-status-code (eql 404)) &key) "NOT FOUND")</div>
<div><br></div><div>-Hans</div></div></div></div>
</blockquote></div><br></div></body></html>