EzDevInfo.com

noir

A framework for writing web applications in clojure. Noir

Reason for skipping AOT?

In many noir apps I have seen the below declaration. What is the purpose of skipping aot ? When to use it and when not to use it ? Any advantages / disadvantages ?

:main ^{:skip-aot true} sample-app.server

Source: (StackOverflow)

Confusing Clojure Compile Errors -- Bad line reporting?

I am getting compile errors while running lein run on my Noir project. It was working, and then suddenly it stopped working. My suspicion was that the error is connected with trying to include [org.pegdown/pegdown "1.1.0"] in my dependencies vector in the project file, but I don't know for sure. I removed that line, ran lein clean; lein deps and then tried lein run again, but the error persists.

Below are two separate errors that I get. I don't know what triggers either error. All my files (in the namespace "benekastah") report an error at line 1, which is typically a normal ns call.

The second error seems to indicate that the problem is in post_modify.clj, but that was working before and I haven't changed it.

I tried the solution found here and it didn't seem to work.

Any insight into these confusing errors?

Error 1:

Exception in thread "main" java.lang.RuntimeException: java.lang.ExceptionInInitializerError
at clojure.lang.Util.runtimeException(Util.java:165)
at clojure.lang.Compiler.eval(Compiler.java:6476)
at clojure.lang.Compiler.load(Compiler.java:6902)
at clojure.lang.RT.loadResourceScript(RT.java:357)
at clojure.lang.RT.loadResourceScript(RT.java:348)
at clojure.lang.RT.load(RT.java:427)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$require.doInvoke(core.clj:5352)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at user$eval1.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6465)
at clojure.lang.Compiler.eval(Compiler.java:6454)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at clojure.main$eval_opt.invoke(main.clj:296)
at clojure.main$initialize.invoke(main.clj:315)
at clojure.main$null_opt.invoke(main.clj:348)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:405)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at clojure.lang.RT.loadClassForName(RT.java:2030)
at clojure.lang.RT.load(RT.java:417)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:604)
at clojure.core$use.doInvoke(core.clj:5363)
at clojure.lang.RestFn.invoke(RestFn.java:512)
at benekastah.views.common$loading__4505__auto__.invoke(common.clj:1)
at benekastah.views.common__init.load(Unknown Source)
at benekastah.views.common__init.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at clojure.lang.RT.loadClassForName(RT.java:2030)
at clojure.lang.RT.load(RT.java:417)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$require.doInvoke(core.clj:5352)
at clojure.lang.RestFn.invoke(RestFn.java:512)
at benekastah.views.blog.index$loading__4505__auto__.invoke(index.clj:1)
at benekastah.views.blog.index__init.load(Unknown Source)
at benekastah.views.blog.index__init.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at clojure.lang.RT.loadClassForName(RT.java:2030)
at clojure.lang.RT.load(RT.java:417)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$require.doInvoke(core.clj:5352)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at noir.server$load_views.doInvoke(server.clj:25)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at benekastah.server$eval10.invoke(server.clj:5)
at clojure.lang.Compiler.eval(Compiler.java:6465)
... 31 more
Caused by: java.lang.NullPointerException
at clojure.core$refer.doInvoke(core.clj:3775)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at clojure.lang.AFn.applyToHelper(AFn.java:161)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_lib.doInvoke(core.clj:5252)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:604)
at clojure.core$use.doInvoke(core.clj:5363)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at benekastah.css.base__init.load(Unknown Source)
at benekastah.css.base__init.<clinit>(Unknown Source)
... 92 more

Error 2:

