From: <bov...@us...> - 2007-10-31 23:09:01
|
Revision: 1422 http://pywebsvcs.svn.sourceforge.net/pywebsvcs/?rev=1422&view=rev Author: boverhof Date: 2007-10-31 16:09:04 -0700 (Wed, 31 Oct 2007) Log Message: ----------- A samples/WSGI A samples/WSGI/SimpleEcho.wsdl A samples/WSGI/echo_client.py AM samples/WSGI/echo_setup.py A samples/WSGI/echo_server.py A samples/WSGI/README M ZSI/twisted/wsgi.py -- Provide a sample for using WSGI with ZSI. Modified Paths: -------------- trunk/zsi/ZSI/twisted/wsgi.py Added Paths: ----------- trunk/zsi/samples/WSGI/ trunk/zsi/samples/WSGI/README trunk/zsi/samples/WSGI/SimpleEcho.wsdl trunk/zsi/samples/WSGI/echo_client.py trunk/zsi/samples/WSGI/echo_server.py trunk/zsi/samples/WSGI/echo_setup.py Modified: trunk/zsi/ZSI/twisted/wsgi.py =================================================================== --- trunk/zsi/ZSI/twisted/wsgi.py 2007-10-31 20:40:35 UTC (rev 1421) +++ trunk/zsi/ZSI/twisted/wsgi.py 2007-10-31 23:09:04 UTC (rev 1422) @@ -3,7 +3,7 @@ # See Copyright for copyright notice! # $Id: __init__.py 1132 2006-02-17 01:55:41Z boverhof $ ########################################################################### -import os, sys, types +import os, sys, types, inspect from StringIO import StringIO # twisted & related imports @@ -37,6 +37,7 @@ def main(): from wsgiref.simple_server import make_server, demo_app + from ZSI.twisted.wsgi import WSGIApplication application = WSGIApplication() httpd = make_server('', 8000, application) application['echo'] = EchoService() @@ -91,10 +92,8 @@ request = kw['request'] root = _get_element_nsuri_name(ps.body_root) - for key,method in resource.__dict__: - if (callable(method) and - getattr(method, 'soapmethod', False) and - method.root == root): + for key,method in inspect.getmembers(resource, inspect.ismethod): + if (getattr(method, 'soapmethod', False) and method.root == root): break else: raise RuntimeError, 'Missing soap callback method for root "%s"' %root @@ -183,7 +182,7 @@ class SOAPApplication(WSGIApplication): """ """ - factory = DefaultHandlerChainFactory + factory = SOAPHandlerChainFactory def __init__(self, **kw): dict.__init__(self, **kw) Added: trunk/zsi/samples/WSGI/README =================================================================== --- trunk/zsi/samples/WSGI/README (rev 0) +++ trunk/zsi/samples/WSGI/README 2007-10-31 23:09:04 UTC (rev 1422) @@ -0,0 +1,37 @@ +================== +WSGI Code is unstable, and currently server-side stubs are NOT generated for you. + + +================== + python wsgi example + run the SimpleEcho service out of python's wsgi + +================== + +% ./echo_setup.sh +% python echo_server.py >& server.log & +[1] 3455 +% python echo_client.py +INTEGER: 1 +STRING: HI +FLOAT: 1.1 +DICT: {'milk': {'cost': 3.1499999999999999, 'unit': 'gal'}} + + +================== + twisted.web2.wsgi example + run the SimpleEcho service out of twisted's web2 wsgi + +================== +% ./echo_setup.sh +% python echo_server.py twisted >& server.log & +[1] 3459 +% python echo_client.py +INTEGER: 1 +STRING: HI +FLOAT: 1.1 +DICT: {'milk': {'cost': 3.1499999999999999, 'unit': 'gal'}} + + + + Added: trunk/zsi/samples/WSGI/SimpleEcho.wsdl =================================================================== --- trunk/zsi/samples/WSGI/SimpleEcho.wsdl (rev 0) +++ trunk/zsi/samples/WSGI/SimpleEcho.wsdl 2007-10-31 23:09:04 UTC (rev 1422) @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<definitions + xmlns="http://schemas.xmlsoap.org/wsdl/" + xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" + xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" + xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:tns="urn:ZSI" + targetNamespace="urn:ZSI" > + <types> + <xsd:schema elementFormDefault="qualified" targetNamespace="urn:ZSI"> + <xsd:element name="Echo"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:anyType"/> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + </xsd:schema> + </types> + + <message name="EchoRequest"> + <part name="parameters" element="tns:Echo" /> + </message> + <message name="EchoResponse"> + <part name="parameters" element="tns:Echo"/> + </message> + + <portType name="EchoServer"> + <operation name="Echo"> + <input message="tns:EchoRequest"/> + <output message="tns:EchoResponse"/> + </operation> + </portType> + + <binding name="EchoServer" type="tns:EchoServer"> + <soap:binding style="document" + transport="http://schemas.xmlsoap.org/soap/http"/> + <operation name="Echo"> + <soap:operation soapAction="Echo"/> + <input> + <soap:body use="literal"/> + </input> + <output> + <soap:body use="literal"/> + </output> + </operation> + </binding> + + <service name="EchoServer"> + <port name="EchoServer" binding="tns:EchoServer"> + <soap:address location="http://localhost:7000"/> + </port> + </service> + +</definitions> Added: trunk/zsi/samples/WSGI/echo_client.py =================================================================== --- trunk/zsi/samples/WSGI/echo_client.py (rev 0) +++ trunk/zsi/samples/WSGI/echo_client.py 2007-10-31 23:09:04 UTC (rev 1422) @@ -0,0 +1,28 @@ +# +# +# + +from EchoServer_client import * +import sys, time + +TRACE=None +loc = EchoServerLocator() +port = loc.getEchoServer(url='http://localhost:8000/echo', tracefile=TRACE) + +msg = EchoRequest() +msg.Value = 1 +rsp = port.Echo(msg) +print "INTEGER: ", rsp.Value + +msg.Value = "HI" +rsp = port.Echo(msg) +print "STRING: ", rsp.Value + +msg.Value = 1.10000 +rsp = port.Echo(msg) +print "FLOAT: ", rsp.Value + + +msg.Value = dict(milk=dict(cost=3.15, unit="gal")) +rsp = port.Echo(msg) +print "DICT: ", rsp.Value Added: trunk/zsi/samples/WSGI/echo_server.py =================================================================== --- trunk/zsi/samples/WSGI/echo_server.py (rev 0) +++ trunk/zsi/samples/WSGI/echo_server.py 2007-10-31 23:09:04 UTC (rev 1422) @@ -0,0 +1,43 @@ +############################################################################ +# Joshua R. Boverhof, LBNL +# See Copyright for copyright notice! +# $Id: __init__.py 1132 2006-02-17 01:55:41Z boverhof $ +########################################################################### +import sys +from EchoServer_client import * +from ZSI.twisted.wsgi import SOAPApplication, soapmethod, SOAPHandlerChainFactory + +class EchoService(SOAPApplication): + factory = SOAPHandlerChainFactory + wsdl_content = dict(name='Echo', targetNamespace='urn:echo', imports=(), portType='') + + @soapmethod(EchoRequest.typecode, EchoResponse.typecode, operation='Echo', soapaction='Echo') + def soap_Echo(self, request, response, **kw): + response = request + return request,response + + +def main(): + from wsgiref.simple_server import make_server, demo_app + from ZSI.twisted.wsgi import WSGIApplication + application = WSGIApplication() + httpd = make_server('', 8000, application) + application['echo'] = EchoService() + httpd.serve_forever() + +def main_twisted(): + from ZSI.twisted.wsgi import test, WSGIApplication + app = WSGIApplication() + app['echo'] = EchoService() + test(app, port=8000) + +if __name__ == '__main__': + if len(sys.argv) == 1: + main() + else: + var = sys.argv[1] + try: + getattr(sys.modules[__name__], 'main_%s' %var)(*sys.argv[2:]) + except Exception, ex: + print>>sys.stderr, ex + sys.exit(1) Added: trunk/zsi/samples/WSGI/echo_setup.py =================================================================== --- trunk/zsi/samples/WSGI/echo_setup.py (rev 0) +++ trunk/zsi/samples/WSGI/echo_setup.py 2007-10-31 23:09:04 UTC (rev 1422) @@ -0,0 +1,2 @@ +#!/bin/sh +wsdl2py -b SimpleEcho.wsdl Property changes on: trunk/zsi/samples/WSGI/echo_setup.py ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |