source: subversion/applications/rendering/wms/error_handler.php @ 29147

Last change on this file since 29147 was 8444, checked in by isortega, 11 years ago

OSM WMS: first upload of a version that seems to work with heavy WMS clients

File size: 3.0 KB
Line 
1<?php
2
3/// @author Iván Sánchez Ortega <ivan@sanchezortega.es>
4
5/**
6    OSM WMS ("OpenStreetMap Web Map Service")
7    Copyright (C) 2008, Iván Sánchez Ortega
8
9    This program is free software: you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation, either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21*/   
22
23/// A custom error handling function will ensure that the WMS exceptions can be thrown in either XML or image format.
24
25/// TODO: what if the installation does not have the GD libraries and the exception format is an image?
26/// TODO: How to return OGC-compliant error codes?
27function wms_error_handler($errno, $errstr, $errfile, $errline)
28{
29        if ( $errno != E_USER_ERROR && $errno != E_ERROR )      // Do nothing if the error is not critical.
30                return false;
31       
32       
33        if ($_REQUEST['EXCEPTIONS']=='XML' || $_REQUEST['EXCEPTIONS']=='application/vnd.ogc.se_xml')
34        {
35        /// Only return errors as XML if the client explicitly asks for it - most WMS clients are lazy and will probably like an image better.
36       
37        echo "<?xml version='1.0' encoding='UTF-8'?>
38<ServiceExceptionReport version='1.3.0'
39  xmlns='http://www.opengis.net/ogc'
40  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
41  xsi:schemaLocation='http://www.opengis.net/ogc
42http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd'>
43<ServiceException>
44<![CDATA[
45Fatal error:
46$errstr
47       
48(Triggered in file $errfile, line $errline).
49]]>
50</ServiceException>
51</ServiceExceptionReport>
52";
53
54        die();
55
56
57        }
58        else
59        {
60                // Return an image, with either nothing or the error message printed.
61               
62               
63                $height = (int) $_REQUEST['HEIGHT'];
64                $width  = (int) $_REQUEST['WIDTH'];
65               
66                $im = imagecreate ( $width , $height );
67               
68                $backgroundcolor = imagecolorallocate ( $im , 255 , 255 , 255 );        // White
69               
70                if ($_REQUEST['TRANSPARENT'])
71                        imagecolortransparent( $im , $backgroundcolor );
72               
73                if ($_REQUEST['EXCEPTIONS'] != 'BLANK' && $_REQUEST['EXCEPTIONS'] != 'application/vnd.ogc.se_blank')
74                {
75                        $textcolor = imagecolorallocate ( $im , 255 , 0 , 0 );  // Red
76               
77                        $errortext = "Fatal error:\n$errstr\n\n(Triggered in file $errfile, line $errline).";
78                        imagettftext ( $im , 8 , 0 , 0 , 0 , $textcolor , './DejaVuSans.ttf' , $errortext );
79                }
80               
81               
82                if ($_REQUEST['FORMAT'] == 'image/png')
83                {
84                        header('Content-type: image/png');
85                        imagepng($im);
86                }
87                if ($_REQUEST['FORMAT'] == 'image/jpeg')
88                {
89                        header('Content-type: image/jpeg');
90                        imagejpeg($im);
91                }
92                if ($_REQUEST['FORMAT'] == 'image/gif')
93                {
94                        header('Content-type: image/gif');
95                        imagegif($im);
96                }
97        }
98       
99       
100       
101       
102
103}
104
105
106set_error_handler("wms_error_handler");
107
108
109
110
111
112
113
114
115
Note: See TracBrowser for help on using the repository browser.