possible to get a ring handler

344 views
Skip to first unread message

Mark Rathwell

unread,
Aug 9, 2011, 9:26:27 PM8/9/11
to clj-...@googlegroups.com

Is there a straightforward way to get a ring handler for a noir app?  I'm specifically trying to figure out if it is realistic to use noir with appengine-magic, which requires a ring handler.  Thanks.

  - Mark

Chris Granger

unread,
Aug 9, 2011, 9:33:38 PM8/9/11
to clj-...@googlegroups.com
Take a look at the Using Noir with other libraries tutorial: http://webnoir.org/tutorials/others

With appengine, however, I think there will likely need to be a lot of changes. Appengine is incredibly restrictive and I think I use things that aren't "allowed."

Not a "solution" per se, but heroku and elastic beanstalk are both free and noir works out of the box with those.

Cheers,
Chris.

Mark Rathwell

unread,
Aug 9, 2011, 9:39:43 PM8/9/11
to clj-...@googlegroups.com

I didn't see anything at a quick glance that will cause problems with appengine, but I'd like to test it out.  So, (noir.server/gen-handler returns a ring handler?

Andy Brown

unread,
Aug 9, 2011, 9:53:01 PM8/9/11
to clj-...@googlegroups.com
I was playing with noir and app engine over the weekend and you can get a handler using noir.server/gen-handler however you will find Google App Engine does not like some of what is in noir.server (and probably elsewhere) and will crash. 


I did not really get to test any of my theories since I went down a bit of a rabbit hole with lien and local maven repositories after that but I will push my experiments to github when and if I figure anything out (maybe next weekend)


I'm all in with app engine so I would love to hear more about any progress made with noir and appengine-magic and I'll be sure to email the group if I make any real progress.

- Andy

Mark Rathwell

unread,
Aug 9, 2011, 10:30:35 PM8/9/11
to clj-...@googlegroups.com
Yeah, load-views is going to cause problems.  I've not been able to use java.io.File at all without crashes.  I'll try to find some time to look into it further this week.  

Not married to app engine, but it makes life a whole lot easier when you're doing this stuff on the side.  Noir (and noir-cljs and pinot) is looking pretty sweet also, especially the ClojureScript integration.

Chris Granger

unread,
Aug 9, 2011, 11:08:14 PM8/9/11
to clj-...@googlegroups.com
Hey guys,

I'll look into it, is there a really quick way to check if something works? Or do I need to signup for an app-engine account and actually push things up?

Cheers,
Chris.

Andy Brown

unread,
Aug 9, 2011, 11:23:34 PM8/9/11
to clj-...@googlegroups.com
You don't need an app engine account.

Download the java dev environment for gae here:
http://code.google.com/appengine/downloads.html

and the follow the getting started steps here: 


They are pretty complete and will get you started about as quickly as possible.  There is also a lein plugin to generate a skeleton project.

Let me know if you run into any issues.

Andy

Mark Rathwell

unread,
Aug 9, 2011, 11:55:51 PM8/9/11
to clj-...@googlegroups.com

The dev appserver is a good approximation of the live environment, but does not guarantee that if it works in dev appserver it will work in live app engine.  I don't have a problem testing any changes you make in the live app engine environment if you just want to test with the dev appserver.

The big lockdown areas with app engine are files, threads, and network requests.  Resources (via clojure.java.io/resource (:only)) are okay, and thereby java.net.URL.  java.io.File always seems to crash, or even just 'use'-ing clojure.java.io without :only.  

In the appengine-magic 'Getting Started' section in the readme, you really only need to do the 'Project Setup' and 'Development Process' sub-sections (modifying to use gen-handler and load-views and defpage, etc. of course)

Again, let me know if I can help in any way, or if you need me to test in live GAE.

 - Mark

Andy Brown

unread,
Aug 9, 2011, 11:57:17 PM8/9/11
to clj-...@googlegroups.com
FYI, This is kind of stack trace you get when you try and :use noir.server with a google app engine project.

noir.core does not actually give you an error from just doing :use noir.core however you are stuck since you can't easily get at the ring handler without noir.server


App engine does not like it when something messes with threads apparently...

- Andy

Mark Rathwell

unread,
Aug 10, 2011, 5:56:25 PM8/10/11
to clj-...@googlegroups.com
So, here's where I'm at...with some very minor modifications to noir [1], I can get down to ring issues.  The current issue that I can't get past is:

noir.server/gen-handler calls noir.server/init-routes, which calls compojure.handler/site, which adds the multipart-params ring middleware.  This middleware uses the blacklisted class java.rmi.server.UID.  For this reason, appengine-magic already has a replacement in appengine-magic.multipart-params/wrap-multipart-params.

Fixing this would require, minimally, offering another way to get a ring handler that does not call compojure.handler/site, and maybe that added the relevant default middlewares other than multipart-params, and let the user add that from appengine-magic.

Not sure how to proceed, is this a realistic path to pursue?  What are your thoughts?

[1] gist of modified noir.server: https://gist.github.com/1138348
     basically, just modified the 'use' of clojure.java.io and clojure.tools.namespace to :only the used functions and 'require'd ring.adapter.jetty

Chris Granger

unread,
Aug 10, 2011, 6:09:53 PM8/10/11
to clj-...@googlegroups.com
I think what I'm going to do is move some of server out of server.clj and put into server/handler.clj (new). From there we can create an appengine util that builds up an appengine compliant stack of middleware using server.handler. Sound reasonable?

That separation is on my plate for tonight, if I do that, I think we can make this work.

Cheers,
Chris.

Mark Rathwell

unread,
Aug 10, 2011, 6:53:55 PM8/10/11
to clj-...@googlegroups.com
Sounds great!  Let me know when you want me to start testing it out.

 - Mark

Chris Granger

unread,
Aug 11, 2011, 12:42:46 AM8/11/11
to clj-...@googlegroups.com
So I've done this, but I can't seem to get the appengine stuff to work. Wanna try it? :)

