本文介绍了当Leeph环服务器在Aleph + Ring上时,NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Ring上运行Aleph,并使用 lein环形服务器来缩短反馈循环。

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

当我调用 lein环形服务器时,一切似乎都很好,但是当我将浏览器指向url时,会得到一个讨厌的 NullPointerException ,堆栈跟踪如下。

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.

但是,当我运行(al.app/start 3006),则不会显示 NLP

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

整个项目可在。

我在做什么错了?

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]
...

我正在使用aleph 0.3.2,这就是我的代码:

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


推荐答案

Lein-Ring插件使用嵌入式Jetty Web服务器,而Aleph使用异步Netty Web服务器。 aleph.http / wrap-aleph-handler 中间件仅设计用于以 aleph.http / start-http-server开头的Netty服务器。 函数。

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.

这篇关于当Leeph环服务器在Aleph + Ring上时,NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-15 18:02