def ogc_impl(): #pylint: disable=too-many-branches nocase_args = lower_get_args() nocase_args = capture_headers(request, nocase_args) service = nocase_args.get("service", "").upper() if service: return ogc_svc_impl(service.lower()) # create dummy env if not exists try: # service argument is only required (in fact only defined) by OGC for # GetCapabilities requests. As long as we are persisting with a single # routing end point for all services, we must derive the service from the request # parameter. # This is a quick hack to fix #64. Service and operation routing could be # handled more elegantly. op = nocase_args.get("request", "").upper() if op in WMS_REQUESTS: return ogc_svc_impl("wms") elif op in WCS_REQUESTS: return ogc_svc_impl("wcs") else: # Should we return a WMS or WCS exception if there is no service specified? # Defaulting to WMS because that's what we already have. raise WMSException("Invalid service and/or request", locator="Service and request parameters") except OGCException as e: _LOG.error("Handled Error: %s", repr(e.errors)) return e.exception_response() except Exception as e: tb = sys.exc_info()[2] ogc_e = WMSException("Unexpected server error: %s" % str(e), http_response=500) return ogc_e.exception_response(traceback=traceback.extract_tb(tb))
def ogc_svc_impl(svc): svc_support = OWS_SUPPORTED[svc] nocase_args = lower_get_args() nocase_args = capture_headers(request, nocase_args) service = nocase_args.get("service", svc).upper() # Is service activated in config? try: if not svc_support.activated(): raise svc_support.default_exception_class( "Invalid service and/or request", locator="Service and request parameters") # Does service match path (if supplied) if service != svc_support.service_upper: raise svc_support.default_exception_class( "Invalid service", locator="Service parameter") version = nocase_args.get("version") version_support = svc_support.negotiated_version(version) except OGCException as e: return e.exception_response() try: return version_support.router(nocase_args) except OGCException as e: return e.exception_response() except Exception as e: tb = sys.exc_info()[2] ogc_e = version_support.exception_class("Unexpected server error: %s" % str(e), http_response=500) return ogc_e.exception_response(traceback=traceback.extract_tb(tb))
def ogc_impl(): #pylint: disable=too-many-branches nocase_args = lower_get_args() nocase_args = capture_headers(request, nocase_args) service = nocase_args.get("service", "").upper() if service: return ogc_svc_impl(service.lower()) # create dummy env if not exists try: # service argument is only required (in fact only defined) by OGC for # GetCapabilities requests. As long as we are persisting with a single # routing end point for all services, we must derive the service from the request # parameter. # This is a quick hack to fix #64. Service and operation routing could be # handled more elegantly. op = nocase_args.get("request", "").upper() if op in WMS_REQUESTS: return ogc_svc_impl("wms") elif op in WCS_REQUESTS: return ogc_svc_impl("wcs") elif op: # Should we return a WMS or WCS exception if there is no service specified? # Defaulting to WMS because that's what we already have. raise WMSException("Invalid service and/or request", locator="Service and request parameters") else: cfg = get_config() url = nocase_args.get('Host', nocase_args['url_root']) base_url = get_service_base_url(cfg.allowed_urls, url) return (render_template( "index.html", cfg=cfg, supported=OWS_SUPPORTED, base_url=base_url, version=__version__, ), 200, resp_headers({"Content-Type": "text/html"})) except OGCException as e: _LOG.error("Handled Error: %s", repr(e.errors)) return e.exception_response() except Exception as e: # pylint: disable=broad-except tb = sys.exc_info()[2] ogc_e = WMSException("Unexpected server error: %s" % str(e), http_response=500) return ogc_e.exception_response(traceback=traceback.extract_tb(tb))
def ogc_svc_impl(svc): svc_support = OWS_SUPPORTED.get(svc) nocase_args = lower_get_args() nocase_args = capture_headers(request, nocase_args) service = nocase_args.get("service", svc).upper() # Is service activated in config? try: if not svc_support: raise WMSException(f"Invalid service: {svc}", valid_keys=[ service.service for service in OWS_SUPPORTED.values() if service.activated() ], code=WMSException.OPERATION_NOT_SUPPORTED, locator="service parameter") if not svc_support.activated(): raise svc_support.default_exception_class( "Invalid service and/or request", locator="Service and request parameters") # Does service match path (if supplied) if service != svc_support.service_upper: raise svc_support.default_exception_class( "Invalid service", locator="Service parameter") version = nocase_args.get("version") version_support = svc_support.negotiated_version(version) except OGCException as e: return e.exception_response() try: return version_support.router(nocase_args) except OGCException as e: return e.exception_response() except Exception as e: #pylint: disable=broad-except tb = sys.exc_info()[2] ogc_e = version_support.exception_class("Unexpected server error: %s" % str(e), http_response=500) return ogc_e.exception_response(traceback=traceback.extract_tb(tb))