2 # Apache mod_wsgi python interface
4 # Copyright (C) 2004-2006 The Trustees of Princeton University
8 sys.path.append('/usr/share/plc_api')
9 sys.stdout = sys.stderr
11 from PLC.Debug import log
12 from PLC.API import PLCAPI
16 def application(environ, start_response):
19 if environ.get('REQUEST_METHOD') != 'POST':
20 content_type = 'text/html'
23 <title>PLCAPI WSGI XML-RPC/SOAP Interface</title>
25 <h1>PLCAPI WSGI XML-RPC/SOAP Interface</h1>
26 <p>Please use XML-RPC or SOAP to access the PLCAPI.</p>
31 content_type = 'text/xml'
32 ip = environ.get('REMOTE_ADDR')
33 port = environ.get('REMOTE_PORT')
34 output = api.handle((ip,port), environ.get('wsgi.input').read())
35 # Shut down database connection, otherwise up to MaxClients DB
36 # connections will remain open.
38 except Exception, err:
39 status = '500 Internal Server Error'
40 content_type = 'text/html'
41 output = 'Internal Server Error'
42 print >> log, err, traceback.format_exc()
45 response_headers = [('Content-type', '%s' % content_type),
46 ('Content-Length', str(len(output)))]
47 start_response(status, response_headers)