NullPointerException when lein ring server on Aleph+Ring

♀尐吖头ヾ 提交于 2020-06-17 07:38:27

问题


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})) 

回答1:


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.



来源:https://stackoverflow.com/questions/24278946/nullpointerexception-when-lein-ring-server-on-alephring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!