def create_application(self, environ, start_response): try: logger.debug("WSGI Call") url, route = environ['wsgiorg.routing_args'] if not route: start_response(HTTP.NOTFOUND, [('Content-Type', 'text/plain')]) return [HTTP.NOTFOUND + ''': No route defined to %s Route:%s Tried to match: %s ''' % (environ['PATH_INFO'], route, str(j25._mapper))] if 'app' not in route: logger.error("'app' is not defined for %s (route:%)", environ['PATH_INFO'], route) start_response(HTTP.INTERNAL_SERVER_ERROR, [('Content-Type', 'text/plain')]) error_message = HTTP.INTERNAL_SERVER_ERROR if j25.is_dev(): error_message = error_format % (HTTP.INTERNAL_SERVER_ERROR, "'app' is not defined for %s (route:%s)" % (environ['PATH_INFO'], route)) return [error_message] if 'action' not in route: logger.error("'action' is not defined for %s (route:%)", environ['PATH_INFO'], route) start_response(HTTP.INTERNAL_SERVER_ERROR, [('Content-Type', 'text/plain')]) error_message = HTTP.INTERNAL_SERVER_ERROR if j25.is_dev(): error_message = error_format % (HTTP.INTERNAL_SERVER_ERROR, "'action' is not defined for %s (route:%s)" % (environ['PATH_INFO'], route)) return [error_message] app_name = route['app'] self.reload_app(app_name) app_config = __import__("%s.config" % app_name, fromlist="t") app = self._apps[app_name] controller_name = route['controller'] controllers = app[1] if controller_name not in controllers: start_response(HTTP.NOTFOUND, [('Content-Type', 'text/plain')]) return [HTTP.NOTFOUND + ": No controller defined under name %s in application %s" % (controller_name, app_name)] return self.dispatch(app_name, controller_name, app, route, url, environ, start_response, app_config) except: tb = traceback.format_exc() logger.critical("Cannot handle request to %s: %s", environ['PATH_INFO'], tb) start_response(HTTP.INTERNAL_SERVER_ERROR, [('Content-Type', 'text/plain')]) error_message = HTTP.INTERNAL_SERVER_ERROR if j25.is_dev(): error_message = error_format % (HTTP.INTERNAL_SERVER_ERROR, tb) return [error_message]
def dispatch(self, app_name, controller_name, app, route, url, environ, start_response, app_config): # create the service instance and inject the context session = environ[j25.Constants.SESSION_KEY] request = Request(environ) app_controllers = app[1] controller = app_controllers[controller_name](session=session, request=request, url=url, app_config=app_config) try: return controller.call_controller_action(environ, start_response, route, app[0]) #app[0] appPackage except: tb = traceback.format_exc() logger.critical("Cannot handle request on (%s): %s" % (environ['PATH_INFO'], tb)) start_response(HTTP.INTERNAL_SERVER_ERROR, [('Content-Type', 'text/plain')]) error_message = HTTP.INTERNAL_SERVER_ERROR if j25.is_dev(): error_message = error_format % (HTTP.INTERNAL_SERVER_ERROR, tb) return [error_message]
def reload_app(self, app_name): if j25.is_dev(): self._app_loader.reload(app_name, self)