Skip to content

Instantly share code, notes, and snippets.

@smartrevolution
Created June 2, 2010 07:37
Show Gist options
  • Save smartrevolution/422066 to your computer and use it in GitHub Desktop.
Save smartrevolution/422066 to your computer and use it in GitHub Desktop.
;taken from clj-gae-datastore/src/example/clojure/com/freiheit/gae/datastore/example.clj
; short-cut to set-up the GAE environment for interactive programming with Clojure and GAE
(ns com.freiheit.gae.datastore.example
(:use
[clojure.contrib def])
(:import
[com.google.apphosting.api ApiProxy ApiProxy$Environment]
[java.io File]
[java.util HashMap]
[com.google.appengine.tools.development ApiProxyLocalFactory ApiProxyLocalImpl LocalServiceContext LocalServerEnvironment]
[com.google.appengine.api.labs.taskqueue.dev LocalTaskQueue]))
(defn init-app-engine
"Initialize the app engine services. Call it once from the REPL"
([]
(init-app-engine "/tmp"))
([dir]
(let [default-port 9090
env-proxy (proxy [ApiProxy$Environment] []
(isLoggedIn [] false)
(getRequestNamespace [] "")
(getDefaultNamespace [] "")
(getAttributes [] (let [attributes (HashMap.)
local-server-url (str "http://localhost:" default-port)]
(.put attributes "com.google.appengine.server_url_key" local-server-url)
attributes))
(getAppId [] "local"))
local-env (proxy [LocalServerEnvironment] []
(getAppDir [] (File. dir))
(getAddress [] "localhost")
(getPort [] default-port)
(waitForServerToStart [] nil))
api-proxy (.create (ApiProxyLocalFactory.) local-env)]
(do
(com.google.apphosting.api.ApiProxy/setEnvironmentForCurrentThread env-proxy)
(com.google.apphosting.api.ApiProxy/setDelegate api-proxy)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment