001 // $HeadURL: /cvsroot/deegree/src/org/deegree/ogcwebservices/wms/WMPService.java,v 002 // 1.3 2004/07/12 06:12:11 ap Exp $ 003 /*---------------- FILE HEADER ------------------------------------------ 004 005 This file is part of deegree. 006 Copyright (C) 2001-2006 by: 007 EXSE, Department of Geography, University of Bonn 008 http://www.giub.uni-bonn.de/deegree/ 009 lat/lon GmbH 010 http://www.lat-lon.de 011 012 This library is free software; you can redistribute it and/or 013 modify it under the terms of the GNU Lesser General Public 014 License as published by the Free Software Foundation; either 015 version 2.1 of the License, or (at your option) any later version. 016 017 This library is distributed in the hope that it will be useful, 018 but WITHOUT ANY WARRANTY; without even the implied warranty of 019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 020 Lesser General Public License for more details. 021 022 You should have received a copy of the GNU Lesser General Public 023 License along with this library; if not, write to the Free Software 024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 025 026 Contact: 027 028 Andreas Poth 029 lat/lon GmbH 030 Aennchenstr. 19 031 53115 Bonn 032 Germany 033 E-Mail: poth@lat-lon.de 034 035 Prof. Dr. Klaus Greve 036 Department of Geography 037 University of Bonn 038 Meckenheimer Allee 166 039 53115 Bonn 040 Germany 041 E-Mail: greve@giub.uni-bonn.de 042 043 044 ---------------------------------------------------------------------------*/ 045 package org.deegree.ogcwebservices.wmps; 046 047 import java.lang.reflect.Constructor; 048 049 import org.deegree.enterprise.Proxy; 050 import org.deegree.framework.log.ILogger; 051 import org.deegree.framework.log.LoggerFactory; 052 import org.deegree.framework.trigger.TriggerProvider; 053 import org.deegree.i18n.Messages; 054 import org.deegree.ogcwebservices.CurrentUpdateSequenceException; 055 import org.deegree.ogcwebservices.InvalidUpdateSequenceException; 056 import org.deegree.ogcwebservices.OGCWebService; 057 import org.deegree.ogcwebservices.OGCWebServiceException; 058 import org.deegree.ogcwebservices.OGCWebServiceRequest; 059 import org.deegree.ogcwebservices.getcapabilities.OGCCapabilities; 060 import org.deegree.ogcwebservices.wmps.configuration.WMPSConfiguration; 061 import org.deegree.ogcwebservices.wmps.configuration.WMPSDeegreeParams; 062 import org.deegree.ogcwebservices.wmps.operation.PrintMap; 063 import org.deegree.ogcwebservices.wmps.operation.WMPSGetCapabilities; 064 import org.deegree.ogcwebservices.wmps.operation.WMPSGetCapabilitiesResult; 065 import org.deegree.ogcwebservices.wmps.operation.WMPSProtocolFactory; 066 067 /** 068 * Handles saving the PrintMap request to the databank and generating the initial response to be 069 * sent to the user. 070 * 071 * @author <a href="mailto:deshmukh@lat-lon.de">Anup Deshmukh</a> 072 * @version 2.0 073 */ 074 public class WMPService implements OGCWebService { 075 076 private static final ILogger LOG = LoggerFactory.getLogger( WMPService.class ); 077 078 private static final TriggerProvider TP = TriggerProvider.create( WMPService.class ); 079 080 private PrintMapHandler printMapHandler; 081 082 private WMPSConfiguration configuration; 083 084 /** 085 * Creates a new WMPService object. 086 * 087 * @param configuration 088 */ 089 public WMPService( WMPSConfiguration configuration ) { 090 this.configuration = configuration; 091 this.printMapHandler = new PrintMapHandler( configuration ); 092 Proxy proxy = this.configuration.getDeegreeParams().getProxy(); 093 if ( proxy != null ) { 094 proxy.setProxy( true ); 095 } 096 } 097 098 /** 099 * Return the OGCCapabilities. 100 * 101 * @return OGCCapabilities 102 */ 103 public OGCCapabilities getCapabilities() { 104 return this.configuration; 105 } 106 107 /** 108 * the method performs the handling of the passed OGCWebServiceEvent directly and returns the 109 * result to the calling class/method 110 * 111 * @param request 112 * request to perform 113 * @return Object 114 * @throws OGCWebServiceException 115 */ 116 public Object doService( OGCWebServiceRequest request ) 117 throws OGCWebServiceException { 118 119 request = (OGCWebServiceRequest)TP.doPreTrigger( this, request )[0]; 120 121 Object result = null; 122 if ( request instanceof PrintMap ) { 123 124 String template = ( (PrintMap) request ).getTemplate(); 125 WMPSDeegreeParams params = this.configuration.getDeegreeParams(); 126 boolean isSynchronous = params.getSynchronousTemplates().contains( template ); 127 128 String handler = HandlerMapping.getString( "WMPService.PRINTMAP" ); 129 RequestManager rqManager = (RequestManager) createHandler( request, PrintMap.class, 130 handler ); 131 132 try { 133 rqManager.saveRequestToDB(); 134 135 result = rqManager.createInitialResponse( Messages.getMessage( "WMPS_INIT_RESPONSE" ) ); 136 } catch ( OGCWebServiceException e ) { 137 138 throw new OGCWebServiceException( "Error saving the PrintMap request " 139 + "to the DB. " + e.getMessage() ); 140 } 141 142 try { 143 if ( isSynchronous ) { 144 result = this.printMapHandler.runSynchronous( (PrintMap) request ); 145 } else { 146 Thread printMap = new Thread( this.printMapHandler ); 147 printMap.start(); 148 } 149 } catch ( Exception e ) { 150 LOG.logError( e.getMessage(), e ); 151 throw new OGCWebServiceException( "Error performing the PrintMap request. " 152 + e.getMessage() ); 153 } 154 } else if ( request instanceof WMPSGetCapabilities ) { 155 result = handleGetCapabilities( (WMPSGetCapabilities) request ); 156 } 157 158 return TP.doPostTrigger( this, result )[0]; 159 } 160 161 /** 162 * creates a handler class for performing the incomming request. The instance that will be 163 * created depends on the responsible class the for the submitted request in the WMPS 164 * capabilities/configuration. 165 * 166 * @param request 167 * request to be performed 168 * @param requestClass 169 * of the request (GetStyles, WMSFeatureInfoRequest etc.) 170 * @param className 171 * type of the operation to perform by the handler 172 * @return Object 173 * @throws OGCWebServiceException 174 */ 175 private Object createHandler( OGCWebServiceRequest request, Class requestClass, String className ) 176 throws OGCWebServiceException { 177 178 // describes the signature of the required constructor 179 Class[] cl = new Class[2]; 180 cl[0] = WMPSConfiguration.class; 181 cl[1] = requestClass; 182 183 // set parameter to submitt to the constructor 184 Object[] o = new Object[2]; 185 o[0] = this.configuration; 186 o[1] = request; 187 188 Object handler = null; 189 190 try { 191 // get constructor 192 Class creator = Class.forName( className ); 193 Constructor con = creator.getConstructor( cl ); 194 // call constructor and instantiate a new DataStore 195 handler = con.newInstance( o ); 196 } catch ( Exception e ) { 197 LOG.logError( e.getMessage(), e ); 198 throw new OGCWebServiceException( "Couldn't instantiate " + className + '!' ); 199 } 200 201 return handler; 202 } 203 204 /** 205 * reads/creates the capabilities of the WMPS. 206 * 207 * @param request 208 * capabilities request 209 * @return WMPSGetCapabilitiesResult 210 * @throws CurrentUpdateSequenceException 211 * @throws InvalidUpdateSequenceException 212 */ 213 private WMPSGetCapabilitiesResult handleGetCapabilities( WMPSGetCapabilities request ) 214 throws CurrentUpdateSequenceException, InvalidUpdateSequenceException { 215 216 String rUp = request.getUpdateSequence(); 217 String cUp = this.configuration.getUpdateSequence(); 218 219 if ( ( rUp != null ) && ( cUp != null ) && ( rUp.compareTo( cUp ) == 0 ) ) { 220 throw new CurrentUpdateSequenceException( "request update sequence: " + rUp 221 + "is equal to capabilities" 222 + " update sequence " + cUp ); 223 } 224 225 if ( ( rUp != null ) && ( cUp != null ) && ( rUp.compareTo( cUp ) > 0 ) ) { 226 throw new InvalidUpdateSequenceException( "request update sequence: " + rUp 227 + " is higher then the " 228 + "capabilities update sequence " + cUp ); 229 } 230 return WMPSProtocolFactory.createGetCapabilitiesResult( request, null, this.configuration ); 231 } 232 233 } 234 /*************************************************************************************************** 235 * Changes to this class. What the people have been up to: $Log$ 236 * Changes to this class. What the people have been up to: Revision 1.26 2006/10/02 06:30:35 poth 237 * Changes to this class. What the people have been up to: bug fixes 238 * Changes to this class. What the people have been up to: 239 * Revision 1.25 2006/09/13 07:37:58 deshmukh 240 * removed excess debug statements. 241 * Changes to this 242 * class. What the people have been up to: Revision 1.24 2006/08/29 19:54:14 poth Changes to this 243 * class. What the people have been up to: footer corrected Changes to this class. What the people 244 * have been up to: Revision 1.23 2006/08/10 245 * 07:11:35 deshmukh WMPS has been modified 246 * to support the new configuration changes and the excess code not needed has been replaced. 247 * Changes to this class. What the people 248 * have been up to: Revision 1.22 2006/07/31 11:21:07 deshmukh Changes to this class. What the 249 * people have been up to: wmps implemention... Changes to this class. What the people have been up 250 * to: Revision 1.21 2006/07/20 13:24:12 251 * deshmukh Removed a few floating bugs. 252 * Changes to this class. What the people 253 * have been up to: Revision 1.20 2006/06/13 09:30:08 poth Changes to this class. What the people 254 * have been up to: *** empty log message *** Changes to this class. What the people have been up 255 * to: Revision 1.19 2006/06/12 09:34:53 256 * deshmukh extended the print map 257 * capabilites to support the get request and changed the db structure. Changes to this class. What 258 * the people have been up to: Revision 1.18 2006/06/07 12:37:51 deshmukh Reset the changes made to 259 * the WMPS. 260 * 261 * Revision 1.16 2006/05/17 12:21:37 poth not required exceptions removed 262 * 263 * Revision 1.15 2006/05/17 12:18:48 poth not required exceptions removed 264 * 265 * Revision 1.14 2006/05/16 14:55:54 poth alternative synchronous performance of PrintMap requests 266 * implemented 267 * 268 * Revision 1.13 2006/05/16 06:43:12 poth ** empty log message *** 269 * 270 * 271 **************************************************************************************************/