001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/enterprise/servlet/SOSHandler.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2008 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 lat/lon GmbH
036 Aennchenstraße 19
037 53177 Bonn
038 Germany
039 E-Mail: greve@giub.uni-bonn.de
040
041 ---------------------------------------------------------------------------*/
042 package org.deegree.enterprise.servlet;
043
044 import java.io.IOException;
045 import java.io.OutputStream;
046
047 import javax.servlet.http.HttpServletResponse;
048
049 import org.deegree.enterprise.ServiceException;
050 import org.deegree.framework.log.ILogger;
051 import org.deegree.framework.log.LoggerFactory;
052 import org.deegree.framework.xml.XMLFragment;
053 import org.deegree.ogcwebservices.OGCWebServiceException;
054 import org.deegree.ogcwebservices.OGCWebServiceRequest;
055 import org.deegree.ogcwebservices.sos.SOService;
056 import org.deegree.ogcwebservices.sos.SOServiceFactory;
057 import org.deegree.ogcwebservices.sos.XMLFactory;
058 import org.deegree.ogcwebservices.sos.capabilities.SOSCapabilities;
059 import org.deegree.ogcwebservices.sos.describeplatform.DescribePlatformResult;
060 import org.deegree.ogcwebservices.sos.describesensor.DescribeSensorResult;
061 import org.deegree.ogcwebservices.sos.getobservation.GetObservationResult;
062
063 /**
064 * Web servlet client for WFS.
065 *
066 * @author <a href="mailto:mkulbe@lat-lon.de">Matthias Kulbe</a>
067 * @author last edited by: $Author: apoth $
068 *
069 * @version $Revision: 9348 $, $Date: 2007-12-27 17:59:14 +0100 (Do, 27 Dez 2007) $
070 */
071 class SOSHandler extends AbstractOWServiceHandler {
072
073 private static ILogger LOG = LoggerFactory.getLogger( SOSHandler.class );
074
075 /**
076 *
077 */
078 SOSHandler() {
079 LOG.logDebug( "New SOSHandler instance created: " + this.getClass().getName() );
080 }
081
082 /**
083 * @param request
084 * @param response
085 * @throws ServiceException
086 * @throws OGCWebServiceException
087 * @see "org.deegree.enterprise.servlet.ServiceDispatcher#perform(org.deegree.services.AbstractOGCWebServiceRequest,javax.servlet.http.HttpServletResponse)"
088 */
089 public void perform( OGCWebServiceRequest request, HttpServletResponse response )
090 throws ServiceException, OGCWebServiceException {
091
092 Object serviceRes = this.getService().doService( request );
093
094 if ( serviceRes instanceof OGCWebServiceException ) {
095 sendException( response, (OGCWebServiceException) serviceRes );
096 } else if ( response instanceof Exception ) {
097 sendException( response, (Exception) serviceRes );
098 } else if ( serviceRes instanceof SOSCapabilities ) {
099 XMLFragment doc = XMLFactory.export( (SOSCapabilities) serviceRes );
100 createResponse( response, doc );
101 } else if ( serviceRes instanceof DescribePlatformResult ) {
102 XMLFragment doc = XMLFactory.export( (DescribePlatformResult) serviceRes );
103 createResponse( response, doc );
104 } else if ( serviceRes instanceof DescribeSensorResult ) {
105 XMLFragment doc = XMLFactory.export( (DescribeSensorResult) serviceRes );
106 createResponse( response, doc );
107 } else if ( serviceRes instanceof GetObservationResult ) {
108 XMLFragment doc = XMLFactory.export( (GetObservationResult) serviceRes );
109 createResponse( response, doc );
110 } else {
111
112 String mesgFragment = null;
113 if ( response == null ) {
114 mesgFragment = "null response object";
115 } else {
116 mesgFragment = response.getClass().getName();
117 }
118
119 OGCWebServiceException e = new OGCWebServiceException(
120 getClass().getName(),
121 "Unknown response class: "
122 + mesgFragment );
123 sendException( response, e );
124 }
125 }
126
127 private void createResponse( HttpServletResponse response, XMLFragment doc )
128 throws OGCWebServiceException {
129
130 try {
131 OutputStream os = response.getOutputStream();
132 doc.write( os );
133 os.close();
134 } catch ( IOException e ) {
135 throw new OGCWebServiceException( "SCS Web Service failed." );
136 }
137
138 }
139
140 /**
141 * @return Service
142 * @throws ServiceException
143 */
144 /*
145 * (non-Javadoc)
146 *
147 * @see org.deegree.enterprise.servlet.ServiceDispatcher#setConfiguration(java.net.URL)
148 */
149 public SOService getService()
150 throws ServiceException {
151 SOService service = null;
152 try {
153 service = SOServiceFactory.getService();
154 } catch ( Exception e ) {
155 LOG.logError( e.getMessage(), e );
156 throw new ServiceException( e );
157 }
158 return service;
159 }
160 }