2 # Apache mod_python interface for JSON requests
4 # Aaron Klingaman <alk@absarokasoft.com>
5 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2004-2006 The Trustees of Princeton University
13 from mod_python import apache
15 from PLC.Logger import logger
17 from PLC.API import PLCAPI
22 if req.method != "POST":
23 req.content_type = "text/html"
24 req.send_http_header()
27 <title>PLCAPI JSON Interface</title>
29 <h1>PLCAPI JSON Interface</h1>
30 <p>Please POST JSON to access the PLCAPI.</p>
36 request = req.read(int(req.headers_in['content-length']))
38 # mod_python < 3.2: The IP address portion of remote_addr is
39 # incorrect (always 0.0.0.0) when IPv6 is enabled.
40 # http://issues.apache.org/jira/browse/MODPYTHON-64?page=all
41 (remote_ip, remote_port) = req.connection.remote_addr
42 remote_addr = (req.connection.remote_ip, remote_port)
45 response = api.handle_json(remote_addr, request)
47 # Shut down database connection, otherwise up to MaxClients DB
48 # connections will remain open.
52 req.content_type = "text/json; charset=" + api.encoding
53 req.send_http_header()
58 except Exception as err:
59 logger.exception("INTERNAL ERROR !!")
60 return apache.HTTP_INTERNAL_SERVER_ERROR