Created
December 17, 2009 15:25
-
-
Save billdozr/258810 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns com.myapp.service.web | |
(:gen-class) | |
(:use [compojure] | |
[compojure.http response]) | |
(:import [org.springframework.web.context ContextLoaderListener] | |
[org.springframework.web.context.support | |
WebApplicationContextUtils] | |
[com.myapp.core.model Label])) | |
(defn test-create-label [request] | |
(do | |
(let [spring-ctx | |
(WebApplicationContextUtils/getWebApplicationContext | |
(request :servlet-context)) | |
label-dao (.getBean spring-ctx "labelDao") | |
new-label (doto (new Label) | |
(.setName "Label 1") | |
(.setDescription "testing"))] | |
(.create label-dao new-label) | |
(.read label-dao (.getId new-label))))) | |
(defn test-page [request] | |
(html [:html | |
[:head] | |
[:body | |
[:p "Test page."] | |
[:p "Label name: " (test-create-label request)]]])) | |
;; define routes | |
(defroutes webservice | |
(GET "/" | |
(test-page request)) | |
(ANY "*" | |
(page-not-found))) | |
(defn start-server [host port] | |
(defserver ws-server {:host host :port port} | |
"/*" (servlet webservice)) | |
(let [ctx (get-context ws-server)] | |
(doto ctx | |
(.setInitParams {"contextConfigLocation" | |
"classpath:/myapp-core-context.xml"}) | |
(.addEventListener (new ContextLoaderListener))) | |
(start ws-server))) | |
(defn -main [& args] | |
(start-server "127.0.0.1" 8080)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment