Package proxy :: Module apacheServer
[hide private]
[frames] | no frames]

Source Code for Module proxy.apacheServer

 1  # apacheServer.py      - Apache XML-RPC server for mod_python (Spacewalk). 
 2  # 
 3  # Copyright (c) 2008--2017 Red Hat, Inc. 
 4  # 
 5  # This software is licensed to you under the GNU General Public License, 
 6  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 7  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 8  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 9  # along with this software; if not, see 
10  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
11  # 
12  # Red Hat trademarks are not licensed under GPLv2. No permission is 
13  # granted to use or replicate Red Hat trademarks that are incorporated 
14  # in this software or its documentation. 
15  # 
16   
17  # common module imports 
18  from spacewalk.common.rhnConfig import CFG, initCFG 
19  from spacewalk.common.rhnLog import initLOG, log_setreq, log_debug 
20  from spacewalk.common.rhnTB import Traceback 
21  from spacewalk.common import apache 
22 23 24 -class HandlerWrap:
25 26 """ Wrapper handlers to catch unwanted exceptions """ 27 svrHandlers = None 28
29 - def __init__(self, name, init=0):
30 self.__name = name 31 # Flag: should we initialize the config and logging components? 32 self.__init = init
33
34 - def __call__(self, req):
35 # NOTE: all imports done here due to required initialization of 36 # of the configuration module before all others. 37 # Initialization is dependent on RHNComponentType in the 38 # req object. 39 40 if self.__init: 41 from apacheHandler import getComponentType 42 # We cannot trust the config files to tell us if we are in the 43 # broker or in the redirect because we try to always pass 44 # upstream all requests 45 componentType = getComponentType(req) 46 initCFG(componentType) 47 initLOG(CFG.LOG_FILE, CFG.DEBUG) 48 log_debug(1, 'New request, component %s' % (componentType, )) 49 50 # Instantiate the handlers 51 if HandlerWrap.svrHandlers is None: 52 HandlerWrap.svrHandlers = self.get_handler_factory(req)() 53 54 if self.__init: 55 # Set the component type 56 HandlerWrap.svrHandlers.set_component(componentType) 57 58 try: 59 log_setreq(req) 60 if hasattr(HandlerWrap.svrHandlers, self.__name): 61 f = getattr(HandlerWrap.svrHandlers, self.__name) 62 ret = f(req) 63 else: 64 raise Exception("Class has no attribute %s" % self.__name) 65 # pylint: disable=W0702 66 except: 67 Traceback(self.__name, req, extra="Unhandled exception type", 68 severity="unhandled") 69 return apache.HTTP_INTERNAL_SERVER_ERROR 70 else: 71 return ret
72 73 @staticmethod
74 - def get_handler_factory(_req):
75 """ Handler factory. Redefine in your subclasses if so choose """ 76 from apacheHandler import apacheHandler 77 return apacheHandler
78 79 80 # Instantiate external entry points: 81 HeaderParserHandler = HandlerWrap("headerParserHandler", init=1) 82 Handler = HandlerWrap("handler") 83 CleanupHandler = HandlerWrap("cleanupHandler") 84 LogHandler = HandlerWrap("logHandler") 85