3 # Apache mod_wsgi python interface
5 # Copyright (C) 2004-2006 The Trustees of Princeton University
9 sys.path.append('/usr/share/plc_api')
10 sys.stdout = sys.stderr
12 from PLC.Logger import logger
13 from PLC.API import PLCAPI
15 def application(environ, start_response):
18 if environ.get('REQUEST_METHOD') != 'POST':
19 content_type = 'text/html'
22 <title>PLCAPI WSGI XML-RPC/SOAP Interface</title>
24 <h1>PLCAPI WSGI XML-RPC/SOAP Interface</h1>
25 <p>Please use XML-RPC or SOAP to access the PLCAPI.</p>
29 # Thomas Dreibholz <dreibh@simula.no>
30 # Note that this function is called within multiple threads!
31 # "api" MUST be a local variable instead of a global one.
32 # Otherwise, this causes concurrent accesses to the same
33 # object within different threads!
36 content_type = 'text/xml'
37 ip = environ.get('REMOTE_ADDR')
38 port = environ.get('REMOTE_PORT')
39 output = api.handle((ip,port), environ.get('wsgi.input').read())
40 # Shut down database connection, otherwise up to MaxClients DB
41 # connections will remain open.
43 except Exception as err:
44 status = '500 Internal Server Error'
45 content_type = 'text/html'
46 output = 'Internal Server Error'
47 logger.exception("INTERNAL ERROR !!")
50 response_headers = [('Content-type', '%s' % content_type),
51 ('Content-Length', str(len(output)))]
52 start_response(status, response_headers)