From 254be00498175dd98d097fe0791a1b03807f26c6 Mon Sep 17 00:00:00 2001 From: Martijn Vermaat <martijn@vermaat.name> Date: Thu, 24 May 2012 09:25:00 +0000 Subject: [PATCH] Refactor webservice organisation git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/branches/rpclib-branch@537 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1 --- bin/mutalyzer-webservice.wsgi | 4 +-- mutalyzer/services/__init__.py | 3 +++ mutalyzer/{webservice.py => services/rpc.py} | 28 +------------------- mutalyzer/services/soap.py | 25 +++++++++++++++++ mutalyzer/website.py | 4 +-- 5 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 mutalyzer/services/__init__.py rename mutalyzer/{webservice.py => services/rpc.py} (97%) create mode 100644 mutalyzer/services/soap.py diff --git a/bin/mutalyzer-webservice.wsgi b/bin/mutalyzer-webservice.wsgi index 5a01545e..ff63ee0b 100755 --- a/bin/mutalyzer-webservice.wsgi +++ b/bin/mutalyzer-webservice.wsgi @@ -30,7 +30,7 @@ To start the built-in HTTP server on port 8081: import sys from wsgiref.simple_server import make_server -from mutalyzer import webservice +from mutalyzer.services import soap DEFAULT_PORT = 8081 @@ -38,7 +38,7 @@ DEFAULT_PORT = 8081 # Unfortunately we cannot instantiate wsgi.Application here, see the note # near the bottom of mutalyzer/webservice.py. -application = webservice.application +application = soap.wsgi_application if __name__ == '__main__': diff --git a/mutalyzer/services/__init__.py b/mutalyzer/services/__init__.py new file mode 100644 index 00000000..05b3d031 --- /dev/null +++ b/mutalyzer/services/__init__.py @@ -0,0 +1,3 @@ +""" +Services (RPC) for Mutalyzer. +""" diff --git a/mutalyzer/webservice.py b/mutalyzer/services/rpc.py similarity index 97% rename from mutalyzer/webservice.py rename to mutalyzer/services/rpc.py index 826a0ce1..220cf46b 100644 --- a/mutalyzer/webservice.py +++ b/mutalyzer/services/rpc.py @@ -1,8 +1,6 @@ """ -Mutalyzer webservices. +Mutalyzer RPC services. -@todo: Do we really use namespaces correctly? -@todo: For some reason, the server exposes its location including ?wsdl. @todo: More thourough input checking. The @soap decorator does not do any kind of strictness checks on the input. For example, in transcriptInfo, the build argument must really be present. (Hint: @@ -10,24 +8,11 @@ Mutalyzer webservices. """ -# WSGI applications should never print anything to stdout. We redirect to -# stderr, but eventually Mutalyzer should be fixed to never just 'print' -# anything. -# http://code.google.com/p/modwsgi/wiki/DebuggingTechniques -import sys -sys.stdout = sys.stderr - -# Log exceptions to stdout -import logging; logging.basicConfig() - -from rpclib.application import Application -from rpclib.protocol.soap import Soap11 from rpclib.decorator import srpc from rpclib.service import ServiceBase from rpclib.model.primitive import String, Integer, Boolean, DateTime from rpclib.model.complex import Array from rpclib.model.fault import Fault -from rpclib.server.wsgi import WsgiApplication import os import socket from operator import itemgetter, attrgetter @@ -1100,14 +1085,3 @@ class MutalyzerService(ServiceBase): return descriptions #getdbSNPDescriptions #MutalyzerService - - -# WSGI application for use with e.g. Apache/mod_wsgi -soap_application = Application([MutalyzerService], mutalyzer.SOAP_NAMESPACE, - in_protocol=Soap11(), out_protocol=Soap11(), - name='Mutalyzer') -# Note: We would like to create the wsgi.Application instance only in the -# bin/mutalyzer-webservice.wsgi script, but unfortunately this breaks the -# get_wsdl method of soap_application which we use to generate API -# documentation in website.py. -application = WsgiApplication(soap_application) diff --git a/mutalyzer/services/soap.py b/mutalyzer/services/soap.py new file mode 100644 index 00000000..31bb4e67 --- /dev/null +++ b/mutalyzer/services/soap.py @@ -0,0 +1,25 @@ +""" +Mutalyzer SOAP/1.1 webservice. +""" + + +from rpclib.application import Application +from rpclib.protocol.soap import Soap11 +from rpclib.server.wsgi import WsgiApplication + +import mutalyzer +from mutalyzer.services import rpc + + +# SOAP/1.1 application. +application = Application([rpc.MutalyzerService], tns=mutalyzer.SOAP_NAMESPACE, + in_protocol=Soap11(), out_protocol=Soap11(), + name='Mutalyzer') + + +# Below we define WSGI applications for use with e.g. Apache/mod_wsgi. +# Note: We would like to create the wsgi.Application instance only in the +# bin/mutalyzer-webservice.wsgi script, but unfortunately this breaks the +# get_interface_document method of rpclib which we use to generate API +# documentation in website.py. +wsgi_application = WsgiApplication(application) diff --git a/mutalyzer/website.py b/mutalyzer/website.py index 67245a8f..da8c89b1 100644 --- a/mutalyzer/website.py +++ b/mutalyzer/website.py @@ -34,7 +34,7 @@ import mutalyzer from mutalyzer import util from mutalyzer import config from mutalyzer.grammar import Grammar -from mutalyzer import webservice +from mutalyzer.services import soap from mutalyzer import variantchecker from mutalyzer.output import Output from mutalyzer.mapping import Converter @@ -1444,7 +1444,7 @@ class Documentation: @todo: Cache this transformation. """ url = web.ctx.homedomain + web.ctx.homepath + WEBSERVICE_LOCATION - wsdl = Wsdl11(webservice.soap_application.interface) + wsdl = Wsdl11(soap.application.interface) wsdl.build_interface_document(url) wsdl_handle = StringIO(wsdl.get_interface_document()) xsl_handle = open(os.path.join(mutalyzer.package_root(), WSDL_VIEWER), -- GitLab