Skip to content

Instantly share code, notes, and snippets.

@paulosuzart
Created July 19, 2010 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulosuzart/480886 to your computer and use it in GitHub Desktop.
Save paulosuzart/480886 to your computer and use it in GitHub Desktop.
; Starts an JTornado HTTP Server and a sample RequestHandler.
; Bit verbose due to compilation directives. Recommendation is to generate
; a set of macros to hide this.
(ns org.ctornadoweb
; Compiled and implements a static main method to start the server
(:import (org.jtornadoweb HttpServer)
(org.jtornadoweb.Web$Application)
(org.jtornadoweb.Web$RequestHandler))
(:gen-class :prefix "server-"))
(gen-class
:name org.ctornadoweb.MyHandler
:extends org.jtornadoweb.Web$RequestHandler
:prefix "do-")
(defn do-get [this]
"Handles the HTTP GET method"
(.write "hello clojure"))
(defn do-post [this]
"Handles the HTTP POST method"
(.write (.getArgument "name" "default" false)))
(defn server-main []
"main method"
(.listen
(org.jtornadoweb.HttpServer.
(.add (org.jtornadoweb.Web$Application.) "/" org.ctornadoweb.MyHandler)
false nil false) 8089))
;use (compile 'org.ctornadoweb)
@paulosuzart
Copy link
Author

The server still performs super.get(), what causes an error.

@kotarak
Copy link

kotarak commented Jul 20, 2010

Include the hyphen in the do prefix: do-.

@paulosuzart
Copy link
Author

oh god! worked. Thanks

@felipecruz
Copy link

I'm not a clojure fan.. but JTornado is nice!

@paulosuzart
Copy link
Author

Hi Felipe. We are working hard to release the first stable version of JTornado. The idea is to kill all bureaucracy for Java on the Web. We still have the plan to rearrange the webframework (primarily written for java) to better fit other VM Languages like Groovy, Scala and Clojure.
Thanks.

@felipecruz
Copy link

Sure.. i wrote about that last year.. http://www.loogica.net/blog/2009/11/04/java-para-web-sem-servlets/ but my framework works with Jetty.. but JTornado is even better because it's (even) small (than jetty) and lightweight.. and combined with something like freemarker and some lightweight persistence framework can provide a very performatic, small yet powerfull solution to put java websites with minimum effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment