source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/config/middleware.py @ 2615

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/config/middleware.py@2615
Revision 2615, 2.8 KB checked in by lawrence, 13 years ago (diff)

Moving some of the wsgi stack into the ows stack.
At this point an xml dif retrieve works in ows_common.

Line 
1from paste import httpexceptions
2from paste.cascade import Cascade
3from paste.urlparser import StaticURLParser
4from paste.registry import RegistryManager
5from paste.deploy.config import ConfigMiddleware, CONFIG
6from paste.deploy.converters import asbool
7
8from pylons.error import error_template
9from pylons.middleware import ErrorHandler, ErrorDocuments, StaticJavascripts, error_mapper
10import pylons.wsgiapp
11
12from ows_server.config.environment import load_environment
13import ows_server.lib.helpers
14import ows_server.lib.app_globals as app_globals
15
16from ows_server.config.ndgMiddleware import ndgMiddleware
17
18import logging
19
20def make_app(global_conf, full_stack=True, **app_conf):
21    """Create a WSGI application and return it
22   
23    global_conf is a dict representing the Paste configuration options, the
24    paste.deploy.converters should be used when parsing Paste config options
25    to ensure they're treated properly.
26   
27    """
28    # Setup the Paste CONFIG object, adding app_conf/global_conf for legacy code
29    conf = global_conf.copy()
30    conf.update(app_conf)
31    conf.update(dict(app_conf=app_conf, global_conf=global_conf))
32    CONFIG.push_process_config(conf)
33
34    # Load our Pylons configuration defaults
35    config = load_environment(global_conf, app_conf)
36    config.init_app(global_conf, app_conf, package='ows_server',
37                    template_engine='kid')
38       
39    # Load our default Pylons WSGI app and make g available
40    app = pylons.wsgiapp.PylonsApp(config, helpers=ows_server.lib.helpers,
41                                   g=app_globals.Globals)
42    g = app.globals
43    app = ConfigMiddleware(app, conf)
44   
45    # YOUR MIDDLEWARE
46    # Put your own middleware here, so that any problems are caught by the error
47    # handling middleware underneath
48
49    app = ndgMiddleware(app)
50
51    # Configure logging
52   
53    logging.basicConfig(format='%(thread)s %(name)s %(levelname)s %(message)s')
54   
55    # If errror handling and exception catching will be handled by middleware
56    # for multiple apps, you will want to set full_stack = False in your config
57    # file so that it can catch the problems.
58    if asbool(full_stack):
59        # Change HTTPExceptions to HTTP responses
60        app = httpexceptions.make_middleware(app, global_conf)
61   
62        # Error Handling
63        app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware)
64   
65        # Display error documents for 401, 403, 404 status codes (if debug is disabled also
66        # intercepts 500)
67        #app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
68   
69    # Establish the Registry for this application
70    app = RegistryManager(app)
71   
72    static_app = StaticURLParser(config.paths['static_files'])
73    javascripts_app = StaticJavascripts()
74    app = Cascade([static_app, javascripts_app, app])
75    return app
Note: See TracBrowser for help on using the repository browser.