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