[noir "1.1.1-SNAPSHOT"]

Relevant file:

Mark Rathwell

unread,
Aug 11, 2011, 12:21:29 PM8/11/11
to clj-...@googlegroups.com
My simple tests are working fine on app engine.  I've got my code pasted below in case anyone may find it useful getting started.  Thanks a lot for this, Chris!

;; ** names changed to protect the innocent **

;;--- project.clj ---  

(defproject test-site "1.0.0"
  :description "Noir / App Engine Test Website"
  :dependencies [[org.clojure/clojure "1.2.1"]
                 [org.clojure/clojure-contrib "1.2.0"]
[noir "1.1.1-SNAPSHOT"]]
  :dev-dependencies [[swank-clojure "1.2.1"]
    [appengine-magic "0.4.3"]
    [lein-ring "0.4.3"]]
  :appengine-app-versions {"test-appengine-site-dev" "2"
                           "test-appengine-site-stage" "2"
                           "test-appengine-site-production" "2"}
  :appengine-sdk {"me" "/Users/me/Devel/appengine-java-sdk-1.5.2"
                  "billybob" "/Users/billybob/Devel"})


;;--- app_servlet.clj (appengine-magic default name) ---

(ns test-site.app_servlet
  (:gen-class :extends javax.servlet.http.HttpServlet)
  (:use test-site.core)
  (:use [appengine-magic.servlet :only [make-servlet-service-method]]))

(defn -service [this request response]
  ((make-servlet-service-method test-site-gae) this request response))


;;--- core.clj (appengine-magic default name) ---

(ns test-site.core
  (:require [appengine-magic.core :as gae]
   [noir.util.gae :as noir]))

