built an opensrf http translator proxy for paster so mod_python is not required for...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 3 Apr 2008 03:26:49 +0000 (03:26 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 3 Apr 2008 03:26:49 +0000 (03:26 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9205 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/oilsweb/development.ini
Open-ILS/web/oilsweb/oilsweb/config/routing.py
Open-ILS/web/oilsweb/oilsweb/controllers/translator.py [new file with mode: 0644]

index f95da19..671e864 100644 (file)
@@ -67,6 +67,11 @@ local_templates = /openils/var/web/oilsweb/oilsweb/local_templates
 #oils_demo_workstation = BR1-demo
 
 
+# when using the opensrf translator proxy, define the 
+# translator host and path here
+#osrf_http_translator_host = localhost:80
+#osrf_http_translator_path = /osrf-http-translator
+
 
 
 # Logging configuration
index 6d1b4cc..516b694 100644 (file)
@@ -27,6 +27,7 @@ def make_map():
     map.connect(prefix+'admin/:action/:type/:id', controller='admin')
     map.connect(prefix+'admin/:action/:type', controller='admin')
 
+    map.connect('osrf-http-translator', controller='translator', action='proxy')
 
     ''' trying a different set of admin routes above...
     map.connect('acq_admin', 'oils/admin', controller='acq_admin')
diff --git a/Open-ILS/web/oilsweb/oilsweb/controllers/translator.py b/Open-ILS/web/oilsweb/oilsweb/controllers/translator.py
new file mode 100644 (file)
index 0000000..0df6a55
--- /dev/null
@@ -0,0 +1,24 @@
+from oilsweb.lib.base import *
+import urllib2, urllib, httplib
+import osrf.json
+import pylons
+
+class TranslatorController(BaseController):
+    ''' This controller acts as a proxy for the OpenSRF http translator
+        so that paster can handle opensrf AJAX requests. '''
+    def proxy(self):
+        try:
+            headers = {}
+            for k,v in request.headers.iteritems():
+                headers[k] = v
+            conn = httplib.HTTPConnection(pylons.config['osrf_http_translator_host'])
+            conn.request("POST", pylons.config['osrf_http_translator_path'], 
+                urllib.urlencode({'osrf-msg':request.params['osrf-msg']}), headers)
+            resp = conn.getresponse()
+            for h in resp.getheaders():
+                response.headers[h[0]] = h[1]
+            return resp.read()
+        except Exception, e:
+            import sys
+            sys.stderr.write(unicode(e) + '\n')
+