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

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

WMS now works sufficiently to be crudely viewable with openlayers but
bugs remain.

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