001 // $HeadURL:
002 // /cvsroot/deegree/src/org/deegree/ogcwebservices/OGCRequestFactory.java,v 1.12
003 // 2004/08/10 17:17:02 tf Exp $
004 /*----------------------------------------------------------------------------
005 This file is part of deegree, http://deegree.org/
006 Copyright (C) 2001-2009 by:
007 Department of Geography, University of Bonn
008 and
009 lat/lon GmbH
010
011 This library is free software; you can redistribute it and/or modify it under
012 the terms of the GNU Lesser General Public License as published by the Free
013 Software Foundation; either version 2.1 of the License, or (at your option)
014 any later version.
015 This library is distributed in the hope that it will be useful, but WITHOUT
016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
018 details.
019 You should have received a copy of the GNU Lesser General Public License
020 along with this library; if not, write to the Free Software Foundation, Inc.,
021 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022
023 Contact information:
024
025 lat/lon GmbH
026 Aennchenstr. 19, 53177 Bonn
027 Germany
028 http://lat-lon.de/
029
030 Department of Geography, University of Bonn
031 Prof. Dr. Klaus Greve
032 Postfach 1147, 53001 Bonn
033 Germany
034 http://www.geographie.uni-bonn.de/deegree/
035
036 e-mail: info@deegree.org
037 ----------------------------------------------------------------------------*/
038 package org.deegree.ogcwebservices;
039
040 import static org.deegree.framework.util.CharsetUtils.getSystemCharset;
041 import static org.deegree.i18n.Messages.get;
042 import static org.deegree.ogcbase.ExceptionCode.INVALIDPARAMETERVALUE;
043 import static org.deegree.ogcbase.ExceptionCode.MISSINGPARAMETERVALUE;
044 import static org.deegree.ogcbase.ExceptionCode.OPERATIONNOTSUPPORTED;
045
046 import java.io.BufferedReader;
047 import java.io.IOException;
048 import java.io.InputStreamReader;
049 import java.io.Reader;
050 import java.io.StringReader;
051 import java.io.UnsupportedEncodingException;
052 import java.net.MalformedURLException;
053 import java.net.URLDecoder;
054 import java.util.Map;
055
056 import javax.servlet.ServletRequest;
057 import javax.servlet.http.HttpServletRequest;
058
059 import org.deegree.framework.log.ILogger;
060 import org.deegree.framework.log.LoggerFactory;
061 import org.deegree.framework.util.CharsetUtils;
062 import org.deegree.framework.util.IDGenerator;
063 import org.deegree.framework.util.KVP2Map;
064 import org.deegree.framework.util.StringTools;
065 import org.deegree.framework.xml.XMLFragment;
066 import org.deegree.framework.xml.XMLParsingException;
067 import org.deegree.framework.xml.XMLTools;
068 import org.deegree.ogcbase.CommonNamespaces;
069 import org.deegree.ogcbase.ExceptionCode;
070 import org.deegree.ogcwebservices.csw.capabilities.CatalogueGetCapabilities;
071 import org.deegree.ogcwebservices.csw.capabilities.CatalogueOperationsMetadata;
072 import org.deegree.ogcwebservices.csw.discovery.DescribeRecord;
073 import org.deegree.ogcwebservices.csw.discovery.GetRecordById;
074 import org.deegree.ogcwebservices.csw.discovery.GetRecords;
075 import org.deegree.ogcwebservices.csw.discovery.GetRepositoryItem;
076 import org.deegree.ogcwebservices.csw.manager.Harvest;
077 import org.deegree.ogcwebservices.getcapabilities.OperationsMetadata;
078 import org.deegree.ogcwebservices.wass.common.CloseSession;
079 import org.deegree.ogcwebservices.wass.common.GetSession;
080 import org.deegree.ogcwebservices.wass.was.operation.DescribeUser;
081 import org.deegree.ogcwebservices.wass.was.operation.WASGetCapabilities;
082 import org.deegree.ogcwebservices.wass.wss.operation.DoService;
083 import org.deegree.ogcwebservices.wass.wss.operation.WSSGetCapabilities;
084 import org.deegree.ogcwebservices.wcs.describecoverage.DescribeCoverage;
085 import org.deegree.ogcwebservices.wcs.getcapabilities.WCSGetCapabilities;
086 import org.deegree.ogcwebservices.wcs.getcoverage.GetCoverage;
087 import org.deegree.ogcwebservices.wcts.operation.GetResourceByID;
088 import org.deegree.ogcwebservices.wcts.operation.GetResourceByIDDocument;
089 import org.deegree.ogcwebservices.wcts.operation.IsTransformable;
090 import org.deegree.ogcwebservices.wcts.operation.IsTransformableDocument;
091 import org.deegree.ogcwebservices.wcts.operation.Transform;
092 import org.deegree.ogcwebservices.wcts.operation.TransformDocument;
093 import org.deegree.ogcwebservices.wcts.operation.WCTSGetCapabilities;
094 import org.deegree.ogcwebservices.wcts.operation.WCTSGetCapabilitiesDocument;
095 import org.deegree.ogcwebservices.wfs.operation.DescribeFeatureType;
096 import org.deegree.ogcwebservices.wfs.operation.GetFeature;
097 import org.deegree.ogcwebservices.wfs.operation.GetFeatureWithLock;
098 import org.deegree.ogcwebservices.wfs.operation.GetGmlObject;
099 import org.deegree.ogcwebservices.wfs.operation.LockFeature;
100 import org.deegree.ogcwebservices.wfs.operation.WFSGetCapabilities;
101 import org.deegree.ogcwebservices.wfs.operation.transaction.Transaction;
102 import org.deegree.ogcwebservices.wmps.operation.DescribeTemplate;
103 import org.deegree.ogcwebservices.wmps.operation.GetAvailableTemplates;
104 import org.deegree.ogcwebservices.wmps.operation.PrintMap;
105 import org.deegree.ogcwebservices.wmps.operation.WMPSGetCapabilities;
106 import org.deegree.ogcwebservices.wms.operation.DescribeLayer;
107 import org.deegree.ogcwebservices.wms.operation.GetFeatureInfo;
108 import org.deegree.ogcwebservices.wms.operation.GetLegendGraphic;
109 import org.deegree.ogcwebservices.wms.operation.GetMap;
110 import org.deegree.ogcwebservices.wms.operation.WMSGetCapabilities;
111 import org.deegree.ogcwebservices.wps.capabilities.WPSGetCapabilities;
112 import org.deegree.ogcwebservices.wps.describeprocess.DescribeProcessRequest;
113 import org.deegree.ogcwebservices.wps.execute.ExecuteRequest;
114 import org.deegree.ogcwebservices.wpvs.operation.Get3DFeatureInfo;
115 import org.deegree.ogcwebservices.wpvs.operation.GetView;
116 import org.deegree.ogcwebservices.wpvs.operation.WPVSGetCapabilities;
117 import org.w3c.dom.Document;
118 import org.w3c.dom.Element;
119 import org.xml.sax.SAXException;
120
121 /**
122 * Factory for generating request objects for OGC Web Services.
123 * <p>
124 * Requests may be generated from KVP or DOM representations. Also contains methods that decide whether an incoming
125 * request representation is valid for a certain service.
126 * </p>
127 * Currently supported services are:
128 * <ul>
129 * <li>CSW</li>
130 * <li>WFS</li>
131 * <li>WCS</li>
132 * <li>WMS</li>
133 * <li>WFS-G</li>
134 * <li>SOS</li>
135 * <li>WMPS</li>
136 * <li>WSS</li>
137 * <li>WAS</li>
138 * <li>WPVS</li>
139 * </ul>
140 *
141 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
142 * @author last edited by: $Author: apoth $
143 *
144 * @version $Revision: 29966 $, $Date: 2011-03-09 15:19:04 +0100 (Wed, 09 Mar 2011) $
145 */
146 public class OGCRequestFactory {
147
148 private static final ILogger LOG = LoggerFactory.getLogger( OGCRequestFactory.class );
149
150 private static final String CSW_SERVICE_NAME = "CSW";
151
152 /**
153 * The service name of a getRepositoryItem request, only valid for the csw/ebrim. Fixed value:
154 * "urn:x-ogc:specification:cswebrim:Service:OGC-CSW:ebRIM"
155 */
156 public static final String CSW_SERVICE_NAME_EBRIM = "urn:x-ogc:specification:cswebrim:Service:OGC-CSW:ebRIM";
157
158 private static final String WFS_SERVICE_NAME = "WFS";
159
160 private static final String WCS_SERVICE_NAME = "WCS";
161
162 private static final String WMS_SERVICE_NAME = "WMS";
163
164 private static final String SOS_SERVICE_NAME = "SOS";
165
166 private static final String WPVS_SERVICE_NAME = "WPVS";
167
168 private static final String WMPS_SERVICE_NAME = "WMPS";
169
170 private static final String WPS_SERVICE_NAME = "WPS";
171
172 private static final String WSS_SERVICE_NAME = "WSS";
173
174 private static final String WAS_SERVICE_NAME = "WAS";
175
176 private static final String WCTS_SERVICE_NAME = "WCTS";
177
178 /**
179 * Creates an <code>OGCWebServiceRequest</code> from the content contained within the passed request.
180 *
181 * @param request
182 * @return the request object
183 * @throws OGCWebServiceException
184 */
185 public static OGCWebServiceRequest create( ServletRequest request )
186 throws OGCWebServiceException {
187
188 Map<String, String> result = KVP2Map.toMap( request );
189
190 LOG.logDebug( "Request parameters: " + result );
191
192 if ( result.size() != 0 ) {
193 return createFromKVP( result );
194 }
195
196 XMLFragment fragment = null;
197 try {
198 Reader xmlReader = null;
199 if ( LOG.isDebug() ) {
200 LOG.logDebug( "Request's content type is " + request.getContentType() );
201 LOG.logDebug( "Request's character encoding is " + request.getCharacterEncoding() );
202 }
203
204 if ( request.getContentType() != null ) {
205 if ( request.getCharacterEncoding() == null ) {
206 request.setCharacterEncoding( getSystemCharset() );
207 }
208 xmlReader = request.getReader();
209 } else {
210 // DO NOT REMOVE THIS !!!!!
211 // IT IS ABSOLUTELY NECESSARY TO ENSURE CORRECT CHARACTER ENCODING !!!
212 xmlReader = new StringReader( getRequestContent( (HttpServletRequest) request ) );
213 }
214 if ( LOG.getLevel() == ILogger.LOG_DEBUG ) {
215 StringBuffer sb = new StringBuffer();
216 BufferedReader br = new BufferedReader( xmlReader );
217 String line = null;
218 while ( ( line = br.readLine() ) != null ) {
219 sb.append( line );
220 }
221 String content = sb.toString();
222 LOG.logDebugFile( "OGCRequestFactory_incoming", ".xml", content );
223 xmlReader = new StringReader( content );
224 }
225 fragment = new XMLFragment( xmlReader, XMLFragment.DEFAULT_URL );
226 } catch ( SAXException se ) {
227 se.printStackTrace();
228 String message = se.getMessage();
229 if ( message != null ) {
230 if ( message.contains( "not allowed in prolog" ) ) {
231 throw new OGCWebServiceException( "OGCRequestFactory",
232 "No key-value pairs were given and the request"
233 + " does not contain parsable xml",
234 ExceptionCode.NOAPPLICABLECODE );
235 }
236 throw new OGCWebServiceException( "OGCRequestFactory", "Error parsing XML request: " + message,
237 ExceptionCode.NOAPPLICABLECODE );
238 }
239 throw new OGCWebServiceException( "OGCRequestFactory", "Error parsing XML request",
240 ExceptionCode.NOAPPLICABLECODE );
241 } catch ( Exception e ) {
242 LOG.logError( "Error parsing XML request: " + e.getMessage(), e );
243 throw new OGCWebServiceException( "OGCRequestFactory", "Error parsing XML request: " + e.getMessage() );
244 }
245
246 return createFromXML( fragment.getRootElement().getOwnerDocument() );
247 }
248
249 /**
250 * DO NOT REMOVE THIS !!!!! IT IS ABSOLUTLY NECESSARY TO ENSURE CORRECT CHARACTER ENCODING !!!
251 *
252 * @param request
253 * @throws IOException
254 */
255 private static String getRequestContent( HttpServletRequest request )
256 throws IOException {
257 String method = request.getMethod();
258
259 if ( method.equalsIgnoreCase( "POST" ) ) {
260 String charset = request.getCharacterEncoding();
261 LOG.logDebug( "posted character encoding: ", charset );
262 if ( charset == null ) {
263 charset = "UTF-8";
264 }
265 StringBuffer req = readPost( request, charset );
266 if ( charset.equalsIgnoreCase( CharsetUtils.getSystemCharset() ) ) {
267 return req.toString();
268 }
269 if ( charset.equalsIgnoreCase( "UTF-8" ) && !charset.equalsIgnoreCase( CharsetUtils.getSystemCharset() ) ) {
270 String s = new String( req.toString().getBytes(), CharsetUtils.getSystemCharset() );
271 return s;
272 }
273 if ( !charset.equalsIgnoreCase( "UTF-8" ) && !charset.equalsIgnoreCase( CharsetUtils.getSystemCharset() ) ) {
274 String s = new String( req.toString().getBytes(), "UTF-8" );
275 return s;
276 }
277 return req.toString();
278 }
279
280 String req = request.getQueryString();
281 if ( req == null ) {
282 req = readPost( request, CharsetUtils.getSystemCharset() ).toString();
283 }
284 LOG.logDebug( "request string: ", req );
285
286 return URLDecoder.decode( req, CharsetUtils.getSystemCharset() );
287
288 }
289
290 /**
291 * DO NOT REMOVE THIS !!!!! IT IS ABSOLUTLY NECESSARY TO ENSURE CORRECT CHARACTER ENCODING !!!
292 *
293 * @param request
294 * @param charset
295 * @throws UnsupportedEncodingException
296 * @throws IOException
297 */
298 private static StringBuffer readPost( HttpServletRequest request, String charset )
299 throws UnsupportedEncodingException, IOException {
300 java.io.Reader reader = new InputStreamReader( request.getInputStream(), charset );
301 BufferedReader br = new BufferedReader( reader );
302 StringBuffer req = new StringBuffer( 10000 );
303 for ( String line = null; ( line = br.readLine() ) != null; ) {
304 req.append( ( new StringBuilder( String.valueOf( line ) ) ).append( "\n" ).toString() );
305 }
306
307 br.close();
308 return req;
309 }
310
311 /**
312 * Creates an instance of an <code>AbstractOGCWebServiceRequest</code> from the passed DOM object. Supported OWS are
313 * 'WMS', 'WFS', 'WCS' and 'CSW'. If a request for another service is passed or a request that isn't supported by
314 * one of the listed services an exception will be thrown. <BR>
315 * Notice that not all listed services will support request processing by reading the request to be performed from a
316 * DOM object. In this case also an exception will be thrown even if the same request may can be performed if KVP is
317 * used.
318 *
319 * @param doc
320 * @return the request object
321 * @throws OGCWebServiceException
322 */
323 public static OGCWebServiceRequest createFromXML( Document doc )
324 throws OGCWebServiceException {
325
326 if ( LOG.getLevel() == ILogger.LOG_DEBUG ) {
327 XMLFragment xml = new XMLFragment();
328 xml.setRootElement( doc.getDocumentElement() );
329 LOG.logDebug( "XML request (pretty printed): ", xml.getAsPrettyString() );
330 }
331
332 String service = XMLTools.getAttrValue( doc.getDocumentElement(), null, "service", null );
333 String request = doc.getDocumentElement().getLocalName();
334 service = getTargetService( service, request, doc );
335 if ( "unknown".equals( service ) ) {
336 throw new OGCWebServiceException( "OGCRequestFactory", "Specified service '" + service
337 + "' is not a known OGC service type." );
338 }
339 OGCWebServiceRequest ogcRequest = null;
340 if ( request == null ) {
341 throw new OGCWebServiceException( "request", "Request parameter must be set!", MISSINGPARAMETERVALUE );
342 } else if ( WMS_SERVICE_NAME.equals( service ) ) {
343 ogcRequest = getWMSRequest( request, doc );
344 } else if ( WFS_SERVICE_NAME.equals( service ) ) {
345 ogcRequest = getWFSRequest( request, doc );
346 } else if ( WCS_SERVICE_NAME.equals( service ) ) {
347 ogcRequest = getWCSRequest( request, doc );
348 } else if ( CSW_SERVICE_NAME.equals( service ) ) {
349 ogcRequest = getCSWRequest( request, doc );
350 } else if ( WPVS_SERVICE_NAME.equals( service ) ) {
351 ogcRequest = getWPVSRequest( request, doc );
352 } else if ( WMPS_SERVICE_NAME.equals( service ) ) {
353 ogcRequest = getWMPSRequest( request, doc );
354 } else if ( WPS_SERVICE_NAME.equals( service ) ) {
355 ogcRequest = getWPSRequest( request, doc );
356 } else if ( WSS_SERVICE_NAME.equals( service ) ) {
357 ogcRequest = getWSSRequest( request, doc );
358 } else if ( WAS_SERVICE_NAME.equals( service ) ) {
359 ogcRequest = getWASRequest( request, doc );
360 } else if ( WCTS_SERVICE_NAME.equals( service ) ) {
361 ogcRequest = getWCTSRequest( request, doc );
362 } else {
363 throw new OGCWebServiceException( "OGCRequestFactory", "No handler for service " + service
364 + " in OGCRequestFactory." );
365 }
366 return ogcRequest;
367 }
368
369 /**
370 * Creates an instance of an <code>AbstractOGCWebServiceRequest</code> from the passed KVP encoded request.
371 * Supported OWS are 'WMS', 'WFS', 'WCS' and 'CSW'. If a request for another service is passed or a request that
372 * isn't supported by one of the listed services an exception will be thrown. <BR>
373 * Notice that not all listed services will support request processing by reading the request to be performed from
374 * KVPs. In this case also an exception will be thrown even if the same request may be performed if a DOM object is
375 * used.
376 *
377 * @param map
378 * @return the request object
379 * @throws OGCWebServiceException
380 */
381 public static OGCWebServiceRequest createFromKVP( Map<String, String> map )
382 throws OGCWebServiceException {
383
384 LOG.logDebug( "KVP request: ", map );
385 // request parameter given?
386 String request = map.get( "REQUEST" );
387 if ( request == null ) {
388 LOG.logInfo( "parameter: ", map );
389 throw new OGCWebServiceException( "request", get( "NO_REQUEST_PARAMETER" ), MISSINGPARAMETERVALUE );
390 }
391 // service parameter given?
392 String service = map.get( "SERVICE" );
393 if ( service == null ) {
394 // a profile of a service will be treated as a service
395 service = map.get( "PROFILE" );
396 if ( service == null ) {
397 service = getTargetService( service, request, null );
398 }
399 }
400
401 OGCWebServiceRequest ogcRequest = null;
402 if ( !WFS_SERVICE_NAME.equals( service ) ) {
403 map.put( "SERVICE", service );
404 }
405 if ( WMS_SERVICE_NAME.equals( service ) ) {
406 ogcRequest = getWMSRequest( request, map );
407 } else if ( WFS_SERVICE_NAME.equals( service ) ) {
408 ogcRequest = getWFSRequest( request, map );
409 } else if ( WCS_SERVICE_NAME.equals( service ) ) {
410 ogcRequest = getWCSRequest( request, map );
411 } else if ( CSW_SERVICE_NAME_EBRIM.equals( service ) || CSW_SERVICE_NAME.equals( service ) ) {
412 ogcRequest = getCSWRequest( request, map );
413 } else if ( WPVS_SERVICE_NAME.equals( service ) ) {
414 ogcRequest = getWPVSRequest( request, map );
415 } else if ( WMPS_SERVICE_NAME.equals( service ) ) {
416 ogcRequest = getWMPSRequest( request, map );
417 } else if ( WPS_SERVICE_NAME.equals( service ) ) {
418 ogcRequest = getWPSRequest( request, map );
419 } else if ( WSS_SERVICE_NAME.equals( service ) ) {
420 ogcRequest = getWSSRequest( request, map );
421 } else if ( WAS_SERVICE_NAME.equals( service ) ) {
422 ogcRequest = getWASRequest( request, map );
423 } else if ( WCTS_SERVICE_NAME.equals( service ) ) {
424 ogcRequest = getWCTSRequest( request, map );
425 } else {
426 if ( map.get( "SERVICE" ) == null || map.get( "SERVICE" ).equals( "unknown" ) ) {
427 throw new OGCWebServiceException( "service", get( "NO_SERVICE_SPECIFIED" ), MISSINGPARAMETERVALUE );
428 }
429
430 throw new OGCWebServiceException( "service", get( "UNKNOWN_SERVICE_SPECIFIED", map.get( "SERVICE" ) ),
431 INVALIDPARAMETERVALUE );
432 }
433 return ogcRequest;
434 }
435
436 /**
437 * Creates the corresponding WFS request object from the given parameters.
438 *
439 * @param request
440 * @param map
441 * @return the corresponding WFS request object
442 * @throws OGCWebServiceException
443 */
444 private static OGCWebServiceRequest getWFSRequest( String request, Map<String, String> map )
445 throws OGCWebServiceException {
446 OGCWebServiceRequest ogcRequest = null;
447 map.put( "ID", "" + IDGenerator.getInstance().generateUniqueID() );
448 if ( request.equals( "GetCapabilities" ) ) {
449 ogcRequest = WFSGetCapabilities.create( map );
450 } else if ( request.equals( "GetFeature" ) ) {
451 ogcRequest = GetFeature.create( map );
452 } else if ( request.equals( "GetFeatureWithLock" ) ) {
453 ogcRequest = GetFeatureWithLock.create( map );
454 } else if ( request.equals( "GetGmlObject" ) ) {
455 ogcRequest = GetGmlObject.create( map );
456 } else if ( request.equals( "LockFeature" ) ) {
457 ogcRequest = LockFeature.create( map );
458 } else if ( request.equals( "DescribeFeatureType" ) ) {
459 ogcRequest = DescribeFeatureType.create( map );
460 } else if ( request.equals( "Transaction" ) ) {
461 ogcRequest = Transaction.create( map );
462 } else {
463 throw new InvalidParameterValueException( "Unknown WFS request type: '" + request + "'." );
464 }
465 return ogcRequest;
466 }
467
468 /**
469 * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The returned request will be
470 * a WFS request. The type of request is determined by also submitted request name. Known requests are:
471 * <ul>
472 * <li>GetCapabilities</li>
473 * <li>GetFeature</li>
474 * <li>GetFeatureWithLock</li>
475 * <li>DescribeFeatureType</li>
476 * <li>Transaction</li>
477 * <li>LockFeature</li>
478 * </ul>
479 * <p>
480 * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
481 * </p>
482 *
483 * @param request
484 * @param doc
485 * @return created <code>OGCWebServiceRequest</code>
486 * @throws OGCWebServiceException
487 */
488 private static OGCWebServiceRequest getWFSRequest( String request, Document doc )
489 throws OGCWebServiceException {
490 OGCWebServiceRequest ogcRequest = null;
491 String id = "" + IDGenerator.getInstance().generateUniqueID();
492 if ( request.equals( "GetCapabilities" ) ) {
493 ogcRequest = WFSGetCapabilities.create( id, doc.getDocumentElement() );
494 } else if ( request.equals( "GetFeature" ) ) {
495 ogcRequest = GetFeature.create( id, doc.getDocumentElement() );
496 } else if ( request.equals( "GetFeatureWithLock" ) ) {
497 ogcRequest = GetFeatureWithLock.create( id, doc.getDocumentElement() );
498 } else if ( request.equals( "DescribeFeatureType" ) ) {
499 ogcRequest = DescribeFeatureType.create( id, doc.getDocumentElement() );
500 } else if ( request.equals( "Transaction" ) ) {
501 ogcRequest = Transaction.create( id, doc.getDocumentElement() );
502 } else if ( request.equals( "LockFeature" ) ) {
503 ogcRequest = LockFeature.create( id, doc.getDocumentElement() );
504 } else if ( request.equals( "GetGmlObject" ) ) {
505 ogcRequest = GetGmlObject.create( id, doc.getDocumentElement() );
506 } else {
507 throw new OGCWebServiceException( "Unknown / unimplemented WFS request type: '" + request + "'.",
508 OPERATIONNOTSUPPORTED );
509 }
510 return ogcRequest;
511 }
512
513 /**
514 * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The returned request will be
515 * a WSS request. The type of request is determined by also submitted request name. Known requests are:
516 * <ul>
517 * <li>GetCapabilities</li>
518 * <li>GetSession</li>
519 * <li>CloseSession</li>
520 * <li>DoService</li>
521 * </ul>
522 * <p>
523 * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
524 * </p>
525 *
526 * @param request
527 * @param doc
528 * @return created <code>OGCWebServiceRequest</code>
529 * @throws OGCWebServiceException
530 */
531 private static OGCWebServiceRequest getWSSRequest( String request, Document doc )
532 throws OGCWebServiceException {
533 OGCWebServiceRequest ogcRequest = null;
534 String id = "" + IDGenerator.getInstance().generateUniqueID();
535 if ( ( "GetCapabilities" ).equals( request ) ) {
536 ogcRequest = WSSGetCapabilities.create( id, doc.getDocumentElement() );
537 } else if ( ( "GetSession" ).equals( request ) ) {
538 ogcRequest = GetSession.create( id, doc.getDocumentElement() );
539 } else if ( ( "CloseSession" ).equals( request ) ) {
540 ogcRequest = CloseSession.create( id, doc.getDocumentElement() );
541 } else if ( ( "DoService" ).equals( request ) ) {
542 ogcRequest = DoService.create( id, doc.getDocumentElement() );
543 } else {
544 throw new OGCWebServiceException( "Unknown / unimplemented WSS request type: '" + request + "'." );
545 }
546 return ogcRequest;
547 }
548
549 /**
550 * Creates an <code>OGCWebServiceRequest</code> from the passed <code>key value pair</code>. The returned request
551 * will be a WSS request. The type of request is determined by also submitted request name. Known requests are:
552 * <ul>
553 * <li>GetCapabilities</li>
554 * <li>GetSession</li>
555 * <li>CloseSession</li>
556 * <li>DoService</li>
557 * </ul>
558 * <p>
559 * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
560 * </p>
561 *
562 * @param request
563 * @param kvp
564 * @return created <code>OGCWebServiceRequest</code>
565 * @throws OGCWebServiceException
566 */
567 private static OGCWebServiceRequest getWSSRequest( String request, Map<String, String> kvp )
568 throws OGCWebServiceException {
569 OGCWebServiceRequest ogcRequest = null;
570 String id = "" + IDGenerator.getInstance().generateUniqueID();
571 if ( ( "GetCapabilities" ).equals( request ) ) {
572 ogcRequest = WSSGetCapabilities.create( id, kvp );
573 } else if ( ( "GetSession" ).equals( request ) ) {
574 ogcRequest = GetSession.create( id, kvp );
575 } else if ( ( "CloseSession" ).equals( request ) ) {
576 ogcRequest = CloseSession.create( id, kvp );
577 } else if ( ( "DoService" ).equals( request ) ) {
578 ogcRequest = DoService.create( id, kvp );
579 } else {
580 throw new OGCWebServiceException( "Unknown / unimplemented WSS request type: '" + request + "'." );
581 }
582 return ogcRequest;
583 }
584
585 /**
586 * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The returned request will be
587 * a WAS request. The type of request is determined by also submitted request name. Known requests are:
588 * <ul>
589 * <li>GetCapabilities</li>
590 * <li>GetSession</li>
591 * <li>CloseSession</li>
592 * </ul>
593 * <p>
594 * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
595 * </p>
596 *
597 * @param request
598 * @param doc
599 * @return created <code>OGCWebServiceRequest</code>
600 * @throws OGCWebServiceException
601 */
602 private static OGCWebServiceRequest getWASRequest( String request, Document doc )
603 throws OGCWebServiceException {
604 OGCWebServiceRequest ogcRequest = null;
605 String id = "" + IDGenerator.getInstance().generateUniqueID();
606 // note: DescribeUser is only supported through KVP
607 if ( ( "GetCapabilities" ).equals( request ) ) {
608 ogcRequest = WASGetCapabilities.create( id, doc.getDocumentElement() );
609 } else if ( ( "GetSession" ).equals( request ) ) {
610 ogcRequest = GetSession.create( id, doc.getDocumentElement() );
611 } else if ( ( "CloseSession" ).equals( request ) ) {
612 ogcRequest = CloseSession.create( id, doc.getDocumentElement() );
613 } else {
614 throw new OGCWebServiceException( "Unknown / unimplemented WAS request type: '" + request + "'." );
615 }
616 return ogcRequest;
617 }
618
619 /**
620 * Creates an <code>OGCWebServiceRequest</code> from the passed <code>key value pair</code>. The returned request
621 * will be a WAS request. The type of request is determined by also submitted request name. Known requests are:
622 * <ul>
623 * <li>GetCapabilities</li>
624 * <li>GetSession</li>
625 * <li>CloseSession</li>
626 * <li>DescribeUser</li>
627 * </ul>
628 * <p>
629 * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
630 * </p>
631 *
632 * @param request
633 * @param kvp
634 * @return created <code>OGCWebServiceRequest</code>
635 * @throws OGCWebServiceException
636 */
637 private static OGCWebServiceRequest getWASRequest( String request, Map<String, String> kvp )
638 throws OGCWebServiceException {
639 OGCWebServiceRequest ogcRequest = null;
640 kvp.put( "SERVICE", WAS_SERVICE_NAME );
641 String id = "" + IDGenerator.getInstance().generateUniqueID();
642 if ( ( "GetCapabilities" ).equals( request ) ) {
643 ogcRequest = WASGetCapabilities.create( id, kvp );
644 } else if ( ( "GetSession" ).equals( request ) ) {
645 ogcRequest = GetSession.create( id, kvp );
646 } else if ( ( "CloseSession" ).equals( request ) ) {
647 ogcRequest = CloseSession.create( id, kvp );
648 } else if ( ( "DescribeUser" ).equals( request ) ) {
649 ogcRequest = new DescribeUser( id, kvp );
650 } else {
651 throw new OGCWebServiceException( "Unknown / unimplemented WAS request type: '" + request + "'." );
652 }
653 return ogcRequest;
654 }
655
656 /**
657 * return the type of service the passed request targets
658 *
659 * @param service
660 * @param request
661 * @param doc
662 * @return the type of service the passed request targets
663 */
664 public static String getTargetService( String service, String request, Document doc ) {
665
666 if ( WMS_SERVICE_NAME.equals( service ) || isWMSRequest( request ) ) {
667 return WMS_SERVICE_NAME;
668 } else if ( WFS_SERVICE_NAME.equals( service ) || isWFSRequest( request, doc ) ) {
669 return WFS_SERVICE_NAME;
670 } else if ( WCS_SERVICE_NAME.equals( service ) || isWCSRequest( request ) ) {
671 return WCS_SERVICE_NAME;
672 } else if ( CSW_SERVICE_NAME_EBRIM.equals( service ) || CSW_SERVICE_NAME.equals( service )
673 || isCSWRequest( request, doc ) ) {
674 return CSW_SERVICE_NAME;
675 } else if ( SOS_SERVICE_NAME.equals( service ) || isSOSRequest( request ) ) {
676 return SOS_SERVICE_NAME;
677 } else if ( WPVS_SERVICE_NAME.equals( service ) || isWPVSRequest( request ) ) {
678 return WPVS_SERVICE_NAME;
679 } else if ( WMPS_SERVICE_NAME.equals( service ) || isWMPSRequest( doc, request ) ) {
680 return WMPS_SERVICE_NAME;
681 } else if ( WPS_SERVICE_NAME.equals( service ) || isWPSRequest( request ) ) {
682 return WPS_SERVICE_NAME;
683 } else if ( WAS_SERVICE_NAME.equals( service ) || isWASRequest( request ) ) {
684 return WAS_SERVICE_NAME;
685 } else if ( WSS_SERVICE_NAME.equals( service ) || isWSSRequest( request ) ) {
686 return WSS_SERVICE_NAME;
687 } else if ( WCTS_SERVICE_NAME.equals( service ) || isWCTSRequest( doc ) ) {
688 return WCTS_SERVICE_NAME;
689 } else {
690 return "unknown";
691 }
692
693 }
694
695 /**
696 * @param doc
697 * to check
698 * @return true if the namespace of the given dom-xml document equals {@link CommonNamespaces#WCTSNS}.
699 */
700 private static boolean isWCTSRequest( Document doc ) {
701 if ( doc != null ) {
702 Element root = doc.getDocumentElement();
703 if ( root != null ) {
704 String ns = root.getNamespaceURI();
705 return CommonNamespaces.WCTSNS.toASCIIString().equals( ns )
706 || CommonNamespaces.DEEGREEWCTS.toASCIIString().equals( ns );
707 }
708 }
709 return false;
710 }
711
712 /**
713 * returns true if the request is a WMPS request
714 *
715 * @param request
716 * name, e.g. 'GetCapabilities' name, e.g. 'PrintMap'
717 * @return true if the request is a WMPS request
718 */
719 private static boolean isWMPSRequest( Document doc, String request ) {
720 if ( doc != null ) {
721 Element root = doc.getDocumentElement();
722 if ( root != null ) {
723 String ns = root.getNamespaceURI();
724 if ( CommonNamespaces.WMPSNS.toASCIIString().equals( ns ) ) {
725 return true;
726 }
727 }
728 }
729 if ( ( "PrintMap".equals( request ) ) ) {
730 return true;
731 } else if ( ( "GetAvailableTemplates".equals( request ) ) ) {
732 return true;
733 } else if ( ( "DescribeTemplate".equals( request ) ) ) {
734 return true;
735 }
736 return false;
737 }
738
739 /**
740 * returns true if the request is a WMS request
741 *
742 * @param request
743 * @return true if the request is a WMS request
744 */
745 private static boolean isWMSRequest( String request ) {
746 if ( "GetMap".equals( request ) || "map".equals( request ) || "GetFeatureInfo".equals( request )
747 || "feature_info".equals( request ) || "GetLegendGraphic".equals( request )
748 || "GetStyles".equals( request ) || "PutStyles".equals( request ) || "DescribeLayer".equals( request ) ) {
749 return true;
750 }
751 return false;
752 }
753
754 /**
755 * returns true if the request is a WFS request
756 *
757 * @param request
758 * @param doc
759 * @return true if the request is a WFS request
760 */
761 private static boolean isWFSRequest( String request, Document doc ) {
762 if ( doc != null ) {
763 String s = doc.getDocumentElement().getNamespaceURI();
764 if ( CommonNamespaces.WFSNS.toString().equals( s ) ) {
765 return true;
766 }
767 } else {
768 if ( "DescribeFeatureType".equals( request ) || "GetFeature".equals( request )
769 || "GetFeatureWithLock".equals( request ) || "GetGmlObject".equals( request )
770 || "Lock".equals( request ) || "Transaction".equals( request ) ) {
771 return true;
772 }
773 }
774 return false;
775 }
776
777 /**
778 * returns true if the request is a WCS request
779 *
780 * @param request
781 * @return true if the request is a WCS request
782 */
783 private static boolean isWCSRequest( String request ) {
784 if ( "GetCoverage".equals( request ) || "DescribeCoverage".equals( request ) ) {
785 return true;
786 }
787 return false;
788 }
789
790 /**
791 * returns true if the request is a CSW request
792 *
793 * @param request
794 * @return true if the request is a CSW request
795 */
796 private static boolean isCSWRequest( String request, Document doc ) {
797 if ( doc != null ) {
798 String s = doc.getDocumentElement().getNamespaceURI();
799 if ( CommonNamespaces.CSWNS.toString().equals( s ) || CommonNamespaces.CSW202NS.toString().equals( s ) ) {
800 return true;
801 }
802 } else {
803 if ( CatalogueOperationsMetadata.GET_RECORDS_NAME.equals( request )
804 || CatalogueOperationsMetadata.DESCRIBE_RECORD_NAME.equals( request )
805 || CatalogueOperationsMetadata.GET_RECORD_BY_ID_NAME.equals( request )
806 || CatalogueOperationsMetadata.GET_DOMAIN_NAME.equals( request )
807 || CatalogueOperationsMetadata.HARVEST_NAME.equals( request ) ) {
808 return true;
809 }
810 }
811 return false;
812 }
813
814 /**
815 * returns true if the request is a SOS request
816 *
817 * @param request
818 * @return true if the request is a SOS request
819 */
820 private static boolean isSOSRequest( String request ) {
821 if ( "GetObservation".equals( request ) || "DescribeSensor".equals( request )
822 || "DescribePlatform".equals( request ) ) {
823 return true;
824 }
825 return false;
826 }
827
828 /**
829 * returns true if the request is a WPVS request
830 *
831 * @param request
832 * name, e.g. 'GetView'
833 * @return true if the request is a WPVS request
834 */
835 private static boolean isWPVSRequest( String request ) {
836 if ( "GetView".equals( request ) ) {
837 return true;
838 }
839 return false;
840 }
841
842 /**
843 * returns true if the request is a WPS request
844 *
845 * @param request
846 * name, e.g. 'GetCapabilities' name, e.g. 'DescribeProcess', e.g. 'Exceute'
847 * @return true if the request is a WPS request
848 */
849 private static boolean isWPSRequest( String request ) {
850 if ( "DescribeProcess".equals( request ) || "Execute".equals( request ) ) {
851 return true;
852 }
853 return false;
854 }
855
856 /**
857 * returns true if the request is a WAS request
858 *
859 * @param request
860 * name, e.g. 'GetSession' name, e.g. 'CloseSession', e.g. 'GetSAMLResponse'
861 * @return true if and only if the request contains one of the above Strings
862 */
863 private static boolean isWASRequest( String request ) {
864 if ( "GetSession".equals( request ) || "CloseSession".equals( request ) || "GetSAMLResponse".equals( request )
865 || "DescribeUser".equals( request ) ) {
866 return true;
867 }
868 return false;
869 }
870
871 /**
872 * returns true if the request is a WSS request
873 *
874 * @param request
875 * name, e.g. 'GetSession' name, e.g. 'CloseSession', e.g. 'GetSAMLResponse'
876 * @return true if and only if the request contains one of the above Strins
877 */
878 private static boolean isWSSRequest( String request ) {
879 if ( "GetSession".equals( request ) || "CloseSession".equals( request ) || "DoService".equals( request ) ) {
880 return true;
881 }
882 return false;
883 }
884
885 /**
886 * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Object</code>. the returned request will be a
887 * WCS request. The type of request is determind by the the also passed 'request' parameter. Possible requests are:
888 * <ul>
889 * <li>GetCapabilities
890 * <li>GetCoverage
891 * <li>DescribeCoverage
892 * </ul>
893 * <p>
894 * Any other request passed to the method causes an exception to be thrown.
895 * </p>
896 *
897 * @param request
898 * @param req
899 * @return created <code>OGCWebServiceRequest</code>
900 * @throws OGCWebServiceException
901 */
902 @SuppressWarnings("unchecked")
903 private static OGCWebServiceRequest getWMSRequest( String request, Object req )
904 throws OGCWebServiceException {
905 OGCWebServiceRequest ogcRequest = null;
906 String id = "" + IDGenerator.getInstance().generateUniqueID();
907 try {
908 Map<String, String> map = null;
909 if ( req instanceof Map ) {
910 map = (Map<String, String>) req;
911 map.put( "ID", id );
912 }
913 if ( request.equals( "GetCapabilities" ) || "capabilities".equals( request ) ) {
914 if ( map != null ) {
915 // defaulting to 1.1.1 is not possible because of spec requirements
916 // if( ( map.get( "VERSION" ) == null ) && ( map.get( "WMTVER" ) == null ) )
917 // {
918 // map.put( "VERSION", "1.3.0" );
919 // }
920 ogcRequest = WMSGetCapabilities.create( map );
921 }
922 } else if ( request.equals( "GetMap" ) || request.equals( "map" ) ) {
923 if ( map != null ) {
924 ogcRequest = GetMap.create( map );
925 } else {
926 ogcRequest = GetMap.create( id, (Document) req );
927 }
928 } else if ( request.equals( "GetFeatureInfo" ) || request.equals( "feature_info" ) ) {
929 if ( map != null ) {
930 ogcRequest = GetFeatureInfo.create( map );
931 }
932 } else if ( request.equals( "GetLegendGraphic" ) ) {
933 if ( map != null ) {
934 ogcRequest = GetLegendGraphic.create( map );
935 }
936 } else if ( request.equals( "DescribeLayer" ) ) {
937 if ( map != null ) {
938 ogcRequest = DescribeLayer.create( map );
939 }
940 } else {
941 throw new OGCWebServiceException( "Unknown WMS request type: '" + request + "'." );
942 }
943 } catch ( MalformedURLException e ) {
944 LOG.logError( e.getLocalizedMessage(), e );
945 throw new OGCWebServiceException( e.getMessage() );
946 } catch ( XMLParsingException e ) {
947 LOG.logError( e.getLocalizedMessage(), e );
948 throw new OGCWebServiceException( e.getMessage() );
949 }
950 return ogcRequest;
951 }
952
953 /**
954 * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>. the returned request
955 * will be a WCS request. The type of request is determind by the the also passed 'request' parameter. Possible
956 * requests are:
957 * <ul>
958 * <li>GetCapabilities
959 * <li>GetCoverage
960 * <li>DescribeCoverage
961 * </ul>
962 * Any other request passed to the method causes an exception to be thrown.
963 *
964 * @param request
965 * a string describing the request type.
966 * @param req
967 * the kvp-encoded request
968 * @return one of the above mentioned Requests.
969 * @throws OGCWebServiceException
970 * if the requested operation is not one of the above mentioned, or something went wrong while creating
971 * the request.
972 */
973 private static AbstractOGCWebServiceRequest getWCSRequest( String request, Map<String, String> req )
974 throws OGCWebServiceException {
975 AbstractOGCWebServiceRequest ogcRequest = null;
976 String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
977 req.put( "ID", id );
978 if ( request.equals( "GetCapabilities" ) ) {
979 ogcRequest = WCSGetCapabilities.create( req );
980 } else if ( request.equals( "GetCoverage" ) ) {
981 ogcRequest = GetCoverage.create( req );
982 } else if ( request.equals( "DescribeCoverage" ) ) {
983 ogcRequest = DescribeCoverage.create( req );
984 } else {
985 throw new OGCWebServiceException( "Unknown WCS request type: '" + request + "'." );
986 }
987 return ogcRequest;
988 }
989
990 /**
991 * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Docuement</code>. the returned request
992 * will be a WCS request. The type of request is determind by the the also passed 'request' parameter. Possible
993 * requests are:
994 * <ul>
995 * <li>GetCapabilities
996 * <li>GetCoverage
997 * <li>DescribeCoverage
998 * </ul>
999 * Any other request passed to the method causes an exception to be thrown.
1000 *
1001 * @param request
1002 * a string describing the request type.
1003 * @param req
1004 * the XML-encoded request
1005 * @return one of the above mentioned Requests.
1006 * @throws OGCWebServiceException
1007 * if the requested operation is not one of the above mentioned, or something went wrong while creating
1008 * the request.
1009 */
1010 private static AbstractOGCWebServiceRequest getWCSRequest( String request, Document req )
1011 throws OGCWebServiceException {
1012 AbstractOGCWebServiceRequest ogcRequest = null;
1013 String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
1014 if ( request.equals( "GetCapabilities" ) ) {
1015 ogcRequest = WCSGetCapabilities.create( id, req );
1016 } else if ( request.equals( "GetCoverage" ) ) {
1017 ogcRequest = GetCoverage.create( id, req );
1018 } else if ( request.equals( "DescribeCoverage" ) ) {
1019 ogcRequest = DescribeCoverage.create( id, req );
1020 } else {
1021 throw new OGCWebServiceException( "Unknown WCS request type: '" + request + "'." );
1022 }
1023 return ogcRequest;
1024 }
1025
1026 /**
1027 * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>. The returned request
1028 * will be a <code>CSW</code> request. The type of request is determined by the the also passed 'request' parameter.
1029 * Allowed values for the request parameter are:
1030 * <ul>
1031 * <li>GetCapabilities</li>
1032 * <li>GetRecords</li>
1033 * <li>GetRecordsByID</li>
1034 * <li>DescribeRecord</li>
1035 * <li>GetDomain, will cause an exception to be thrown</li>
1036 * <li>Transaction, will cause an exception to be thrown</li>
1037 * <li>Harvest</li>
1038 * </ul>
1039 *
1040 * Any other request passed to the method causes an exception to be thrown.
1041 *
1042 * @param request
1043 * a string describing the request type.
1044 * @param req
1045 * the KVP-encoded request
1046 * @return one of the above mentioned Requests.
1047 * @throws OGCWebServiceException
1048 * if the requested operation is not one of the above mentioned, not supported or something went wrong
1049 * while creating the request.
1050 */
1051 private static AbstractOGCWebServiceRequest getCSWRequest( String request, Map<String, String> req )
1052 throws OGCWebServiceException {
1053 AbstractOGCWebServiceRequest ogcRequest = null;
1054 String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
1055 LOG.logDebug( StringTools.concat( 200, "Creating CSW request '", request, "' with ID=", id, "/type:",
1056 req.getClass().getName() ) );
1057
1058 if ( OperationsMetadata.GET_CAPABILITIES_NAME.equals( request ) ) {
1059 req.put( "ID", id );
1060 ogcRequest = CatalogueGetCapabilities.create( req );
1061 } else if ( CatalogueOperationsMetadata.GET_RECORDS_NAME.equals( request ) ) {
1062 req.put( "ID", id );
1063 ogcRequest = GetRecords.create( req );
1064 } else if ( CatalogueOperationsMetadata.GET_RECORD_BY_ID_NAME.equals( request ) ) {
1065 // req.put( "ID", id );
1066 ogcRequest = GetRecordById.create( id, req );
1067 } else if ( CatalogueOperationsMetadata.GET_REPOSITORY_ITEM.equals( request ) ) {
1068 req.put( "REQUESTID", id );
1069 ogcRequest = GetRepositoryItem.create( req );
1070 } else if ( CatalogueOperationsMetadata.DESCRIBE_RECORD_NAME.equals( request ) ) {
1071 req.put( "ID", id );
1072 ogcRequest = DescribeRecord.create( req );
1073 } else if ( CatalogueOperationsMetadata.GET_DOMAIN_NAME.equals( request ) ) {
1074 // TODO
1075 throw new OGCWebServiceException( CatalogueOperationsMetadata.TRANSACTION_NAME + " is not supported." );
1076 } else if ( CatalogueOperationsMetadata.TRANSACTION_NAME.equals( request ) ) {
1077 throw new OGCWebServiceException( CatalogueOperationsMetadata.TRANSACTION_NAME
1078 + " through HTTP Get is not supported." );
1079 } else if ( CatalogueOperationsMetadata.HARVEST_NAME.equals( request ) ) {
1080 req.put( "ID", id );
1081 ogcRequest = Harvest.create( req );
1082 } else {
1083 throw new OGCWebServiceException( "Unknown CSW request type: '" + request + "'." );
1084 }
1085 LOG.logDebug( "CSW request created: " + ogcRequest );
1086 return ogcRequest;
1087 }
1088
1089 /**
1090 * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>. The returned request
1091 * will be a <code>CSW</code> request. The type of request is determined by the the also passed 'request' parameter.
1092 * Allowed values for the request parameter are:
1093 * <ul>
1094 * <li>GetCapabilities</li>
1095 * <li>GetRecords</li>
1096 * <li>GetRecordsByID</li>
1097 * <li>DescribeRecord</li>
1098 * <li>GetDomain, will cause an exception to be thrown</li>
1099 * <li>Transaction</li>
1100 * <li>Harvest, will cause an exception to be thrown</li>
1101 * </ul>
1102 *
1103 * Any other request passed to the method causes an exception to be thrown.
1104 *
1105 * @param request
1106 * a string describing the request type.
1107 * @param req
1108 * the XML-encoded request
1109 * @return one of the above mentioned Requests.
1110 * @throws OGCWebServiceException
1111 * if the requested operation is not one of the above mentioned, or something went wrong while creating
1112 * the request.
1113 */
1114 private static AbstractOGCWebServiceRequest getCSWRequest( String request, Document req )
1115 throws OGCWebServiceException {
1116 AbstractOGCWebServiceRequest ogcRequest = null;
1117 String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
1118 LOG.logDebug( StringTools.concat( 200, "Creating CSW request '", request, "' with ID=", id, "/type:",
1119 req.getClass().getName() ) );
1120 Element docElem = req.getDocumentElement();
1121 if ( OperationsMetadata.GET_CAPABILITIES_NAME.equals( request ) ) {
1122 ogcRequest = CatalogueGetCapabilities.create( id, docElem );
1123 } else if ( CatalogueOperationsMetadata.GET_RECORDS_NAME.equals( request ) ) {
1124 ogcRequest = GetRecords.create( id, docElem );
1125 } else if ( CatalogueOperationsMetadata.GET_RECORD_BY_ID_NAME.equals( request ) ) {
1126 ogcRequest = GetRecordById.create( id, docElem );
1127 } else if ( CatalogueOperationsMetadata.GET_REPOSITORY_ITEM.equals( request ) ) {
1128 throw new OGCWebServiceException( CatalogueOperationsMetadata.GET_REPOSITORY_ITEM + " is not supported." );
1129 } else if ( CatalogueOperationsMetadata.DESCRIBE_RECORD_NAME.equals( request ) ) {
1130 ogcRequest = DescribeRecord.create( id, docElem );
1131 } else if ( CatalogueOperationsMetadata.GET_DOMAIN_NAME.equals( request ) ) {
1132 // TODO
1133 throw new OGCWebServiceException( CatalogueOperationsMetadata.TRANSACTION_NAME + " is not supported." );
1134 } else if ( CatalogueOperationsMetadata.TRANSACTION_NAME.equals( request ) ) {
1135 ogcRequest = org.deegree.ogcwebservices.csw.manager.Transaction.create( id, docElem );
1136 } else if ( CatalogueOperationsMetadata.HARVEST_NAME.equals( request ) ) {
1137 throw new OGCWebServiceException( CatalogueOperationsMetadata.HARVEST_NAME
1138 + " through HTTP post is not supported." );
1139 } else {
1140 throw new OGCWebServiceException( "Unknown CSW request type: '" + request + "'." );
1141 }
1142 LOG.logDebug( "CSW request created: " + ogcRequest );
1143 return ogcRequest;
1144 }
1145
1146
1147 /**
1148 * Creates an <code>OGCWebServiceRequest</code> from the passed <code>XML-Document</code>. the returned request will
1149 * be a WPVS request. The type of request is determind by the the also passed 'request' parameter. Possible requests
1150 * are:
1151 * <ul>
1152 * <li>GetCapabilities
1153 * <li>GetView
1154 * </ul>
1155 * <p>
1156 * Any other request passed to the method causes an exception to be thrown.
1157 * </p>
1158 *
1159 * @param requestName
1160 * name of the request, one of GetCapabilities or GetView
1161 * @param request
1162 * the request as an xml document
1163 * @return created <code>OGCWebServiceRequest</code>
1164 * @throws OGCWebServiceException
1165 */
1166 @SuppressWarnings("unused")
1167 private static OGCWebServiceRequest getWPVSRequest( String requestName, Document request )
1168 throws OGCWebServiceException {
1169 OGCWebServiceRequest ogcRequest = null;
1170 String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
1171
1172 if ( OperationsMetadata.GET_CAPABILITIES_NAME.equals( requestName ) ) {
1173 // ogcRequest = WPVSGetCapabilities.create(id, (Document) req);
1174 } else if ( "GetView".equals( requestName ) ) {
1175 // ogcRequest = GetView.create( req );
1176 } else {
1177 throw new OGCWebServiceException( "Unknown WPVS request type: '" + requestName + "'." );
1178 }
1179 return ogcRequest;
1180 }
1181
1182 /**
1183 * Creates an <code>OGCWebServiceRequest</code> from the passed <code>KVP-Map</code>. the returned request will be a
1184 * WPVS request. The type of request is determind by the the also passed 'request' parameter. Possible requests are:
1185 * <ul>
1186 * <li>GetCapabilities
1187 * <li>GetView
1188 * </ul>
1189 * <p>
1190 * Any other request passed to the method causes an exception to be thrown.
1191 * </p>
1192 *
1193 * @param requestName
1194 * name of the request, one of GetCapabilities or GetView
1195 * @param request
1196 * the actual parameters of the request
1197 * @return created <code>OGCWebServiceRequest</code>
1198 * @throws OGCWebServiceException
1199 */
1200 private static OGCWebServiceRequest getWPVSRequest( String requestName, Map<String, String> request )
1201 throws OGCWebServiceException {
1202 OGCWebServiceRequest ogcRequest = null;
1203 String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
1204
1205 if ( OperationsMetadata.GET_CAPABILITIES_NAME.equals( requestName ) ) {
1206 request.put( "ID", id );
1207 ogcRequest = WPVSGetCapabilities.create( request );
1208 } else if ( "GetView".equals( requestName ) ) {
1209 ogcRequest = GetView.create( request );
1210 } else if ( "Get3DFeatureInfo".equals( requestName ) ) {
1211 ogcRequest = Get3DFeatureInfo.create( request );
1212 } else {
1213 throw new OGCWebServiceException( "Unknown WPVS request type: '" + requestName + "'." );
1214 }
1215 return ogcRequest;
1216 }
1217
1218 /**
1219 * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>. the returned request
1220 * will be a WMPS request. The type of request is determind by the the also passed 'request' parameter. Possible
1221 * requests are:
1222 * <ul>
1223 * <li>GetCapabilities
1224 * </ul>
1225 * Any other request passed to the method causes an exception to be thrown.
1226 *
1227 * @param request
1228 * @param doc
1229 * @param req
1230 * @return created <code>OGCWebServiceRequest</code>
1231 * @throws OGCWebServiceException
1232 * @throws OGCWebServiceException
1233 */
1234 private static OGCWebServiceRequest getWMPSRequest( String request, Document doc )
1235 throws OGCWebServiceException {
1236 OGCWebServiceRequest ogcRequest = null;
1237
1238 if ( request.equals( "PrintMap" ) ) {
1239 try {
1240 ogcRequest = PrintMap.create( doc.getDocumentElement() );
1241 } catch ( Exception e ) {
1242 throw new OGCWebServiceException( "Error creating a Print Map object for the request '" + request
1243 + "'. " + e.getMessage() );
1244 }
1245 } else if ( request.equals( "GetAvailableTemplates" ) ) {
1246 try {
1247 ogcRequest = GetAvailableTemplates.create( doc.getDocumentElement() );
1248 } catch ( Exception e ) {
1249 throw new OGCWebServiceException( "Error creating a GetAvailableTemplates object for the request '"
1250 + request + "'. " + e.getMessage() );
1251 }
1252 } else if ( request.equals( "DescribeTemplate" ) ) {
1253 try {
1254 ogcRequest = DescribeTemplate.create( doc.getDocumentElement() );
1255 } catch ( Exception e ) {
1256 throw new OGCWebServiceException( "Error creating a DescribeTemplate object for the request '"
1257 + request + "'. " + e.getMessage() );
1258 }
1259 } else {
1260 throw new OGCWebServiceException( "Unknown / unimplemented WMPS request type: '" + request + "'." );
1261 }
1262 return ogcRequest;
1263 }
1264
1265 /**
1266 * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>. the returned request
1267 * will be a WMPS request. The type of request is determind by the the also passed 'request' parameter. Possible
1268 * requests are:
1269 * <ul>
1270 * <li>GetCapabilities
1271 * </ul>
1272 * Any other request passed to the method causes an exception to be thrown.
1273 *
1274 * @param request
1275 * @param map
1276 * @param req
1277 * @return OGCWebServiceRequest
1278 * @throws InconsistentRequestException
1279 * @throws InvalidParameterValueException
1280 * @throws OGCWebServiceException
1281 */
1282 private static OGCWebServiceRequest getWMPSRequest( String request, Map<String, String> map )
1283 throws InconsistentRequestException, InvalidParameterValueException {
1284 OGCWebServiceRequest ogcRequest = null;
1285 map.put( "ID", "" + IDGenerator.getInstance().generateUniqueID() );
1286 if ( request.equals( "GetCapabilities" ) ) {
1287 ogcRequest = WMPSGetCapabilities.create( map );
1288 } else if ( request.equals( "PrintMap" ) ) {
1289 ogcRequest = PrintMap.create( map );
1290 } else if ( request.equals( "DescribeTemplate" ) ) {
1291 ogcRequest = DescribeTemplate.create( map );
1292 } else if ( request.equals( "GetAvailableTemplates" ) ) {
1293 ogcRequest = GetAvailableTemplates.create( map );
1294 } else {
1295 throw new InvalidParameterValueException( "Unknown WMPS request type: '" + request + "'." );
1296 }
1297 return ogcRequest;
1298 }
1299
1300 /**
1301 * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Map</code>. The returned request will be a WPS
1302 * request. The type of request is determined by also submitted request name. Known requests are:
1303 * <ul>
1304 * <li>GetCapabilities</li>
1305 * <li>DescribeProcess</li>
1306 * <li>Execute</li>
1307 * </ul>
1308 * <p>
1309 * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
1310 * </p>
1311 *
1312 * @param request
1313 * @param map
1314 * @return created <code>OGCWebServiceRequest</code>
1315 * @throws OGCWebServiceException
1316 */
1317 private static OGCWebServiceRequest getWPSRequest( String request, Map<String, String> map )
1318 throws OGCWebServiceException {
1319 OGCWebServiceRequest ogcRequest = null;
1320 map.put( "ID", "" + IDGenerator.getInstance().generateUniqueID() );
1321 if ( "GetCapabilities".equals( request ) ) {
1322 ogcRequest = WPSGetCapabilities.create( map );
1323 } else if ( "DescribeProcess".equals( request ) ) {
1324 ogcRequest = DescribeProcessRequest.create( map );
1325 } else if ( "Execute".equals( request ) ) {
1326 ogcRequest = ExecuteRequest.create( map );
1327 } else {
1328 throw new InvalidParameterValueException( "Unknown WPS request type: '" + request + "'." );
1329 }
1330 return ogcRequest;
1331 }
1332
1333 /**
1334 * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The returned request will be
1335 * a WPS request. The type of request is determined by also submitted request name. Known requests are:
1336 * <ul>
1337 * <li>GetCapabilities</li>
1338 * <li>DescribeProcess</li>
1339 * <li>Execute</li>
1340 * </ul>
1341 * <p>
1342 * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
1343 * </p>
1344 *
1345 * @param request
1346 * @param doc
1347 * @return created <code>OGCWebServiceRequest</code>
1348 * @throws OGCWebServiceException
1349 */
1350 private static OGCWebServiceRequest getWPSRequest( String request, Document doc )
1351 throws OGCWebServiceException {
1352 OGCWebServiceRequest ogcRequest = null;
1353 String id = "" + IDGenerator.getInstance().generateUniqueID();
1354 if ( "GetCapabilities".equals( request ) ) {
1355 ogcRequest = WPSGetCapabilities.create( id, doc.getDocumentElement() );
1356 } else if ( "DescribeProcess".equals( request ) ) {
1357 ogcRequest = DescribeProcessRequest.create( id, doc.getDocumentElement() );
1358
1359 } else if ( "Execute".equals( request ) ) {
1360 ogcRequest = ExecuteRequest.create( id, doc.getDocumentElement() );
1361
1362 } else {
1363 throw new OGCWebServiceException( "Unknown WPS request type: '" + request + "'." );
1364 }
1365 return ogcRequest;
1366 }
1367
1368 /**
1369 * @param request
1370 * containing the local-name of the top root element.
1371 * @param doc
1372 * @return
1373 * @throws IllegalArgumentException
1374 * @throws OGCWebServiceException
1375 */
1376 private static OGCWebServiceRequest getWCTSRequest( String request, Document doc )
1377 throws OGCWebServiceException, IllegalArgumentException {
1378 OGCWebServiceRequest result = null;
1379 String requestID = Long.toString( IDGenerator.getInstance().generateUniqueID() );
1380 if ( "GetResourceByID".equals( request ) ) {
1381 result = new GetResourceByIDDocument( requestID, doc.getDocumentElement() ).getResourceById();
1382 } else if ( "GetCapabilities".equals( request ) ) {
1383 result = new WCTSGetCapabilitiesDocument( requestID, doc.getDocumentElement() ).getGetCapabilities();
1384 } else if ( "Transform".equals( request ) ) {
1385 result = new TransformDocument( requestID, doc.getDocumentElement() ).getTransformRequest();
1386 } else if ( "IsTransformable".equals( request ) ) {
1387 result = new IsTransformableDocument( requestID, doc.getDocumentElement() ).getIsTransformable();
1388 } else if ( "GetTransformation".equals( request ) ) {
1389 throw new OGCWebServiceException( "GetTransformation requests are currently not supported by the WCTS",
1390 ExceptionCode.OPERATIONNOTSUPPORTED );
1391 // result = new Document(requestID, doc.getDocumentElement() ).getIsTransformable();
1392 } else {
1393 throw new OGCWebServiceException( request + " is not known to the WCTS",
1394 ExceptionCode.OPERATIONNOTSUPPORTED );
1395 }
1396 return result;
1397 }
1398
1399 /**
1400 * @param request
1401 * @param map
1402 * @return
1403 * @throws OGCWebServiceException
1404 */
1405 private static OGCWebServiceRequest getWCTSRequest( String request, Map<String, String> map )
1406 throws OGCWebServiceException {
1407 OGCWebServiceRequest result = null;
1408 String requestID = Long.toString( IDGenerator.getInstance().generateUniqueID() );
1409 if ( "GetResourceByID".equals( request ) ) {
1410 result = GetResourceByID.create( requestID, map );
1411 } else if ( "GetCapabilities".equals( request ) ) {
1412 result = WCTSGetCapabilities.create( requestID, map );
1413 } else if ( "Transform".equals( request ) ) {
1414 result = Transform.create( requestID, map );
1415 } else if ( "IsTransformable".equals( request ) ) {
1416 result = IsTransformable.create( requestID, map );
1417 } else if ( "GetTransformation".equals( request ) ) {
1418 throw new OGCWebServiceException( "GetTransformation requests are currently not supported by the WCTS",
1419 ExceptionCode.OPERATIONNOTSUPPORTED );
1420 // result = new Document(requestID, doc.getDocumentElement() ).getIsTransformable();
1421 } else {
1422 throw new OGCWebServiceException( request + " is not known to the WCTS",
1423 ExceptionCode.OPERATIONNOTSUPPORTED );
1424 }
1425 return result;
1426 }
1427
1428 }