简体   繁体   中英

NullPointerException when lein ring server on Aleph+Ring

I am trying to run Aleph on top of Ring and use lein ring server for shorter feedback loop.

When I'm invoking lein ring server everything seems to be fine but when I point my browser to an url I get a nasty NullPointerException with the stack trace below.

However, when I run (al.app/start 3006) then no NLP shows up.

The whole project is available on GitHub .

What am I doing wrong?

core.clj:107    lamina.core/enqueue
app.clj:39  al.app/hello-handler
http.clj:79 aleph.http/wrap-aleph-handler[fn]
response.clj:27 compojure.response/eval1328[fn]
response.clj:10 compojure.response/eval1289[fn]
core.clj:93 compojure.core/make-route[fn]
core.clj:39 compojure.core/if-route[fn]
...    

I am using aleph 0.3.2 and that's my code:

(ns al.app
  (:use
      aleph.http
      lamina.core
      compojure.core
      ring.middleware.keyword-params)
 (:require [compojure.route :as route]))

(defn hello-handler                                                                    
  "Our handler for the /hello path"                                                    
  [ch request]                                                                         
  (let [params (:route-params request)                                          
        name (params :name)]                                                           
    (enqueue ch                                                                        
      {:status 200                                                                     
       :headers {}                                                                     
       :body (str "Hello " name)})))                                                   

(defroutes my-routes                                                                   
  (GET ["/hello/:name", :name #"[a-zA-Z]+"] {} (wrap-aleph-handler hello-handler))     
  (route/not-found "Page not found"))                                                  

(defn start                                                                            
    "Start our server in the specified port"                                           
    [port]                                                                             
    (start-http-server (wrap-ring-handler my-routes) {:port port})) 

The Lein-Ring plugin uses an embedded Jetty web server, while Aleph uses the asynchronous Netty web server. The aleph.http/wrap-aleph-handler middleware is designed only to work with a Netty server started with aleph.http/start-http-server function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM