[Opensrf-commits] r2058 - in trunk: . examples (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Nov 8 20:59:04 EST 2010
Author: dbs
Date: 2010-11-08 20:59:03 -0500 (Mon, 08 Nov 2010)
New Revision: 2058
Added:
trunk/examples/simple_text.py.in
trunk/examples/simple_text_curl.sh
Modified:
trunk/configure.ac
Log:
Add a Python and curl example of invoking the Perl simpletext services
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2010-11-09 01:57:38 UTC (rev 2057)
+++ trunk/configure.ac 2010-11-09 01:59:03 UTC (rev 2058)
@@ -263,6 +263,7 @@
AC_PYTHON_MOD([setuptools])
AC_CONFIG_FILES([
examples/math_client.py
+ examples/simple_text.py
src/python/Makefile
])
fi
Added: trunk/examples/simple_text.py.in
===================================================================
--- trunk/examples/simple_text.py.in (rev 0)
+++ trunk/examples/simple_text.py.in 2010-11-09 01:59:03 UTC (rev 2058)
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+import osrf.system
+import osrf.ses
+
+# XXX: Replace with command line arguments
+file = '@CONF_DIR@/conf/opensrf_core.xml'
+method = 'opensrf.simple-text.reverse'
+text = 'raboof'
+
+# Pull connection settings from <config><opensrf> section of opensrf_core.xml
+osrf.system.System.connect(config_file=file, config_context='config.opensrf')
+
+# Set up a connection to the opensrf.math service
+session = osrf.ses.ClientSession('opensrf.simple-text')
+
+# Call one of the methods defined by the opensrf.math service
+request = session.request(method, text)
+
+# Retrieve the response from the method
+response = request.recv(timeout=2)
+
+print(response.content())
+
+# Cleanup request and connection resources
+request.cleanup()
+session.cleanup()
Added: trunk/examples/simple_text_curl.sh
===================================================================
--- trunk/examples/simple_text_curl.sh (rev 0)
+++ trunk/examples/simple_text_curl.sh 2010-11-09 01:59:03 UTC (rev 2058)
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# Simple demonstration of invoking a public OpenSRF method via curl
+
+# Expected output will be something like:
+# [{"__c":"osrfMessage","__p":{"threadTrace":"0","locale":"en-CA","type":"RESULT","payload":{"__c":"osrfResult","__p":{"status":"OK","statusCode":"200","content":4}}}},{"__c":"osrfMessage","__p":{"threadTrace":"0","locale":"en-CA","type":"STATUS","payload":{"__c":"osrfConnectStatus","__p":{"status":"Request Complete","statusCode":"205"}}}}]
+
+#curl -H "X-OpenSRF-service: opensrf.simple-text" --data 'osrf-msg=[{"__c":"osrfMessage","__p":{"threadTrace":0,"type":"REQUEST","payload":{"__c":"osrfMethod","__p":{"method":"opensrf.simple-text.reverse","params":["foobar"]}},"locale":"en-CA"}}]' http://localhost/osrf-http-translator
+curl -H "X-OpenSRF-service: opensrf.simple-text" --data 'osrf-msg=[{"__c":"osrfMessage","__p":{"threadTrace":0,"type":"REQUEST","payload":{"__c":"osrfMethod","__p":{"method":"opensrf.simple-text.split","params":["This is a test, it%27s only a test"]}},"locale":"en-CA"}}]' http://localhost/osrf-http-translator
+#curl -H "X-OpenSRF-service: opensrf.simple-text" --data 'osrf-msg=[{"__c":"osrfMessage","__p":{"threadTrace":0,"type":"REQUEST","payload":{"__c":"osrfMethod","__p":{"method":"opensrf.simple-text.substring","params":["foobar", 3, 1]}},"locale":"en-CA"}}]' http://localhost/osrf-http-translator
More information about the opensrf-commits
mailing list