Fall-through to my error handler not working

36 views
Skip to first unread message

Alen Ribic

unread,
Dec 23, 2009, 8:58:01 AM12/23/09
to Compojure
I am using Compojure "0.3.1" and I have a static-routes and error-
routes defined like so:

(defroutes static-routes
(GET "/*"
(or (serve-file (:* params)) :next)))

(defroutes error-routes
(ANY "/*" [404 "404 - Page not found"]))

Error 404 handeling works fine until I add this decorator for my ws-
json-routes:

(decorate ws-json-routes
(with-headers {"Content-Type" "application/json; charset=UTF-8"}))

After that I get this exception when I expect a HTTP 404 to be caught
by my error-routes for urls not located in routes:

ERROR log - /
java.lang.NullPointerException
at compojure.http.servlet$update_servlet_response__1045.invoke
(servlet.clj:99)
at compojure.http.servlet$request_handler__1050.invoke(servlet.clj:
110)
at com.billdozr.service.web$start_server__141$fn__143.invoke(web.clj:
75)
at com.billdozr.service.web.proxy$javax.servlet.http.HttpServlet
$0.service(Unknown Source)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1166)
at
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal
(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter
(OncePerRequestFilter.java:76)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle
(ServletHandler.java:388)
at org.mortbay.jetty.servlet.SessionHandler.handle
(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle
(ContextHandler.java:765)
at org.mortbay.jetty.handler.HandlerWrapper.handle
(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
536)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete
(HttpConnection.java:915)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405)
at org.mortbay.jetty.bio.SocketConnector$Connection.run
(SocketConnector.java:228)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run
(QueuedThreadPool.java:582)

Am I suppose to explicitly maybe set the content-type of the other
routes after decorating the ws-json-routes one?

Regards,
-Alen

Alen Ribic

unread,
Dec 23, 2009, 9:07:53 AM12/23/09
to Compojure
I came across Brian Carper's fix/workaround on this in his cow-blog
clojure web app.

;; This is to work around a bug in Compojure
;; (or a misunderstanding on my part about how Compojure should work)
;; This prevents NPEs and INTERNAL_SERVER_ERRORS due to with-mimetypes
;; barfing on requests with no :body (e.g. when file isn't found and
;; we want to fallthrough to error-routes
(defn short-circuit [handler]
(fn [request]
(let [response (handler request)]
(when (:body response)
response))))

This fixes my problem too.
Shouldn't the response always have the :body appended even if no body
was supplied during the request handling process?

-Al

James Reeves

unread,
Dec 23, 2009, 6:12:09 PM12/23/09
to Compojure
This looks like a bug. If anyone wants to submit a patch for it I'll
make it a priority to merge it in.

- James

Alen Ribic

unread,
Dec 26, 2009, 12:52:22 PM12/26/09
to Compojure
Hi James,

I've opened an issue for this at github and provided the necessary
patch.

http://github.com/weavejester/compojure/issues/#issue/18

Happy Christmas.

-Alen Ribic

Reply all
Reply to author
Forward
0 new messages