001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/enterprise/servlet/AbstractOWServiceHandler.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2006 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/deegree/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 This library is free software; you can redistribute it and/or
012 modify it under the terms of the GNU Lesser General Public
013 License as published by the Free Software Foundation; either
014 version 2.1 of the License, or (at your option) any later version.
015
016 This library is distributed in the hope that it will be useful,
017 but WITHOUT ANY WARRANTY; without even the implied warranty of
018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 Lesser General Public License for more details.
020
021 You should have received a copy of the GNU Lesser General Public
022 License along with this library; if not, write to the Free Software
023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Contact:
026
027 Andreas Poth
028 lat/lon GmbH
029 Aennchenstraße 19
030 53177 Bonn
031 Germany
032 E-Mail: poth@lat-lon.de
033
034 Prof. Dr. Klaus Greve
035 Department of Geography
036 University of Bonn
037 Meckenheimer Allee 166
038 53115 Bonn
039 Germany
040 E-Mail: greve@giub.uni-bonn.de
041
042 ---------------------------------------------------------------------------*/
043 package org.deegree.enterprise.servlet;
044
045 import java.io.OutputStream;
046
047 import javax.servlet.http.HttpServletResponse;
048
049 import org.deegree.framework.log.ILogger;
050 import org.deegree.framework.log.LoggerFactory;
051 import org.deegree.framework.xml.XMLFragment;
052 import org.deegree.ogcwebservices.ExceptionReport;
053 import org.deegree.ogcwebservices.OGCWebServiceException;
054 import org.deegree.owscommon.XMLFactory;
055
056 /**
057 * This class provides methods that are common to all services that comply to the OWS Common
058 * Implementation Specification 0.3.0.
059 * <p>
060 * At the moment, the only implemented functionality allows the sending of exception reports to the
061 * client, but in the future this may be extended by providing a method that sends responses to
062 * GetCapabilities requests.
063 * </p>
064 *
065 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
066 *
067 * @author last edited by: $Author: apoth $
068 *
069 * @version 2.0, $Revision: 6627 $, $Date: 2007-04-17 18:32:10 +0200 (Di, 17 Apr 2007) $
070 *
071 * @since 2.0
072 */
073 abstract class AbstractOWServiceHandler implements ServiceDispatcher {
074
075 //private static final String RESPONSE_TYPE = "application/vnd.ogc.se_xml";
076 private static final String RESPONSE_TYPE = "text/xml";
077
078 private static ILogger LOG = LoggerFactory.getLogger( AbstractOWServiceHandler.class );
079
080 /**
081 * Sends an exception report to the client. The exception report complies to the OWS Common
082 * Implementation Specification 0.3.0.
083 *
084 * @param httpResponse
085 * @param serviceException
086 */
087 public void sendException( HttpServletResponse httpResponse,
088 OGCWebServiceException serviceException ) {
089
090 ExceptionReport report = new ExceptionReport(
091 new OGCWebServiceException[] { serviceException } );
092 try {
093 httpResponse.setContentType( RESPONSE_TYPE );
094 XMLFragment reportDocument = XMLFactory.export( report );
095 OutputStream os = httpResponse.getOutputStream();
096 reportDocument.write( os );
097 os.close();
098 } catch (Exception e) {
099 LOG.logError( "Error sending exception report: ", e );
100 }
101
102 }
103
104 /**
105 * Sends an exception report to the client. The exception report complies to the OWS Common
106 * Implementation Specification 0.3.0.
107 *
108 * @param httpResponse
109 * @param serviceException
110 */
111 public void sendException( HttpServletResponse httpResponse,
112 Exception serviceException ) {
113
114 OGCWebServiceException ogc = new OGCWebServiceException( serviceException.getMessage() );
115
116 ExceptionReport report = new ExceptionReport( new OGCWebServiceException[] { ogc } );
117 try {
118 httpResponse.setContentType( RESPONSE_TYPE );
119 XMLFragment reportDocument = XMLFactory.export( report );
120 OutputStream os = httpResponse.getOutputStream();
121 reportDocument.write( os );
122 os.close();
123 } catch (Exception e) {
124 LOG.logError( "Error sending exception report: ", e );
125 }
126
127 }
128 }