Exception in thread "main" java.lang.NullPointerException, compiling:(post_modify.clj:1)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3342)
at clojure.lang.Compiler.compile1(Compiler.java:6985)
at clojure.lang.Compiler.compile1(Compiler.java:6975)
at clojure.lang.Compiler.compile(Compiler.java:7046)
at clojure.lang.RT.compile(RT.java:385)
at clojure.lang.RT.load(RT.java:425)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$require.doInvoke(core.clj:5352)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at noir.server$load_views.doInvoke(server.clj:25)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3337)
at clojure.lang.Compiler.compile1(Compiler.java:6985)
at clojure.lang.Compiler.compile(Compiler.java:7046)
at clojure.lang.RT.compile(RT.java:385)
at clojure.lang.RT.load(RT.java:425)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$compile$fn__4615.invoke(core.clj:5397)
at clojure.core$compile.invoke(core.clj:5396)
at user$eval27.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6465)
at clojure.lang.Compiler.eval(Compiler.java:6455)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at clojure.main$eval_opt.invoke(main.clj:296)
at clojure.main$initialize.invoke(main.clj:315)
at clojure.main$null_opt.invoke(main.clj:348)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:405)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
at clojure.lang.Compiler$ObjExpr.emitVar(Compiler.java:4728)
at clojure.lang.Compiler$DefExpr.emit(Compiler.java:395)
at clojure.lang.Compiler.compile1(Compiler.java:6984)
at clojure.lang.Compiler.compile(Compiler.java:7046)
at clojure.lang.RT.compile(RT.java:385)
at clojure.lang.RT.load(RT.java:425)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$require.doInvoke(core.clj:5352)
at clojure.lang.RestFn.invoke(RestFn.java:551)
at benekastah.views.blog.post_modify$loading__4505__auto__.invoke(post_modify.clj:1)
at clojure.lang.AFn.applyToHelper(AFn.java:159)
at clojure.lang.AFn.applyTo(AFn.java:151)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3337)
... 46 more
Exception in thread "main" java.lang.RuntimeException: java.lang.ExceptionInInitializerError
at clojure.lang.Util.runtimeException(Util.java:165)
at clojure.lang.Compiler.eval(Compiler.java:6476)
at clojure.lang.Compiler.load(Compiler.java:6902)
at clojure.lang.RT.loadResourceScript(RT.java:357)
at clojure.lang.RT.loadResourceScript(RT.java:348)
at clojure.lang.RT.load(RT.java:427)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$require.doInvoke(core.clj:5352)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at user$eval1.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6465)
at clojure.lang.Compiler.eval(Compiler.java:6454)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at clojure.main$eval_opt.invoke(main.clj:296)
at clojure.main$initialize.invoke(main.clj:315)
at clojure.main$null_opt.invoke(main.clj:348)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:405)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at clojure.lang.RT.loadClassForName(RT.java:2030)
at clojure.lang.RT.load(RT.java:417)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:604)
at clojure.core$use.doInvoke(core.clj:5363)
at clojure.lang.RestFn.invoke(RestFn.java:512)
at benekastah.views.common$loading__4505__auto__.invoke(common.clj:1)
at benekastah.views.common__init.load(Unknown Source)
at benekastah.views.common__init.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at clojure.lang.RT.loadClassForName(RT.java:2030)
at clojure.lang.RT.load(RT.java:417)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$require.doInvoke(core.clj:5352)
at clojure.lang.RestFn.invoke(RestFn.java:512)
at benekastah.views.blog.index$loading__4505__auto__.invoke(index.clj:1)
at benekastah.views.blog.index__init.load(Unknown Source)
at benekastah.views.blog.index__init.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at clojure.lang.RT.loadClassForName(RT.java:2030)
at clojure.lang.RT.load(RT.java:417)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$require.doInvoke(core.clj:5352)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at noir.server$load_views.doInvoke(server.clj:25)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at benekastah.server$eval10.invoke(server.clj:5)
at clojure.lang.Compiler.eval(Compiler.java:6465)
... 31 more
Caused by: java.lang.NullPointerException
at clojure.core$refer.doInvoke(core.clj:3775)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at clojure.lang.AFn.applyToHelper(AFn.java:161)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_lib.doInvoke(core.clj:5252)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:604)
at clojure.core$use.doInvoke(core.clj:5363)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at benekastah.css.base__init.load(Unknown Source)
at benekastah.css.base__init.<clinit>(Unknown Source)
... 92 more

