TurboZSI is a plugin for the web framework TurboGears for creating and serving web services. It serves as a bridge between TurboGears and the python based web services modules, ZSI. It exposes the functionality of ZSI through several extensions to TurboGears and CherryPy. Some of these extensions include an additional "tg-admin" command, a SOAP filter for CherryPy, and base classes for top-down and bottom-up web service controllers.
User-centric documentation for ZSI is currently being written for the pending 2.0 release. ZSI is a mature API for working with WSDL, XMLSchema, and SOAP. Hence, TurboZSI has a similar focus of adhering to specification.
Note: TurboZSI is still in its infancy, so bugs may exist and support may be limited.
These instructions assume familiarity with Python and TurboGears. Python 2.4 is required.
- TurboZSI requires the preview version of TurboGears. If you run into problems running the following command, please refer to these instructions.
- easy_install -f http://www.turbogears.org/preview/download/ TurboGears
- Next simple install TurboZSI.
- easy_install -f http://sda.iu.edu/turbozsi/ TurboZSI
This section walks through a very simple example that will hopefully make the intended usage of TurboZSI more clear. The preferred approach for deploying web services is a top-down one. This sample is an instance of this. The other approach, bottom-up, will be discussed in a later section. We are going to create a TurboGears project which will implement an Echo service using this wsdl.
- Start a new TurboGears project. (choose all default options)
- Enter the project's directory.
- Use the "tg-admin wsdl2stubs" to create the client and server stubs for our service. The resulting files will be saved in the "echo/generated/" folder.
- tg-admin wsdl2stubs -u http://sda.iu.edu/turbozsi/Echo.wsdl
- Running the previous command should have generated the following files:
- "echo/generated/__init__.py" - An empty file for the module
"echo/generated/EchoServer_services.py" - The client classes
"echo/generated/EchoServer_services_server.py" - The base server controller class
"echo/generated/EchoServer_services_types.py" - Python type-mapping classes
- Implement the service logic. Copy and paste the following to a new file, "echo/echo_impl.py".
from turbozsi import wsexpose
from generated.EchoServer_services_server import EchoServer
def Echo(self, req, resp):
resp.EchoResult = req.EchoIn*3
- Add the service to the root controller. (add lines in bold to "echo/controllers.py")
from echo_impl import EchoImpl
log.debug("Happy TurboGears Controller Responding For Duty")
Echo = EchoImpl()
- That's it for the server side. Now start your app and the SOAP service will be served at "http://your-server:port/Echo/".
- For completeness sake, let's write a test that uses our generated client stubs to call our service. Leave the server running and follow these instructions in a new terminal. Copy and paste the following code to the new file, "echo/tests/test_echo.py".
from echo.generated.EchoServer_services import *
loc = EchoServerLocator()
port = loc.getEchoServer('http://localhost:8080/Echo/',
req = EchoRequest()
req.EchoIn = 'Hello'
resp = port.Echo(req)
print 'GotResponse:', resp.EchoResult
assert resp.EchoResult == req.EchoIn*3
- Finally let's run the tests for our app with nose. This should run all the tests in the "echo/tests/" folder and report "OK".
For now please refer to the built-in module documentation. More coming soon...