X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=apache%2Fplc.wsgi;fp=apache%2Fplc.wsgi;h=a720088915a7d950ad86a98f9a0ee81670bab932;hb=6ce6589692d760ba10b47af0d24651c3481e389a;hp=840fc061f7d51f721deb8020825776682165f6d3;hpb=9ad1311ca10e1d8010a6494a2cde43ffcd3aa8e7;p=plcapi.git diff --git a/apache/plc.wsgi b/apache/plc.wsgi index 840fc06..a720088 100644 --- a/apache/plc.wsgi +++ b/apache/plc.wsgi @@ -1,3 +1,4 @@ +# -*- python -*- # # Apache mod_wsgi python interface # @@ -13,12 +14,14 @@ from PLC.API import PLCAPI api = PLCAPI() +# recipe from this page +# http://code.google.com/p/modwsgi/wiki/DebuggingTechniques +# let ErrorMiddleware deal with exceptions def application(environ, start_response): - try: - status = '200 OK' - if environ.get('REQUEST_METHOD') != 'POST': - content_type = 'text/html' - output = """ + status = '200 OK' + if environ.get('REQUEST_METHOD') != 'POST': + content_type = 'text/html' + output = """ PLCAPI WSGI XML-RPC/SOAP Interface @@ -26,20 +29,15 @@ def application(environ, start_response):

Please use XML-RPC or SOAP to access the PLCAPI.

""" - else: - api.environ = environ - content_type = 'text/xml' - ip = environ.get('REMOTE_ADDR') - port = environ.get('REMOTE_PORT') - output = api.handle((ip,port), environ.get('wsgi.input').read()) - # Shut down database connection, otherwise up to MaxClients DB - # connections will remain open. - api.db.close() - except Exception, err: - status = '500 Internal Server Error' - content_type = 'text/html' - output = 'Internal Server Error' - print >> log, err, traceback.format_exc() + else: + api.environ = environ + content_type = 'text/xml' + ip = environ.get('REMOTE_ADDR') + port = environ.get('REMOTE_PORT') + output = api.handle((ip,port),environ.get('wsgi.input').read()) + # Shut down database connection, otherwise up to MaxClients DB + # connections will remain open. + api.db.close() # Write response response_headers = [('Content-type', '%s' % content_type), @@ -47,3 +45,5 @@ def application(environ, start_response): start_response(status, response_headers) return [output] +from paste.exceptions.errormiddleware import ErrorMiddleware +application = ErrorMiddleware(application, debug=True)