weavejester / ring-jetty-component

A component for the standard Ring Jetty adapter
32 stars 3 forks source link

Erro 500 to start jetty #6

Closed jcthalys closed 6 years ago

jcthalys commented 6 years ago

Is there something wrong with my config or it's really a bug because I tried as discribed in the README.md

(ns user
  (:require [test.server :refer [http-server]]
            [clojure.tools.namespace.repl :refer [refresh refresh-all]]
            [taoensso.timbre :as timbre]
            [com.stuartsierra.component :as component]))

(defn init []
  (timbre/set-level! :trace))

(defn start []
  (alter-var-root #'http-server component/start))

(defn stop []
  (alter-var-root #'http-server (fn [s] (when s (component/stop s)))))

(defn go []
  (init)
  (start))

(defn reset []
  (stop)
  (refresh :after 'user/go))

And

(ns test.server
  (:require [ring.component.jetty :refer [jetty-server]]
            [compojure.core :refer [defroutes GET POST]]
            [compojure.route :refer [not-found]]
            [ring.middleware.json :refer [wrap-json-response wrap-json-body]]
            [ring.middleware.params :refer [wrap-params]]
            [ring.middleware.not-modified :refer [wrap-not-modified]]
            [ring.logger.timbre :refer [wrap-with-logger]]

            [ring.middleware.cors :refer [wrap-cors]]
            [ring.middleware.defaults :refer [wrap-defaults api-defaults]]
            [cheshire.generate]
            ))

(defroutes app-routes
           (GET "/" [] "Hello World")
           (not-found "Not Found"))

(def app
  (wrap-defaults app-routes api-defaults))

(def http-server
  (jetty-server {:app app, :port 3000}))

And when a try connect

(ns test.server-test
  (:require
    [clojure.test :refer :all]
    [ring.mock.request :as mock]
    [test.server :refer :all]
    [clj-http.client :as http]
    [com.stuartsierra.component :as component]))

(deftest test-app
  (testing "main route"
    (let [server (component/start http-server)]
      (try
        (let [;response (app (mock/request :get "/"))
             response (http/get "http://localhost:3000/")]
         (is (= (:status response) 200))
         (is (= (:body response) "Hello World")))
        (finally
          (component/stop server)))))
Starting nREPL server...
/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin/java -Dfile.encoding=UTF-8 -XX:-OmitStackTraceInFastThrow -Dclojure.compile.path=/Users/jcthalys/Development/Clojure/nubank-test/target/classes -Dnubank-test.version=0.1.0-SNAPSHOT -Dclojure.debug=false "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=64178:/Applications/IntelliJ IDEA CE.app/Contents/bin" -classpath /Users/jcthalys/Development/Clojure/nubank-test/test:/Users/jcthalys/Development/Clojure/nubank-test/dev:/Users/jcthalys/Development/Clojure/nubank-test/src:/Users/jcthalys/Development/Clojure/nubank-test/dev-resources:/Users/jcthalys/Development/Clojure/nubank-test/resources:/Users/jcthalys/Development/Clojure/nubank-test/target/classes:/Users/jcthalys/.m2/repository/clj-time/clj-time/0.11.0/clj-time-0.11.0.jar:/Users/jcthalys/.m2/repository/org/clojars/pjlegato/clansi/1.3.0/clansi-1.3.0.jar:/Users/jcthalys/.m2/repository/com/taoensso/timbre/4.10.0/timbre-4.10.0.jar:/Users/jcthalys/.m2/repository/org/apache/httpcomponents/httpmime/4.5.3/httpmime-4.5.3.jar:/Users/jcthalys/.m2/repository/org/eclipse/jetty/jetty-http/9.2.10.v20150310/jetty-http-9.2.10.v20150310.jar:/Users/jcthalys/.m2/repository/instaparse/instaparse/1.4.0/instaparse-1.4.0.jar:/Users/jcthalys/.m2/repository/org/apache/httpcomponents/httpcore-nio/4.4.6/httpcore-nio-4.4.6.jar:/Users/jcthalys/.m2/repository/tigris/tigris/0.1.1/tigris-0.1.1.jar:/Users/jcthalys/.m2/repository/commons-io/commons-io/2.5/commons-io-2.5.jar:/Users/jcthalys/.m2/repository/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:/Users/jcthalys/.m2/repository/slamhound/slamhound/1.3.1/slamhound-1.3.1.jar:/Users/jcthalys/.m2/repository/org/eclipse/jetty/jetty-server/9.2.10.v20150310/jetty-server-9.2.10.v20150310.jar:/Users/jcthalys/.m2/repository/org/clojure/tools.macro/0.1.5/tools.macro-0.1.5.jar:/Users/jcthalys/.m2/repository/ring/ring-anti-forgery/1.1.0/ring-anti-forgery-1.1.0.jar:/Users/jcthalys/.m2/repository/potemkin/potemkin/0.4.3/potemkin-0.4.3.jar:/Users/jcthalys/.m2/repository/com/taoensso/truss/1.5.0/truss-1.5.0.jar:/Users/jcthalys/.m2/repository/ring/ring-codec/1.0.1/ring-codec-1.0.1.jar:/Users/jcthalys/.m2/repository/ring/ring-servlet/1.4.0/ring-servlet-1.4.0.jar:/Users/jcthalys/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-smile/2.5.3/jackson-dataformat-smile-2.5.3.jar:/Users/jcthalys/.m2/repository/ring/ring-headers/0.3.0/ring-headers-0.3.0.jar:/Users/jcthalys/.m2/repository/com/stuartsierra/component/0.3.2/component-0.3.2.jar:/Users/jcthalys/.m2/repository/ring/ring-ssl/0.3.0/ring-ssl-0.3.0.jar:/Users/jcthalys/.m2/repository/commons-fileupload/commons-fileupload/1.3.3/commons-fileupload-1.3.3.jar:/Users/jcthalys/.m2/repository/org/clojure/tools.nrepl/0.2.12/tools.nrepl-0.2.12.jar:/Users/jcthalys/.m2/repository/org/clojure/tools.reader/0.10.0/tools.reader-0.10.0.jar:/Users/jcthalys/.m2/repository/ring/ring-core/1.6.3/ring-core-1.6.3.jar:/Users/jcthalys/.m2/repository/ring-logger/ring-logger/0.7.7/ring-logger-0.7.7.jar:/Users/jcthalys/.m2/repository/clojure-complete/clojure-complete/0.2.4/clojure-complete-0.2.4.jar:/Users/jcthalys/.m2/repository/clj-http/clj-http/3.7.0/clj-http-3.7.0.jar:/Users/jcthalys/.m2/repository/medley/medley/1.0.0/medley-1.0.0.jar:/Users/jcthalys/.m2/repository/crypto-equality/crypto-equality/1.0.0/crypto-equality-1.0.0.jar:/Users/jcthalys/.m2/repository/ring/ring-jetty-adapter/1.4.0/ring-jetty-adapter-1.4.0.jar:/Users/jcthalys/.m2/repository/org/clojure/clojure/1.9.0/clojure-1.9.0.jar:/Users/jcthalys/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.5.3/jackson-core-2.5.3.jar:/Users/jcthalys/.m2/repository/ring/ring-json/0.4.0/ring-json-0.4.0.jar:/Users/jcthalys/.m2/repository/hiccup/hiccup/1.0.5/hiccup-1.0.5.jar:/Users/jcthalys/.m2/repository/clj-tuple/clj-tuple/0.2.2/clj-tuple-0.2.2.jar:/Users/jcthalys/.m2/repository/com/stuartsierra/dependency/0.2.0/dependency-0.2.0.jar:/Users/jcthalys/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-cbor/2.5.3/jackson-dataformat-cbor-2.5.3.jar:/Users/jcthalys/.m2/repository/org/clojure/tools.logging/0.3.1/tools.logging-0.3.1.jar:/Users/jcthalys/.m2/repository/ring-jetty-component/ring-jetty-component/0.3.1/ring-jetty-component-0.3.1.jar:/Users/jcthalys/.m2/repository/compojure/compojure/1.6.0/compojure-1.6.0.jar:/Users/jcthalys/.m2/repository/slingshot/slingshot/0.12.2/slingshot-0.12.2.jar:/Users/jcthalys/.m2/repository/ring-logger-timbre/ring-logger-timbre/0.7.6/ring-logger-timbre-0.7.6.jar:/Users/jcthalys/.m2/repository/org/clojure/core.specs.alpha/0.1.24/core.specs.alpha-0.1.24.jar:/Users/jcthalys/.m2/repository/org/eclipse/jetty/jetty-io/9.2.10.v20150310/jetty-io-9.2.10.v20150310.jar:/Users/jcthalys/.m2/repository/org/clojure/tools.namespace/0.2.11/tools.namespace-0.2.11.jar:/Users/jcthalys/.m2/repository/suspendable/suspendable/0.1.1/suspendable-0.1.1.jar:/Users/jcthalys/.m2/repository/com/stuartsierra/component.repl/0.2.0/component.repl-0.2.0.jar:/Users/jcthalys/.m2/repository/io/aviso/pretty/0.1.33/pretty-0.1.33.jar:/Users/jcthalys/.m2/repository/org/apache/httpcomponents/httpcore/4.4.6/httpcore-4.4.6.jar:/Users/jcthalys/.m2/repository/crypto-random/crypto-random/1.2.0/crypto-random-1.2.0.jar:/Users/jcthalys/.m2/repository/ring/ring-defaults/0.3.1/ring-defaults-0.3.1.jar:/Users/jcthalys/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar:/Users/jcthalys/.m2/repository/riddley/riddley/0.1.12/riddley-0.1.12.jar:/Users/jcthalys/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:/Users/jcthalys/.m2/repository/cheshire/cheshire/5.5.0/cheshire-5.5.0.jar:/Users/jcthalys/.m2/repository/ring-mock/ring-mock/0.1.5/ring-mock-0.1.5.jar:/Users/jcthalys/.m2/repository/ring-cors/ring-cors/0.1.11/ring-cors-0.1.11.jar:/Users/jcthalys/.m2/repository/org/eclipse/jetty/jetty-util/9.2.10.v20150310/jetty-util-9.2.10.v20150310.jar:/Users/jcthalys/.m2/repository/org/apache/httpcomponents/httpasyncclient/4.1.3/httpasyncclient-4.1.3.jar:/Users/jcthalys/.m2/repository/com/taoensso/encore/2.91.0/encore-2.91.0.jar:/Users/jcthalys/.m2/repository/org/apache/httpcomponents/httpclient/4.5.3/httpclient-4.5.3.jar:/Users/jcthalys/.m2/repository/joda-time/joda-time/2.8.2/joda-time-2.8.2.jar:/Users/jcthalys/.m2/repository/clout/clout/2.1.2/clout-2.1.2.jar:/Users/jcthalys/.m2/repository/org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.jar clojure.main -i /private/var/folders/ht/ln85g08d70b3rkhzx4xn17vc0000gn/T/form-init5838534850579925071.clj
Connecting to local nREPL server...
Clojure 1.9.0
nREPL server started on port 64213 on host 127.0.0.1 - nrepl://127.0.0.1:64213
(go)
2017-12-10 12:01:50.342:INFO::nREPL-worker-0: Logging initialized @12249ms
=>
#ring.component.jetty.JettyServer{:app #object[ring.middleware.not_modified$wrap_not_modified$fn__3855
                                               0xfc74f68
                                               "ring.middleware.not_modified$wrap_not_modified$fn__3855@fc74f68"],
                                  :port 3000,
                                  :server #object[org.eclipse.jetty.server.Server
                                                  0x552e34e3
                                                  "org.eclipse.jetty.server.Server@552e34e3"],
                                  :handler #object[clojure.lang.Atom
                                                   0x7a864798
                                                   {:status :ready,
                                                    :val #object[clojure.lang.Delay
                                                                 0x7953426c
                                                                 {:status :pending, :val nil}]}]}
2017-12-10 12:02:05.134:WARN:oejs.HttpChannel:qtp1345131112-25: /
java.lang.NullPointerException
    at ring.component.jetty.JettyServer$fn__615.invoke(jetty.clj:14)
    at ring.adapter.jetty$proxy_handler$fn__581.invoke(jetty.clj:24)
    at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:497)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.base/java.lang.Thread.run(Thread.java:844)
2017-12-10 12:02:05.984:WARN:oejs.HttpChannel:qtp1345131112-27: /favicon.ico
java.lang.NullPointerException
    at ring.component.jetty.JettyServer$fn__615.invoke(jetty.clj:14)
    at ring.adapter.jetty$proxy_handler$fn__581.invoke(jetty.clj:24)
    at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:497)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.base/java.lang.Thread.run(Thread.java:844)
weavejester commented 6 years ago

You have an error in your code. You've written:

(def app
  (wrap-defaults app-routes api-defaults))

(def http-server
  (jetty-server {:app app, :port 3000}))

But the README says:


(def app
  {:handler handler})

(def http-server
  (jetty-server {:app app, :port 3000}))
jcthalys commented 6 years ago

Yes, that's work! Sorry, and thank you for always helping and responding quickly

weavejester commented 6 years ago

No problem