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.Debug import log
13 from PLC.API import PLCAPI
17 def application(environ, start_response):
20 if environ.get('REQUEST_METHOD') != 'POST':
21 content_type = 'text/html'
24 <title>PLCAPI WSGI XML-RPC/SOAP Interface</title>
26 <h1>PLCAPI WSGI XML-RPC/SOAP Interface</h1>
27 <p>Please use XML-RPC or SOAP to access the PLCAPI.</p>
32 content_type = 'text/xml'
33 ip = environ.get('REMOTE_ADDR')
34 port = environ.get('REMOTE_PORT')
35 output = api.handle((ip,port), environ.get('wsgi.input').read())
36 # Shut down database connection, otherwise up to MaxClients DB
37 # connections will remain open.
39 except Exception, err:
40 status = '500 Internal Server Error'
41 content_type = 'text/html'
42 output = 'Internal Server Error'
43 print >> log, err, traceback.format_exc()
46 response_headers = [('Content-type', '%s' % content_type),
47 ('Content-Length', str(len(output)))]
48 start_response(status, response_headers)