benekastah.views.blog.post_modify.clj

(ns benekastah.views.blog.post-modify
  (:require [noir.response :as resp]
            [somnium.congomongo :as congo]
            [clj-time.core :as time]
            [clj-time.format :as time-format]
            [clj-time.coerce :as time-coerce]
            [clojure.string :as cl-string]
            [benekastah.lib.string :as b-string])
  (:use noir.core
        benekastah.models.db))

(defn- save-post
  [post]
  (try (save! :post post)
       (resp/redirect "/")
    (catch Exception e
      {:status 500
       :body (str "Could not save post: " e)})))

(defpage [:post "/post"] [& param-lists]
         (let [params (populate-defaults 
                        :post 
                        (apply hash-map (apply concat param-lists)))
               {date :date, title :title } params
               slug (str 
                      (time-format/unparse 
                        (time-format/formatters :date)
                        (time-coerce/from-date date)) 
                      "_"
                      (cl-string/replace (cl-string/trim title)
                                         #"[^\w\-]"
                                         "_"))
               p (merge params {:slug slug})]
           (save-post p)))

(defpage [:put "/post"] {:keys [id]}
         (let [post (congo/fetch-by-id id)]
           (save-post post)))

(defpage [:delete "/post"] {:keys [id]}
         (let [post (congo/fetch-by-id id)]
           (congo/destroy! :post post)))

Source: (StackOverflow)

Advertisements

Clojure and noir for a classic web application

How would one go about using Noir with user authentication and an ORM.

Would it all have to be accessed via java objects?

Are there any rails style "blog" tutorials that go about user auth and database access?


Source: (StackOverflow)

How do you accept file uploads in noir

I have a file input setup like this

[:p "Upload a book"]
      (form-to [:post "/upload"]
               (file-upload :book)
               (submit-button "Upload"))

My upload endpoint then looks like this.

(defpage [:post "/upload"] {:keys [book]} (println book))

book just seems to be a string of the title of the file that was uploaded and not the file itself. How do I get the file?


Source: (StackOverflow)

Howto use lib-noir stateful-sessions in Compojure

I think I have a fairly straightforward problem here. But I've been looking at this screen too long. So I'm trying (and failing) to get stateful sessions working in Compojure. The refheap code paste is here.

You can see me trying to use lib-noir (line 62) to initialize stateful sessions. Then when the app is running, I try to make a call to session/put! some data in the session (line 43).

Now, this stacktrace says that in session.put!, lib-noir is trying to swap out a session var that hasn't been bound. Now, I thought I did that on line 62. So I'm sure this is a simple fix that another set of eyes will see.

java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom                                                                                                                                                                                                                                                                                                                                
        at clojure.core$swap_BANG_.invoke(core.clj:2110)                                                                                                                                                                                                                                                                                                                                                                  
        at noir.session$put_BANG_.invoke(session.clj:18)                                                                                                                                                                                                                                                                                                                                                                  
        at bkell.http.handler$fn__6159.invoke(handler.clj:156)                                                                                                                                                                                                                                                                                                                                                            
        at compojure.core$make_route$fn__3800.invoke(core.clj:93)                                                                                                                                                                                                                                                                                                                                                         
        at compojure.core$if_route$fn__3784.invoke(core.clj:39)                                                                                                                                                                                                                                                                                                                                                           
        at compojure.core$if_method$fn__3777.invoke(core.clj:24)                                                                                                                                                                                                                                                                                                                                                          
        at compojure.core$routing$fn__3806.invoke(core.clj:106)                                                                                                                                                                                                                                                                                                                                                           
        at clojure.core$some.invoke(core.clj:2390)                                                                                                                                                                                                                                                                                                                                                                        
        at compojure.core$routing.doInvoke(core.clj:106)                                                                                                                                                                                                                                                                                                                                                                  
        at clojure.lang.RestFn.applyTo(RestFn.java:139)                                                                                                                                                                                                                                                                                                                                                                   
        ...
        at java.lang.Thread.run(Thread.java:619)

