source: TI12-security/trunk/python/bin/LogServer.py @ 917

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/bin/LogServer.py@917
Revision 917, 3.8 KB checked in by pjkersha, 14 years ago (diff)

Working prototype log server. Has no message level security implemented yet.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3"""NDG Logging Web Service server interface
4
5NERC Data Grid Project
6
7P J Kershaw 12/05/06
8
9Copyright (C) 2006 CCLRC & NERC
10
11This software may be distributed under the terms of the Q Public License,
12version 1.0 or later.
13"""
14
15# Handle socket errors from WS
16import socket 
17
18# Command line processing
19import sys
20import os
21import optparse
22
23# Web service interface
24from ZSI import dispatch
25from ZSI.ServiceContainer import ServiceContainer, SOAPRequestHandler
26
27# Logging Web Services stub code generated by wsdl2py and
28# wsdl2dispatch
29from NDG.log_services import *
30from NDG.log_services_server import log
31
32# Logging
33from NDG.Log import *
34
35
36#_____________________________________________________________________________
37class LogSOAPRequestHandler(SOAPRequestHandler):
38     """Add a do_GET method to return the WSDL on HTTP GET requests.
39     Please note that the path to the wsdl file is derived from what
40     the HTTP invocation delivers (which is put into the self.path
41     attribute), so you might want to change this addressing scheme.
42     """
43     def do_GET(self):
44         """Return the WSDL file."""
45         
46         wsdlfile = "/var/www/html/log.wsdl"
47         
48         print "> > > > > using wsdlfile", wsdlfile
49         wsdl = open(wsdlfile).read()
50         self.send_xml(wsdl)
51 
52     def do_POST(self):
53          """Fudge to get _Dispatch to pick up the correct address
54          - seems to be necessary when putting proxy redirect for port in
55          the wsdl e.g. http://glue.badc.rl.ac.uk/log points to the
56          default port for the Logging."""
57          self.path = "/log.wsdl"
58          SOAPRequestHandler.do_POST(self)
59       
60       
61#_____________________________________________________________________________
62# Copied from ZSI.ServiceContainer, extended to instantiate with a custom
63# request handler
64def AsServer(port=80, services=(), RequestHandlerClass=SOAPRequestHandler):
65      """port --
66          services -- list of service instances
67       """
68      address = ("127.0.0.1", port)
69      sc = ServiceContainer(address, RequestHandlerClass=RequestHandlerClass)
70      for service in services:
71           path = service.getPost()
72           sc.setNode(service, path)
73      sc.serve_forever()
74
75
76#_____________________________________________________________________________
77if __name__ == '__main__':
78
79    parser = optparse.OptionParser()
80    parser.add_option("-p", 
81                      "--port", 
82                      dest="port",
83                      type="int",
84                      default=5100,
85                      help="specify a port number to override the default")
86
87    parser.add_option("-f", 
88                      "--log-file",
89                      dest="logFilePath",
90                      help=\
91                "file path for log file to log to - default is $NDG_DIR/logs")
92
93    parser.add_option("-d", 
94                      "--debug",
95                      dest="debug",
96                      action="store_true",
97                      default=False,
98                      help="set to stop in debugger on receipt of WS request")
99
100    (options, args) = parser.parse_args()
101
102
103    # Create server instance at start up
104    try:
105        logSrv = Log(logFilePath=options.logFilePath)
106
107    except Exception, e:
108        sys.stderr.write("Initialising Logging: %s\n" % str(e))
109        sys.exit(1)
110   
111    print "Logging Server listening..."
112    try:
113         AsServer(port=options.port, 
114                  services=[log(logSrv, debug=options.debug)], 
115                  RequestHandlerClass=LogSOAPRequestHandler)
116
117    except KeyboardInterrupt:
118        sys.exit(0)
119
120    except socket.error, e:
121        sys.stderr.write("Logging Server socket error: %s\n" % \
122                         e[1])
123        sys.exit(1)
124       
125    except Exception, e:
126        sys.stderr.write("Logging Server: %s\n" % str(e))
127        sys.exit(1)
128       
Note: See TracBrowser for help on using the repository browser.