Package eoxserver :: Package services :: Module ogc
[hide private]
[frames] | no frames]

Source Code for Module eoxserver.services.ogc

  1  #------------------------------------------------------------------------------- 
  2  # $Id: ogc.py 2008 2012-09-05 17:20:39Z krauses $ 
  3  # 
  4  # Project: EOxServer <http://eoxserver.org> 
  5  # Authors: Stephan Krause <stephan.krause@eox.at> 
  6  #          Stephan Meissl <stephan.meissl@eox.at> 
  7  # 
  8  #------------------------------------------------------------------------------- 
  9  # Copyright (C) 2011 EOX IT Services GmbH 
 10  # 
 11  # Permission is hereby granted, free of charge, to any person obtaining a copy 
 12  # of this software and associated documentation files (the "Software"), to deal 
 13  # in the Software without restriction, including without limitation the rights 
 14  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
 15  # copies of the Software, and to permit persons to whom the Software is  
 16  # furnished to do so, subject to the following conditions: 
 17  # 
 18  # The above copyright notice and this permission notice shall be included in all 
 19  # copies of this Software or works derived from this Software. 
 20  # 
 21  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 22  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 23  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 24  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 25  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 26  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
 27  # THE SOFTWARE. 
 28  #------------------------------------------------------------------------------- 
 29   
 30  """ 
 31  This module contains old style exception handlers that use the OGC 
 32  namespace for exception reports (prior to OWS Common). 
 33  """ 
 34   
 35  from eoxserver.core.util.xmltools import XMLEncoder 
 36  from eoxserver.services.exceptions import InvalidRequestException 
 37  from eoxserver.services.base import BaseExceptionHandler 
 38  from eoxserver.services.interfaces import ( 
 39      ExceptionHandlerInterface, ExceptionEncoderInterface 
 40  ) 
 41   
42 -class OGCExceptionHandler(BaseExceptionHandler):
43 """ 44 Handler class for the OGC namespace. 45 """ 46 REGISTRY_CONF = { 47 "name": "OGC Namespace Exception Handler", 48 "impl_id": "services.ogc.OGCExceptionHandler", 49 "registry_values": { 50 "services.interfaces.exception_scheme": "ogc" 51 } 52 } 53
54 - def _filterExceptions(self, exception):
55 if not isinstance(exception, InvalidRequestException): 56 raise
57
58 - def _getEncoder(self):
59 return OGCExceptionEncoder(self.schemas)
60
61 - def _getContentType(self, exception):
62 return "application/vnd.ogc.se_xml"
63 64 OGCExceptionHandlerImplementation = ExceptionHandlerInterface.implement(OGCExceptionHandler) 65
66 -class OGCExceptionEncoder(XMLEncoder):
67 """ 68 Encoder class for OGC namespace exception reports. 69 """ 70 REGISTRY_CONF = { 71 "name": "OGC Namespace Exception Report Encoder", 72 "impl_id": "services.ogc.OGCExceptionEncoder", 73 "registry_values": { 74 "services.interfaces.exception_scheme": "ogc" 75 } 76 } 77
78 - def _initializeNamespaces(self):
79 return { 80 "ogc": "http://www.opengis.net/ogc", 81 "xsi": "http://www.w3.org/2001/XMLSchema-instance" 82 }
83
84 - def encodeExceptionReport(self, exception_text, exception_code, locator=None):
85 if locator is None: 86 element = self._makeElement("ogc", "ServiceExceptionReport", [ 87 ("", "@version", "1.2.0"), 88 ("ogc", "ServiceException", [ 89 ("", "@code", exception_code), 90 ("", "@@", exception_text) 91 ]) 92 ]) 93 else: 94 element = self._makeElement("ogc", "ServiceExceptionReport", [ 95 ("", "@version", "1.2.0"), 96 ("ogc", "ServiceException", [ 97 ("", "@code", exception_code), 98 ("", "@locator", locator), 99 ("", "@@", exception_text) 100 ]) 101 ]) 102 103 if self.schemas is not None: 104 schemas_location = " ".join(["%s %s"%(ns, location) for ns, location in self.schemas.iteritems()]) 105 element.setAttributeNS(self.ns_dict["xsi"], "%s:%s" % ("xsi", "schemaLocation"), schemas_location) 106 107 return element
108
109 - def encodeInvalidRequestException(self, exception):
110 return self.encodeExceptionReport( 111 exception.msg, 112 exception.error_code, 113 exception.locator 114 )
115
116 - def encodeVersionNegotiationException(self, exception):
117 return "" # TODO: check against OWS Common
118
119 - def encodeException(self, exception):
120 return self.encodeExceptionReport("Internal Server Error", "NoApplicableCode")
121 122 OGCExceptionEncoderImplementation = ExceptionEncoderInterface.implement(OGCExceptionEncoder) 123