Thanks


Source: (StackOverflow)

How to build the war file for a Clojure Noir Web application?

I was able to use these commands to generate and run a sample web app from instrcution on this web site

https://github.com/ibdknox/lein-noir

lein new noir my-project-name
lein run

( I am using Leiningen 2.0.0-preview10 on Java 1.7.0_09 Java HotSpot(TM) Client VM )

The starter web app does run ok but I want to generate the war file which I can deploy manually to my application server (Websphere).

What command or configuration for Leingen 2 is needed to generate a war file for a Noir project?

To clarify, this command "lein new noir webpoc2" generate a noir project with this .clj file

(defproject webpoc1 "0.1.0-SNAPSHOT"
            :description "FIXME: write this!"
            :dependencies [[org.clojure/clojure "1.4.0"]
                           [noir "1.3.0-beta3"]]
            :main webpoc1.server)

If I add Ring to the cl file

:ring {
                   :handler webpoc1.server/handler

}

, and run lein ring uberwar, I get this :

Exception in thread "main" java.lang.RuntimeException: No such var: webpoc1.server/handler, compiling:(
/servlet.clj:1)
        at clojure.lang.Compiler.analyze(Compiler.java:6281)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3497)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6457)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5618)
        at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5054)
        at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3674)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6453)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6443)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3548)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6457)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3497)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6457)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5618)
        at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5054)
        at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3674)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6453)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6443)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.access$100(Compiler.java:37)
        at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:518)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6455)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler.compile1(Compiler.java:7030)
        at clojure.lang.Compiler.compile1(Compiler.java:7025)
        at clojure.lang.Compiler.compile(Compiler.java:7097)
        at clojure.lang.RT.compile(RT.java:387)
        at clojure.lang.RT.load(RT.java:427)
        at clojure.lang.RT.load(RT.java:400)
        at clojure.core$load$fn__4890.invoke(core.clj:5415)
        at clojure.core$load.doInvoke(core.clj:5414)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invoke(core.clj:5227)
        at clojure.core$compile$fn__4895.invoke(core.clj:5426)
        at clojure.core$compile.invoke(core.clj:5425)
        at user$eval3.invoke(NO_SOURCE_FILE:1)
        at clojure.lang.Compiler.eval(Compiler.java:6511)
        at clojure.lang.Compiler.eval(Compiler.java:6500)
        at clojure.lang.Compiler.eval(Compiler.java:6501)
        at clojure.lang.Compiler.eval(Compiler.java:6477)
        at clojure.core$eval.invoke(core.clj:2797)
        at clojure.main$eval_opt.invoke(main.clj:297)
        at clojure.main$initialize.invoke(main.clj:316)
        at clojure.main$null_opt.invoke(main.clj:349)
        at clojure.main$main.doInvoke(main.clj:427)
        at clojure.lang.RestFn.invoke(RestFn.java:421)
        at clojure.lang.Var.invoke(Var.java:419)
        at clojure.lang.AFn.applyToHelper(AFn.java:163)
        at clojure.lang.Var.applyTo(Var.java:532)
        at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: No such var: webpoc1.server/handler
        at clojure.lang.Util.runtimeException(Util.java:170)
        at clojure.lang.Compiler.resolveIn(Compiler.java:6740)
        at clojure.lang.Compiler.resolve(Compiler.java:6710)
        at clojure.lang.Compiler.analyzeSymbol(Compiler.java:6671)
        at clojure.lang.Compiler.analyze(Compiler.java:6244)
        ... 60 more
Subprocess failed

Since I am new to Noir (and Clojure), I am at a loss trying to figure this out


Source: (StackOverflow)

How to get JSON post data in Noir

A while back, Chris Granger posted this middleware to get JSON hashes to appear in the defpage params under an umbrella "backbone" element.

(defn backbone [handler]
  (fn [req]
    (let [neue (if (= "application/json" (get-in req [:headers "content-type"]))
       (update-in req [:params] assoc :backbone (json/parse-string (slurp (:body req)) true))
       req)]
    (handler neue))))

