From 8d57de0db637fa7c011ae9c4bc7a0e6300ec826b Mon Sep 17 00:00:00 2001 From: dbs Date: Tue, 9 Nov 2010 01:59:03 +0000 Subject: [PATCH] Add a Python and curl example of invoking the Perl simpletext services git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@2058 9efc2488-bf62-4759-914b-345cdb29e865 --- configure.ac | 1 + examples/simple_text.py.in | 26 ++++++++++++++++++++++++++ examples/simple_text_curl.sh | 10 ++++++++++ 3 files changed, 37 insertions(+) create mode 100644 examples/simple_text.py.in create mode 100644 examples/simple_text_curl.sh diff --git a/configure.ac b/configure.ac index 89558d3..7418c82 100644 --- a/configure.ac +++ b/configure.ac @@ -263,6 +263,7 @@ if test x$OSRF_INSTALL_PYTHON = xtrue; then AC_PYTHON_MOD([setuptools]) AC_CONFIG_FILES([ examples/math_client.py + examples/simple_text.py src/python/Makefile ]) fi diff --git a/examples/simple_text.py.in b/examples/simple_text.py.in new file mode 100644 index 0000000..2319e03 --- /dev/null +++ b/examples/simple_text.py.in @@ -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 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() diff --git a/examples/simple_text_curl.sh b/examples/simple_text_curl.sh new file mode 100644 index 0000000..c5d9b49 --- /dev/null +++ b/examples/simple_text_curl.sh @@ -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 -- 2.11.0