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

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

Added more logging. Requests are now logged and OWSExceptions are
logged as well as triggering an XML response. Requests to WMS/GetMap don't
trigger the debugger because it screws up openlayers.

Some changes to routes to make csml_api work again. No doubt this will change
when we have Exist plumbed in.

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