How could I modify this code to have the JSON elements appear as top-level params in defpage; i.e. get rid of the :backbone umbrella?


Source: (StackOverflow)

passing data to noir views - Clojure

I'm working with Noir and I can't figure out how to pass information to the views. Right now I have a ref in proj.core/my-ref which is updated in a worker thread. I need to access the ref's value from a view created via defpage located at proj.views.my-view.

What would be the idiomatic way of sharing this ref? I was thinking of passing it in a closure somehow but I don't see how that would work with the way noir pulls in the views

ie

(noir.server/load-views-ns 'proj.views)

Source: (StackOverflow)

Webnoir website as Eclipse project, resources can't be found

I have this webnoir webapp as an Eclipse project. You can download it here: http://dl.dropbox.com/u/3914693/practicum5.zip

When I start it up, using the -main function from Eclipse, the resources folder doesn't seem to be found (I get a 404 on /css/tictactoe.css). What do I change to make it work?


Source: (StackOverflow)

'jQuery' type function for manipulating clojure maps

Is there a jQuery type function to solve the problem of walking through nested maps?

for example, if i have a configuration that looks like this:

  (def fig
    {:config
      {:example
        {:a "a"
         :b "b"
         :c "c"}
       :more
        {:a "a"
         :b "b"
         :c "c"}}})

I still haven't figured out a great way to manipulate nested persistent data structures with assoc and dissoc. However, if there was a jquery style way to manipulate maps, then I can write code like this:

  (->  fig
    ($ [:config :example :a] #(str % "a"))
    ($ [:config :b] #(str % "b")))

  Giving this output:

  {:config
    {:example
      {:a "aa"
       :b "bb"
       :c "c"}
     :more
      {:a "a"
       :b "bb"
       :c "c"}}}

And something like this for selectors:

($ fig [:config :example :a])
  ;=> "a"

($ fig [:config :b])
  ;=> {[:config :example :b] "b", 
  ;    [:config :more :b] "b"}

So in essence, I'm looking for an implementation of jayq for manipulation of clojure objects instead of html doms.

Thanks in advance!


Source: (StackOverflow)

How to get HttpServletRequest in a Ring handler?

Is there a way to get the HttpServletRequest object in a Ring handler? I am using Noir to develope a web app. I need to get the HttpServletRequest obj when handling a URI. So I use the (noir.request.ring-request) function to get back the ring request map which contains :servlet-request key, but the value is nil. Is this the right way to do it or do I miss something?

following is the code:

(ns my-app
     (:use noir.request))
(defpage [:get "/app"] []
     (str (ring-request)))

the result:

{:remote-addr "127.0.0.1", :scheme :http, :query-params {}, :session {}, :form-params {}, :multipart-params {}, :servlet #, :request-method :get, :query-string nil, :content-type nil, :cookies {"ring-session" {:value "eb509a65-d33a-40d2-9646-e2ff785428b0"}}, :uri "/app", :server-name "127.0.0.1", :params {}, :headers {"cookie" "ring-session=eb509a65-d33a-40d2-9646-e2ff785428b0", "accept-charset" "GBK,utf-8;q=0.7,*;q=0.3", "accept-language" "en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4", "accept-encoding" "gzip,deflate,sdch", "accept" "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "user-agent" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2", "connection" "keep-alive", "host" "127.0.0.1:8080"}, :servlet-request #, :content-length nil, :server-port 8080, :character-encoding nil, :servlet-response #, :body #, :servlet-context #}

Source: (StackOverflow)

Clojure Noir Json Put

I'm working through the tutorial Mark McGranaghan REST Tutorial however I'm trying to do it using Noir instead.

I can add new items, however it never takes the body of the PUT command.

I think the problem with how I'm trying to construct the put statement. I'm thinking the {:keys [id attrs]} is the issue, because I'm trying to tell it the json content is in the url, when its not, its in the body. Can anyone advise how i retrieve it from the body using noirs defpage?

(put is in a separate elem file)

(defn put [id attrs]
  (let [new-attrs (merge (get id) attrs)]
  (swap! elems assoc id new-attrs)
  new-attrs))

(defpage [:put "/elems/:id"] {:keys [id attrs]}
  (json-response (elem/put id attrs)))

Source: (StackOverflow)

404s when deploying a noir war to jetty on squeeze

I have a feeling I've missed something obvious here, but I don't know where to start looking.

I have a fresh noir app, created thusly:

$ lein noir new hiworld

I add a new page handler to src/hiworld/server.clj:

(ns hiworld.server
  (:require [noir.server :as server]))
(server/load-views "src/hiworld/views/")

(def handler (server/gen-handler {:mode :dev
                                  :ns 'hiworld}))

I set project.clj up for ring:

(defproject hiworld "0.1.0-SNAPSHOT"
            :description "FIXME: write this!"
            :dependencies [[org.clojure/clojure "1.3.0"]
                           [noir "1.2.2-SNAPSHOT"]]
            :dev-dependencies [[lein-ring "0.5.4"]]
            :ring {:handler hiworld.server/handler}
            :main hiworld.server)

Check it works locally:

$ lein deps
$ lein ring server-headless
# elsewhere
$ curl -I localhost:3000/welcome
HTTP/1.1 200 OK
Date: Mon, 20 Feb 2012 08:51:15 GMT
Set-Cookie: ring-session=ef00a7ad-2061-4026-9d94-3ed86ec8c46c;Path=/
Content-Type: text/html; charset=utf-8
Content-Length: 0
Server: Jetty(6.1.25)

I build a war:

$ lein ring uberwar
# builds hiworld-0.1.0-SNAPSHOT-standalone.war

All good so far. Now, I deploy it to jetty:

$ sudo apt-get install jetty libjetty-extra
$ sudo cp hiworld-0.1.0-SNAPSHOT-standalone.war /usr/share/jetty/webapps/root.war
$ sudo chown jetty:adm /usr/share/jetty/webapps/root.war
$ sudo mv /usr/share/jetty/webapps/root /usr/share/jetty/webapps/root-orig
$ sudo /etc/init.d/jetty restart

But:

$ curl -I localhost:8080/welcome
HTTP/1.1 404 Not Found
Date: Mon, 20 Feb 2012 08:59:27 GMT
Set-Cookie: ring-session=c255da15-6cbd-4d2c-8e17-9d120918bde9;Path=/
Content-Type: text/html; charset=utf-8
Content-Length: 363
Server: Jetty(6.1.24)

What did I miss? As far as I can tell, that should be all I need to do to deploy a trivial web-app to jetty, but evidently I've got something wrong here. I don't mind the restart, so I don't think I need to define my own context - or do I?

UPDATE

I've followed this sequence of instructions to create a simple "hello world" war not involving clojure at all, and it works as expected, so it would appear that there's something Not Quite Right with the clojure stack.

UPDATED AGAIN

I created the simplest possible ring app as a standalone war and deployed it. This worked, so it looks like it's something noir-specific.

UPDATED A THIRD TIME

I created and deployed a hello-world compojure app, which worked as expected.


Source: (StackOverflow)

Noir and Lein under Eclipse

I am trying to use CCW + lein for clojure devl. I built a small Noir app which has page for / with command line lein run , I am able to see the output at localhost

But how to run within CCW + Lein under eclipse , I press Run , and then open the browser , it is not working .. ? What's the problem ? How to debug within Eclipse the web app. ie test whether the server is running , any other web related debugging ? Thanks Sunil


Source: (StackOverflow)

Get the host address programmatically in webnoir

I'm developing a Clojure webnoir app and I need to construct a callback url (for Twitter oauth) that is different in dev-mode than it is in production mode. In dev-mode it needs to be localhost:8080/smth and on production (heroku) obviously something else like http://smooth-lightning-xxxx.herokuapp.com/smth. How do I get the localhost:8080 part programmatically in a defpage?


Source: (StackOverflow)