On 12/21/2008 12:18 PM, Adrian Cuthbertson wrote:
> 2.) Create your servlet "library" file as follows in say
> ./src/myapp/MyServlet.clj;
> (ns myapp.MyServlet
> (:use (compojure http html))
> (:import (java.io <http://java.io> PrintWriter)
> (javax.servlet.http HttpServlet HttpServletRequest
> HttpServletResponse Cookie))
> (:gen-class
> :extends javax.servlet.http.HttpServlet))
>
> (defservice "" ; nb "" here allows class name as myapp.MyServlet
> class from genclass
> (GET "/"
> (html [:h1 "Hello compojure World"])])
> (GET "/setC"
> [(Cookie. "my-cookie" "1234")
> (html [:p "Ok, cookie has been set"])])
> (GET "/getC"
> (str "cookie:" (:my-cookie cookies)))
> (ANY "*"
> [404 (html [:h1 "Page Not Found"])]))
>
Thanks for this bit. I missed the part where defservice could use a
gen-classes class name. I haven't tested it myself, but I'm sure that'll
make my job so much easier.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAklOrq0ACgkQWorbjR01Cx5+lQCeNBVLps/UEOcbCj+IUpwf4Vaa
NvgAn0inTTARSSGotJ8NGCaQDqsFVTlJ
=YNUm
-----END PGP SIGNATURE-----
Thanks, I was able to track down the problem.
On to the next challenge. :)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAklQVX4ACgkQWorbjR01Cx7x5ACcDpAd3le+tdhQkjUUP/uD/GGL
qsUAoKcG2IIdURPDY1Xhn30jteiq7SsP
=GhNp
-----END PGP SIGNATURE-----
It turns out it was a problem with the servlet mapping after all. I'm
not sure what changed, because I know I was able to see the paths
before. (I was echoing them to the screen) Perhaps I changed it when I
was trying to figure out a way to essentially replicate what you had
done with Compojure in a gen-classed setting.
Glad I don't have to do that.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAklQVucACgkQWorbjR01Cx6+LwCgvrEwwLiqQqh1rRxBDFT+a8Ex
FpUAoM0iSvMqeVnMg9MQ0ARqjl+Z6/lG
=CIhk
-----END PGP SIGNATURE-----
What might be a better option is to drop the "-" off the generated
"service" name. Also accept nil as using "-", that way you're
basically emulating what genclass does.
(defservice nil ...) => (defn -service ...)
(defservice "-" ...) => (defn -service ...)
(defservice "foo" ...) => (defn fooservice) ;; :prefix "foo"
(defservice "foo-" ...) => (defn foo-service) ;; :prefix "foo-"
This would be a minor breaking change, if "" no longer translates to
"-service". It probably shouldn't, anyway, because you might have
want/need to use prefixes that don't include a "-".
Works for me.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAklYGzAACgkQWorbjR01Cx5MSQCdFThY6isEPdUZMfWmdxEb9Xgu
R0YAoMFOanCIKyWgbnDk1jDBFAYX0VSM
=Q7CV
-----END PGP SIGNATURE-----