2

I'm trying to make http requests from my Google App Engine webapp, and discovered I have to use URLConnection since it's the only whitelisted class. The corresponding Clojure library is clojure.contrib.http.agent, and my code is as follows:

(defroutes example
  (GET "/" [] (http/string (http/http-agent "http://www.example.com")))
  (route/not-found "Page not found"))

This works fine in my development environment- the browser displays the text for example.com. But when I test it out with Google's development app server:

phrygian:example wei$ dev_appserver.sh war
2010-09-28 14:53:36.120 java[43845:903] [Java CocoaComponent compatibility mode]: Enabled
...
INFO: The server is running at http://localhost:8080/

It just hangs when I load the page. No error, or anything. Any idea what might be going on?

yayitswei
  • 4,587
  • 5
  • 27
  • 34
  • 1
    Does `http-agent` create threads? My understanding is that App Engine doesn't like those. – ponzao Sep 28 '10 at 22:35
  • hmm good question. do you know if there's a non-threaded version of that? – yayitswei Sep 28 '10 at 23:58
  • You could try `http-connection` http://richhickey.github.com/clojure-contrib/http.connection-api.html, which seems to be quite a low-level wrapper around `HttpURLConnection`. Or just use `URLConnection`. I'll try to look at more options after lunch. – ponzao Sep 29 '10 at 09:13
  • I added my comments as a proper answer, it was getting out of hand. I also added a few more possibilities for you to look into. Didn't have time to test any of them though :( – ponzao Sep 30 '10 at 07:41

2 Answers2

3

http-agent creates threads so that might be why it does not work.

From the API documentation:

Creates (and immediately returns) an Agent representing an HTTP request running in a new thread.

You could try http-connection, which is a wrapper around HttpURLConnection, so this should work.

Another alternative is to try clj-http. The API seems to be a bit more high-level, but it uses Apache HttpComponents which might be blacklisted.

I am guessing http.async.client is a definite no-go due to its strong asynchronous approach.

ponzao
  • 20,684
  • 3
  • 41
  • 58
1

You might want to try appengine.urlfetch/fetch from appengine-clj (http://github.com/r0man/appengine-clj, also in clojars)

Miki Tebeka
  • 13,428
  • 4
  • 37
  • 49