;; load all of the routes (defpage's) so they get def'd
(require 'test-site.routes)

;; def the appengine app
(gae/def-appengine-app test-site-gae (noir/gae-handler nil))


;;--- routes.clj (where defpage's are currently going) ---

(ns test-site.routes
  (:use [noir.core :only (defpage defpartial)])
  (:require [noir.response :as resp]))

(defpartial greeting [fname lname]
  [:h1 "Hello, " fname " " lname])

(defpage "/" []
  (resp/redirect "/welcome"))

(defpage "/welcome" []
  "Welcome to the Noir/App Engine test!")

(defpage "/test" {:keys [fname lname]}
  (greeting fname lname))

Andy Brown

unread,
Aug 11, 2011, 12:34:48 PM8/11/11
to clj-...@googlegroups.com
Working over here as well - though I have only tested it locally. Thanks for working on this Chris. (And mark for the example code)

- Andy

Chris Granger

unread,
Aug 11, 2011, 2:20:21 PM8/11/11
to clj-...@googlegroups.com
Awesome. If one of you guys end up writing a blog post about the experience, I'd love to put it up on webnoir.org as an example. Also if you end up with more general utility stuff I'd happily take patches for noir.util.gae. Only caveat is that I don't want to take a hard dependency on appengine magic because of how big it is.

Cheers,
Chris.

Mark Rathwell

unread,
Aug 11, 2011, 3:05:36 PM8/11/11
to clj-...@googlegroups.com
I will try to get a starter app, which is a *little* more complete than my little test, into a github repo, with a quick overview readme.  If people feel like more is necessary, I could possibly also add a wiki page on getting started with appengine-magic to noir's github repo.

 - Mark

semperos

unread,
Aug 11, 2011, 11:07:10 PM8/11/11
to clj-...@googlegroups.com
+1 for more wiki pages ;)

Great work on expanding Noir's reach!

Chris Granger

unread,
Aug 12, 2011, 2:21:48 AM8/12/11
to clj-...@googlegroups.com
Mark,

Both of those would be great if you get to them :)

Cheers,
Chris.

Jimmy

unread,
Aug 13, 2011, 12:10:16 PM8/13/11
to clj-noir
Tried it locally and it works great. Has any one tried to get it work
with eclipse and CCW?
thanks,
Jimmy
> >https://github.com/ibdknox/noir/commit/fe065938142a55cc9dc3d02b10b859...
>
> > Cheers,
> > Chris.
>
> > On Wed, Aug 10, 2011 at 3:53 PM, Mark Rathwell <mark.rathw...@gmail.com>wrote:
>
> >> Sounds great!  Let me know when you want me to start testing it out.
>
> >>  - Mark
>
> >> On Wed, Aug 10, 2011 at 6:09 PM, Chris Granger <ibdk...@gmail.com> wrote:
>
> >>> I think what I'm going to do is move some of server out of server.clj and
> >>> put into server/handler.clj (new). From there we can create an appengine
> >>> util that builds up an appengine compliant stack of middleware using
> >>> server.handler. Sound reasonable?
>
> >>> That separation is on my plate for tonight, if I do that, I think we can
> >>> make this work.
>
> >>> Cheers,
> >>> Chris.
>
> >>> On Wed, Aug 10, 2011 at 2:56 PM, Mark Rathwell <mark.rathw...@gmail.com>wrote:
>
> >>>> So, here's where I'm at...with some very minor modifications to noir
> >>>> [1], I can get down to ring issues.  The current issue that I can't get past
> >>>> is:
>
> >>>> noir.server/gen-handler calls noir.server/init-routes, which calls
> >>>> compojure.handler/site, which adds the multipart-params ring middleware.
> >>>>  This middleware uses the blacklisted class java.rmi.server.UID.  For this
> >>>> reason, appengine-magic already has a replacement in
> >>>> appengine-magic.multipart-params/wrap-multipart-params.
>
> >>>> Fixing this would require, minimally, offering another way to get a ring
> >>>> handler that does not call compojure.handler/site, and maybe that added the
> >>>> relevant default middlewares other than multipart-params, and let the user
> >>>> add that from appengine-magic.
>
> >>>> Not sure how to proceed, is this a realistic path to pursue?  What are
> >>>> your thoughts?
>
> >>>> [1] gist of modified noir.server:https://gist.github.com/1138348
> >>>>      basically, just modified the 'use' of clojure.java.io and
> >>>> clojure.tools.namespace to :only the used functions and 'require'd
> >>>> ring.adapter.jetty
>
> >>>> On Tue, Aug 9, 2011 at 11:57 PM, Andy Brown <andy...@gmail.com> wrote:
>
> >>>>> FYI, This is kind of stack trace you get when you try and :use
> >>>>> noir.server with a google app engine project.
>
> >>>>> noir.core does not actually give you an error from just doing :use
> >>>>> noir.core however you are stuck since you can't easily get at the ring
> >>>>> handler without noir.server
>
> >>>>>http://pastebin.com/1hUkZeQw
>
> >>>>> App engine does not like it when something messes with threads
> >>>>> apparently...
>
> >>>>> - Andy
>
> >>>>> On Tue, Aug 9, 2011 at 8:23 PM, Andy Brown <andy...@gmail.com> wrote:
>
> >>>>>> You don't need an app engine account.
>
> >>>>>> Download the java dev environment for gae here:
> >>>>>>http://code.google.com/appengine/downloads.html
>
> >>>>>> and the follow the getting started steps here:
>
> >>>>>>https://github.com/gcv/appengine-magic
>
> >>>>>> They are pretty complete and will get you started about as quickly as
> >>>>>> possible.  There is also a lein plugin to generate a skeleton project.
>
> >>>>>> Let me know if you run into any issues.
>
> >>>>>> Andy
>
> >>>>>> On Aug 9, 2011, at 8:08 PM, Chris Granger <ibdk...@gmail.com> wrote:
>
> >>>>>> Hey guys,
>
> >>>>>> I'll look into it, is there a really quick way to check if something
> >>>>>> works? Or do I need to signup for an app-engine account and actually push
> >>>>>> things up?
>
> >>>>>> Cheers,
> >>>>>> Chris.
>
> >>>>>> On Tue, Aug 9, 2011 at 7:30 PM, Mark Rathwell <
> >>>>>> mark.rathw...@gmail.com> wrote:
>
> >>>>>>> Yeah, load-views is going to cause problems.  I've not been able to
> >>>>>>> use java.io.File at all without crashes.  I'll try to find some time to look
> >>>>>>> into it further this week.
>
> >>>>>>> Not married to app engine, but it makes life a whole lot easier when
> >>>>>>> you're doing this stuff on the side.  Noir (and noir-cljs and pinot) is
> >>>>>>> looking pretty sweet also, especially the ClojureScript integration.
>
> >>>>>>> On Tue, Aug 9, 2011 at 9:53 PM, Andy Brown <andy...@gmail.com>wrote:
>
> >>>>>>>> I was playing with noir and app engine over the weekend and you can
> >>>>>>>> get a handler using noir.server/gen-handler however you will find Google App
> >>>>>>>> Engine does not like some of what is in noir.server (and probably elsewhere)
> >>>>>>>> and will crash.
>
> >>>>>>>> Likely it's
> >>>>>>>>https://github.com/ibdknox/noir/blob/master/src/noir/server.clj#L4
> >>>>>>>> and
> >>>>>>>>https://github.com/ibdknox/noir/blob/master/src/noir/server.clj#L66
>
> >>>>>>>> I did not really get to test any of my theories since I went down a
> >>>>>>>> bit of a rabbit hole with lien and local maven repositories after that but I
> >>>>>>>> will push my experiments to github when and if I figure anything out (maybe
> >>>>>>>> next weekend)
>
> >>>>>>>>https://github.com/andymoe/noir/tree/gae-patch
>
> >>>>>>>> I'm all in with app engine so I would love to hear more about any
> >>>>>>>> progress made with noir and appengine-magic and I'll be sure to email the
> >>>>>>>> group if I make any real progress.
>
> >>>>>>>> - Andy
>

Chris Granger

unread,
Aug 13, 2011, 2:52:19 PM8/13/11
to clj-...@googlegroups.com
Hey Jimmy,

Someone created a CCW/Eclipse template project here: https://github.com/yogthos/Noir-Eclipse-Template-Project you can probably just copy the .project and .classpath files out of it.

Cheers,
Chris.
Reply all
Reply to author
Forward
0 new messages