0001: // $HeadURL:
0002: // /cvsroot/deegree/src/org/deegree/ogcwebservices/OGCRequestFactory.java,v 1.12
0003: // 2004/08/10 17:17:02 tf Exp $
0004: /*---------------- FILE HEADER ------------------------------------------
0005:
0006: This file is part of deegree.
0007: Copyright (C) 2001-2008 by:
0008: EXSE, Department of Geography, University of Bonn
0009: http://www.giub.uni-bonn.de/deegree/
0010: lat/lon GmbH
0011: http://www.lat-lon.de
0012:
0013: This library is free software; you can redistribute it and/or
0014: modify it under the terms of the GNU Lesser General Public
0015: License as published by the Free Software Foundation; either
0016: version 2.1 of the License, or (at your option) any later version.
0017:
0018: This library is distributed in the hope that it will be useful,
0019: but WITHOUT ANY WARRANTY; without even the implied warranty of
0020: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0021: Lesser General Public License for more details.
0022:
0023: You should have received a copy of the GNU Lesser General Public
0024: License along with this library; if not, write to the Free Software
0025: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0026:
0027: Contact:
0028:
0029: Andreas Poth
0030: lat/lon GmbH
0031: Aennchenstr. 19
0032: 53177 Bonn
0033: Germany
0034: E-Mail: poth@lat-lon.de
0035:
0036: Prof. Dr. Klaus Greve
0037: Department of Geography
0038: University of Bonn
0039: Meckenheimer Allee 166
0040: 53115 Bonn
0041: Germany
0042: E-Mail: greve@giub.uni-bonn.de
0043:
0044:
0045: ---------------------------------------------------------------------------*/
0046: package org.deegree.ogcwebservices;
0047:
0048: import java.io.BufferedReader;
0049: import java.io.IOException;
0050: import java.io.InputStreamReader;
0051: import java.io.StringReader;
0052: import java.io.UnsupportedEncodingException;
0053: import java.net.MalformedURLException;
0054: import java.net.URLDecoder;
0055: import java.util.HashMap;
0056: import java.util.Map;
0057:
0058: import javax.servlet.ServletRequest;
0059: import javax.servlet.http.HttpServletRequest;
0060:
0061: import org.deegree.framework.log.ILogger;
0062: import org.deegree.framework.log.LoggerFactory;
0063: import org.deegree.framework.util.CharsetUtils;
0064: import org.deegree.framework.util.IDGenerator;
0065: import org.deegree.framework.util.StringTools;
0066: import org.deegree.framework.xml.XMLFragment;
0067: import org.deegree.framework.xml.XMLParsingException;
0068: import org.deegree.framework.xml.XMLTools;
0069: import org.deegree.ogcbase.CommonNamespaces;
0070: import org.deegree.ogcbase.ExceptionCode;
0071: import org.deegree.ogcwebservices.csw.capabilities.CatalogueGetCapabilities;
0072: import org.deegree.ogcwebservices.csw.capabilities.CatalogueOperationsMetadata;
0073: import org.deegree.ogcwebservices.csw.discovery.DescribeRecord;
0074: import org.deegree.ogcwebservices.csw.discovery.GetRecordById;
0075: import org.deegree.ogcwebservices.csw.discovery.GetRecords;
0076: import org.deegree.ogcwebservices.csw.discovery.GetRepositoryItem;
0077: import org.deegree.ogcwebservices.csw.manager.Harvest;
0078: import org.deegree.ogcwebservices.getcapabilities.OperationsMetadata;
0079: import org.deegree.ogcwebservices.sos.capabilities.SOSGetCapabilities;
0080: import org.deegree.ogcwebservices.sos.capabilities.SOSOperationsMetadata;
0081: import org.deegree.ogcwebservices.sos.describeplatform.DescribePlatformRequest;
0082: import org.deegree.ogcwebservices.sos.describesensor.DescribeSensorRequest;
0083: import org.deegree.ogcwebservices.sos.getobservation.GetObservationRequest;
0084: import org.deegree.ogcwebservices.wass.common.CloseSession;
0085: import org.deegree.ogcwebservices.wass.common.GetSession;
0086: import org.deegree.ogcwebservices.wass.was.operation.DescribeUser;
0087: import org.deegree.ogcwebservices.wass.was.operation.WASGetCapabilities;
0088: import org.deegree.ogcwebservices.wass.wss.operation.DoService;
0089: import org.deegree.ogcwebservices.wass.wss.operation.WSSGetCapabilities;
0090: import org.deegree.ogcwebservices.wcs.describecoverage.DescribeCoverage;
0091: import org.deegree.ogcwebservices.wcs.getcapabilities.WCSGetCapabilities;
0092: import org.deegree.ogcwebservices.wcs.getcoverage.GetCoverage;
0093: import org.deegree.ogcwebservices.wcts.operation.GetResourceByID;
0094: import org.deegree.ogcwebservices.wcts.operation.GetResourceByIDDocument;
0095: import org.deegree.ogcwebservices.wcts.operation.IsTransformable;
0096: import org.deegree.ogcwebservices.wcts.operation.IsTransformableDocument;
0097: import org.deegree.ogcwebservices.wcts.operation.Transform;
0098: import org.deegree.ogcwebservices.wcts.operation.TransformDocument;
0099: import org.deegree.ogcwebservices.wcts.operation.WCTSGetCapabilities;
0100: import org.deegree.ogcwebservices.wcts.operation.WCTSGetCapabilitiesDocument;
0101: import org.deegree.ogcwebservices.wfs.operation.DescribeFeatureType;
0102: import org.deegree.ogcwebservices.wfs.operation.GetFeature;
0103: import org.deegree.ogcwebservices.wfs.operation.GetFeatureWithLock;
0104: import org.deegree.ogcwebservices.wfs.operation.LockFeature;
0105: import org.deegree.ogcwebservices.wfs.operation.WFSGetCapabilities;
0106: import org.deegree.ogcwebservices.wfs.operation.transaction.Transaction;
0107: import org.deegree.ogcwebservices.wmps.operation.PrintMap;
0108: import org.deegree.ogcwebservices.wmps.operation.WMPSGetCapabilities;
0109: import org.deegree.ogcwebservices.wms.operation.DescribeLayer;
0110: import org.deegree.ogcwebservices.wms.operation.GetFeatureInfo;
0111: import org.deegree.ogcwebservices.wms.operation.GetLegendGraphic;
0112: import org.deegree.ogcwebservices.wms.operation.GetMap;
0113: import org.deegree.ogcwebservices.wms.operation.WMSGetCapabilities;
0114: import org.deegree.ogcwebservices.wps.capabilities.WPSGetCapabilities;
0115: import org.deegree.ogcwebservices.wps.describeprocess.DescribeProcessRequest;
0116: import org.deegree.ogcwebservices.wps.execute.ExecuteRequest;
0117: import org.deegree.ogcwebservices.wpvs.operation.Get3DFeatureInfo;
0118: import org.deegree.ogcwebservices.wpvs.operation.GetView;
0119: import org.deegree.ogcwebservices.wpvs.operation.WPVSGetCapabilities;
0120: import org.w3c.dom.Document;
0121: import org.w3c.dom.Element;
0122: import org.xml.sax.SAXException;
0123:
0124: /**
0125: * Factory for generating request objects for OGC Web Services.
0126: * <p>
0127: * Requests may be generated from KVP or DOM representations. Also contains methods that decide whether an incoming
0128: * request representation is valid for a certain service.
0129: * </p>
0130: * Currently supported services are:
0131: * <ul>
0132: * <li>CSW</li>
0133: * <li>WFS</li>
0134: * <li>WCS</li>
0135: * <li>WMS</li>
0136: * <li>WFS-G</li>
0137: * <li>SOS</li>
0138: * <li>WMPS</li>
0139: * <li>WSS</li>
0140: * <li>WAS</li>
0141: * <li>WPVS</li>
0142: * </ul>
0143: *
0144: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
0145: * @author last edited by: $Author: rbezema $
0146: *
0147: * @version $Revision: 10401 $, $Date: 2008-03-04 08:21:54 -0800 (Tue, 04 Mar 2008) $
0148: */
0149: public class OGCRequestFactory {
0150:
0151: private static final ILogger LOG = LoggerFactory
0152: .getLogger(OGCRequestFactory.class);
0153:
0154: private static final String CSW_SERVICE_NAME = "CSW";
0155:
0156: /**
0157: * The service name of a getRepositoryItem request, only valid for the csw/ebrim. Fixed value:
0158: * "urn:x-ogc:specification:cswebrim:Service:OGC-CSW:ebRIM"
0159: */
0160: public static final String CSW_SERVICE_NAME_EBRIM = "urn:x-ogc:specification:cswebrim:Service:OGC-CSW:ebRIM";
0161:
0162: private static final String WFS_SERVICE_NAME = "WFS";
0163:
0164: private static final String WCS_SERVICE_NAME = "WCS";
0165:
0166: private static final String WMS_SERVICE_NAME = "WMS";
0167:
0168: private static final String SOS_SERVICE_NAME = "SOS";
0169:
0170: private static final String WPVS_SERVICE_NAME = "WPVS";
0171:
0172: private static final String WMPS_SERVICE_NAME = "WMPS";
0173:
0174: private static final String WPS_SERVICE_NAME = "WPS";
0175:
0176: private static final String WSS_SERVICE_NAME = "WSS";
0177:
0178: private static final String WAS_SERVICE_NAME = "WAS";
0179:
0180: private static final String WCTS_SERVICE_NAME = "WCTS";
0181:
0182: /**
0183: * Creates an <code>OGCWebServiceRequest</code> from the content contained within the passed request.
0184: *
0185: * @param request
0186: * @return the request object
0187: * @throws OGCWebServiceException
0188: */
0189: public static OGCWebServiceRequest create(ServletRequest request)
0190: throws OGCWebServiceException {
0191:
0192: // according to javax.servlet.* documentation, the type is correct
0193: Map<String, String[]> map = request.getParameterMap();
0194: Map<String, String> result = new HashMap<String, String>();
0195: for (String key : map.keySet()) {
0196: String[] tmp = map.get(key);
0197: for (int i = 0; i < tmp.length; i++) {
0198: tmp[i] = tmp[i].trim();
0199: }
0200: result.put(key.toUpperCase(), StringTools.arrayToString(
0201: tmp, ','));
0202: }
0203:
0204: LOG.logDebug("Request parameters: " + result);
0205:
0206: if (map.size() != 0) {
0207: return createFromKVP(result);
0208: }
0209:
0210: XMLFragment fragment = null;
0211: try {
0212: if (request.getContentType() != null) {
0213: fragment = new XMLFragment(request.getReader(),
0214: XMLFragment.DEFAULT_URL);
0215: } else {
0216: // DO NOT REMOVE THIS !!!!!
0217: // IT IS ABSOLUTLY NECESSARY TO ENSURE CORRECT CHARACTER ENCODING !!!
0218: StringReader sr = new StringReader(
0219: getRequestContent((HttpServletRequest) request));
0220: fragment = new XMLFragment(sr, XMLFragment.DEFAULT_URL);
0221: }
0222: } catch (SAXException se) {
0223: if (se != null) {
0224: String message = se.getMessage();
0225: if (message != null) {
0226: if (message.contains("not allowed in prolog")) {
0227: throw new OGCWebServiceException(
0228: "OGCRequestFactory",
0229: "No key-value pairs were given and the request does not contain parsable xml",
0230: ExceptionCode.NOAPPLICABLECODE);
0231: }
0232: throw new OGCWebServiceException(
0233: "OGCRequestFactory",
0234: "Error parsing XML request: " + message,
0235: ExceptionCode.NOAPPLICABLECODE);
0236: }
0237: }
0238: throw new OGCWebServiceException("OGCRequestFactory",
0239: "Error parsing XML request",
0240: ExceptionCode.NOAPPLICABLECODE);
0241: } catch (Exception e) {
0242: LOG.logDebug(
0243: "Error parsing XML request: " + e.getMessage(), e);
0244: throw new OGCWebServiceException("OGCRequestFactory",
0245: "Error parsing XML request: " + e.getMessage());
0246: }
0247: Document doc = fragment.getRootElement().getOwnerDocument();
0248:
0249: return createFromXML(doc);
0250: }
0251:
0252: /**
0253: * DO NOT REMOVE THIS !!!!! IT IS ABSOLUTLY NECESSARY TO ENSURE CORRECT CHARACTER ENCODING !!!
0254: *
0255: * @param request
0256: * @return
0257: * @throws IOException
0258: */
0259: private static String getRequestContent(HttpServletRequest request)
0260: throws IOException {
0261: String method = request.getMethod();
0262:
0263: if (method.equalsIgnoreCase("POST")) {
0264: String charset = request.getCharacterEncoding();
0265: LOG.logDebug("posted character encoding: ", charset);
0266: if (charset == null) {
0267: charset = "UTF-8";
0268: }
0269: StringBuffer req = readPost(request, charset);
0270: if (charset.equalsIgnoreCase(CharsetUtils
0271: .getSystemCharset())) {
0272: return req.toString();
0273: }
0274: if (charset.equalsIgnoreCase("UTF-8")
0275: && !charset.equalsIgnoreCase(CharsetUtils
0276: .getSystemCharset())) {
0277: String s = new String(req.toString().getBytes(),
0278: CharsetUtils.getSystemCharset());
0279: return s;
0280: }
0281: if (!charset.equalsIgnoreCase("UTF-8")
0282: && !charset.equalsIgnoreCase(CharsetUtils
0283: .getSystemCharset())) {
0284: String s = new String(req.toString().getBytes(),
0285: "UTF-8");
0286: return s;
0287: }
0288: return req.toString();
0289: }
0290:
0291: String req = request.getQueryString();
0292: if (req == null) {
0293: req = readPost(request, CharsetUtils.getSystemCharset())
0294: .toString();
0295: }
0296: LOG.logDebug("request string: ", req);
0297:
0298: return URLDecoder.decode(req, CharsetUtils.getSystemCharset());
0299:
0300: }
0301:
0302: /**
0303: * DO NOT REMOVE THIS !!!!! IT IS ABSOLUTLY NECESSARY TO ENSURE CORRECT CHARACTER ENCODING !!!
0304: *
0305: * @param request
0306: * @param charset
0307: * @return
0308: * @throws UnsupportedEncodingException
0309: * @throws IOException
0310: */
0311: private static StringBuffer readPost(HttpServletRequest request,
0312: String charset) throws UnsupportedEncodingException,
0313: IOException {
0314: java.io.Reader reader = new InputStreamReader(request
0315: .getInputStream(), charset);
0316: BufferedReader br = new BufferedReader(reader);
0317: StringBuffer req = new StringBuffer(10000);
0318: for (String line = null; (line = br.readLine()) != null;) {
0319: req.append((new StringBuilder(String.valueOf(line)))
0320: .append("\n").toString());
0321: }
0322:
0323: br.close();
0324: return req;
0325: }
0326:
0327: /**
0328: * Creates an instance of an <code>AbstractOGCWebServiceRequest</code> from the passed DOM object. Supported OWS
0329: * are 'WMS', 'WFS', 'WCS' and 'CSW'. If a request for another service is passed or a request that isn't supported
0330: * by one of the listed services an exception will be thrown. <BR>
0331: * Notice that not all listed services will support request processing by reading the request to be performed from a
0332: * DOM object. In this case also an exception will be thrown even if the same request may can be performed if KVP is
0333: * used.
0334: *
0335: * @param doc
0336: * @return the request object
0337: * @throws OGCWebServiceException
0338: */
0339: public static OGCWebServiceRequest createFromXML(Document doc)
0340: throws OGCWebServiceException {
0341:
0342: if (LOG.getLevel() == ILogger.LOG_DEBUG) {
0343: XMLFragment xml = new XMLFragment();
0344: xml.setRootElement(doc.getDocumentElement());
0345: LOG.logDebug("XML request (pretty printed): ", xml
0346: .getAsPrettyString());
0347: }
0348:
0349: String service = XMLTools.getAttrValue(
0350: doc.getDocumentElement(), null, "service", null);
0351: String request = doc.getDocumentElement().getLocalName();
0352: service = getTargetService(service, request, doc);
0353: if ("unknown".equals(service)) {
0354: throw new OGCWebServiceException("OGCRequestFactory",
0355: "Specified service '" + service
0356: + "' is not a known OGC service type.");
0357: }
0358: OGCWebServiceRequest ogcRequest = null;
0359: if (request == null) {
0360: throw new OGCWebServiceException(
0361: "Request parameter must be set!");
0362: } else if (WMS_SERVICE_NAME.equals(service)) {
0363: ogcRequest = getWMSRequest(request, doc);
0364: } else if (WFS_SERVICE_NAME.equals(service)) {
0365: ogcRequest = getWFSRequest(request, doc);
0366: } else if (WCS_SERVICE_NAME.equals(service)) {
0367: ogcRequest = getWCSRequest(request, doc);
0368: } else if (CSW_SERVICE_NAME.equals(service)) {
0369: ogcRequest = getCSWRequest(request, doc);
0370: } else if (SOS_SERVICE_NAME.equals(service)) {
0371: ogcRequest = getSOSRequest(request, doc);
0372: } else if (WPVS_SERVICE_NAME.equals(service)) {
0373: ogcRequest = getSOSRequest(request, doc);
0374: } else if (WMPS_SERVICE_NAME.equals(service)) {
0375: ogcRequest = getWMPSRequest(request, doc);
0376: } else if (WPS_SERVICE_NAME.equals(service)) {
0377: ogcRequest = getWPSRequest(request, doc);
0378: } else if (WSS_SERVICE_NAME.equals(service)) {
0379: ogcRequest = getWSSRequest(request, doc);
0380: } else if (WAS_SERVICE_NAME.equals(service)) {
0381: ogcRequest = getWASRequest(request, doc);
0382: } else if (WCTS_SERVICE_NAME.equals(service)) {
0383: ogcRequest = getWCTSRequest(request, doc);
0384: } else {
0385: throw new OGCWebServiceException("OGCRequestFactory",
0386: "No handler for service " + service
0387: + " in OGCRequestFactory.");
0388: }
0389: return ogcRequest;
0390: }
0391:
0392: /**
0393: * Creates an instance of an <code>AbstractOGCWebServiceRequest</code> from the passed KVP encoded request.
0394: * Supported OWS are 'WMS', 'WFS', 'WCS' and 'CSW'. If a request for another service is passed or a request that
0395: * isn't supported by one of the listed services an exception will be thrown. <BR>
0396: * Notice that not all listed services will support request processing by reading the request to be performed from
0397: * KVPs. In this case also an exception will be thrown even if the same request may be performed if a DOM object is
0398: * used.
0399: *
0400: * @param map
0401: * @return the request object
0402: * @throws OGCWebServiceException
0403: */
0404: public static OGCWebServiceRequest createFromKVP(
0405: Map<String, String> map) throws OGCWebServiceException {
0406:
0407: LOG.logDebug("KVP request: ", map);
0408: // request parameter given?
0409: String request = map.get("REQUEST");
0410: if (request == null) {
0411: LOG.logInfo("parameter: ", map);
0412: throw new InvalidParameterValueException(
0413: "OGCRequestFactory",
0414: "Request parameter must be set.");
0415: }
0416: // service parameter given?
0417: String service = map.get("SERVICE");
0418: if (service == null) {
0419: // a profile of a service will be treated as a service
0420: service = map.get("PROFILE");
0421: if (service == null) {
0422: service = getTargetService(service, request, null);
0423: }
0424: }
0425:
0426: OGCWebServiceRequest ogcRequest = null;
0427: if (WMS_SERVICE_NAME.equals(service)) {
0428: ogcRequest = getWMSRequest(request, map);
0429: } else if (WFS_SERVICE_NAME.equals(service)) {
0430: ogcRequest = getWFSRequest(request, map);
0431: } else if (WCS_SERVICE_NAME.equals(service)) {
0432: ogcRequest = getWCSRequest(request, map);
0433: } else if (CSW_SERVICE_NAME_EBRIM.equals(service)
0434: || CSW_SERVICE_NAME.equals(service)) {
0435: ogcRequest = getCSWRequest(request, map);
0436: } else if (SOS_SERVICE_NAME.equals(service)) {
0437: ogcRequest = getSOSRequest(request, map);
0438: } else if (WPVS_SERVICE_NAME.equals(service)) {
0439: ogcRequest = getWPVSRequest(request, map);
0440: } else if (WMPS_SERVICE_NAME.equals(service)) {
0441: ogcRequest = getWMPSRequest(request, map);
0442: } else if (WPS_SERVICE_NAME.equals(service)) {
0443: ogcRequest = getWPSRequest(request, map);
0444: } else if (WSS_SERVICE_NAME.equals(service)) {
0445: ogcRequest = getWSSRequest(request, map);
0446: } else if (WAS_SERVICE_NAME.equals(service)) {
0447: ogcRequest = getWASRequest(request, map);
0448: } else if (WCTS_SERVICE_NAME.equals(service)) {
0449: ogcRequest = getWCTSRequest(request, map);
0450: } else {
0451: throw new OGCWebServiceException("OGCRequestFactory",
0452: "Specified service '" + map.get("SERVICE")
0453: + "' is not a known OGC service type.");
0454: }
0455: return ogcRequest;
0456: }
0457:
0458: /**
0459: * Creates the corresponding WFS request object from the given parameters.
0460: *
0461: * @param request
0462: * @param map
0463: * @return the corresponding WFS request object
0464: * @throws OGCWebServiceException
0465: */
0466: private static OGCWebServiceRequest getWFSRequest(String request,
0467: Map<String, String> map) throws OGCWebServiceException {
0468: OGCWebServiceRequest ogcRequest = null;
0469: map
0470: .put("ID", ""
0471: + IDGenerator.getInstance().generateUniqueID());
0472: if (request.equals("GetCapabilities")) {
0473: ogcRequest = WFSGetCapabilities.create(map);
0474: } else if (request.equals("GetFeature")) {
0475: ogcRequest = GetFeature.create(map);
0476: } else if (request.equals("GetFeatureWithLock")) {
0477: ogcRequest = GetFeatureWithLock.create(map);
0478: } else if (request.equals("GetGmlObject")) {
0479: throw new OGCWebServiceException(
0480: "'GetGmlObject' operation is not implemented. ");
0481: } else if (request.equals("LockFeature")) {
0482: ogcRequest = LockFeature.create(map);
0483: } else if (request.equals("DescribeFeatureType")) {
0484: ogcRequest = DescribeFeatureType.create(map);
0485: } else if (request.equals("Transaction")) {
0486: ogcRequest = Transaction.create(map);
0487: } else {
0488: throw new InvalidParameterValueException(
0489: "Unknown WFS request type: '" + request + "'.");
0490: }
0491: return ogcRequest;
0492: }
0493:
0494: /**
0495: * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The returned request
0496: * will be a WFS request. The type of request is determined by also submitted request name. Known requests are:
0497: * <ul>
0498: * <li>GetCapabilities</li>
0499: * <li>GetFeature</li>
0500: * <li>GetFeatureWithLock</li>
0501: * <li>DescribeFeatureType</li>
0502: * <li>Transaction</li>
0503: * <li>LockFeature</li>
0504: * </ul>
0505: * <p>
0506: * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
0507: * </p>
0508: *
0509: * @param request
0510: * @param doc
0511: * @return created <code>OGCWebServiceRequest</code>
0512: * @throws OGCWebServiceException
0513: */
0514: private static OGCWebServiceRequest getWFSRequest(String request,
0515: Document doc) throws OGCWebServiceException {
0516: OGCWebServiceRequest ogcRequest = null;
0517: String id = "" + IDGenerator.getInstance().generateUniqueID();
0518: if (request.equals("GetCapabilities")) {
0519: ogcRequest = WFSGetCapabilities.create(id, doc
0520: .getDocumentElement());
0521: } else if (request.equals("GetFeature")) {
0522: ogcRequest = GetFeature
0523: .create(id, doc.getDocumentElement());
0524: } else if (request.equals("GetFeatureWithLock")) {
0525: ogcRequest = GetFeatureWithLock.create(id, doc
0526: .getDocumentElement());
0527: } else if (request.equals("DescribeFeatureType")) {
0528: ogcRequest = DescribeFeatureType.create(id, doc
0529: .getDocumentElement());
0530: } else if (request.equals("Transaction")) {
0531: ogcRequest = Transaction.create(id, doc
0532: .getDocumentElement());
0533: } else if (request.equals("LockFeature")) {
0534: ogcRequest = LockFeature.create(id, doc
0535: .getDocumentElement());
0536: } else {
0537: throw new OGCWebServiceException(
0538: "Unknown / unimplemented WFS request type: '"
0539: + request + "'.");
0540: }
0541: return ogcRequest;
0542: }
0543:
0544: /**
0545: * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The returned request
0546: * will be a WSS request. The type of request is determined by also submitted request name. Known requests are:
0547: * <ul>
0548: * <li>GetCapabilities</li>
0549: * <li>GetSession</li>
0550: * <li>CloseSession</li>
0551: * <li>DoService</li>
0552: * </ul>
0553: * <p>
0554: * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
0555: * </p>
0556: *
0557: * @param request
0558: * @param doc
0559: * @return created <code>OGCWebServiceRequest</code>
0560: * @throws OGCWebServiceException
0561: */
0562: private static OGCWebServiceRequest getWSSRequest(String request,
0563: Document doc) throws OGCWebServiceException {
0564: OGCWebServiceRequest ogcRequest = null;
0565: String id = "" + IDGenerator.getInstance().generateUniqueID();
0566: if (("GetCapabilities").equals(request)) {
0567: ogcRequest = WSSGetCapabilities.create(id, doc
0568: .getDocumentElement());
0569: } else if (("GetSession").equals(request)) {
0570: ogcRequest = GetSession
0571: .create(id, doc.getDocumentElement());
0572: } else if (("CloseSession").equals(request)) {
0573: ogcRequest = CloseSession.create(id, doc
0574: .getDocumentElement());
0575: } else if (("DoService").equals(request)) {
0576: ogcRequest = DoService.create(id, doc.getDocumentElement());
0577: } else {
0578: throw new OGCWebServiceException(
0579: "Unknown / unimplemented WSS request type: '"
0580: + request + "'.");
0581: }
0582: return ogcRequest;
0583: }
0584:
0585: /**
0586: * Creates an <code>OGCWebServiceRequest</code> from the passed <code>key value pair</code>. The returned
0587: * request will be a WSS request. The type of request is determined by also submitted request name. Known requests
0588: * are:
0589: * <ul>
0590: * <li>GetCapabilities</li>
0591: * <li>GetSession</li>
0592: * <li>CloseSession</li>
0593: * <li>DoService</li>
0594: * </ul>
0595: * <p>
0596: * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
0597: * </p>
0598: *
0599: * @param request
0600: * @param kvp
0601: * @return created <code>OGCWebServiceRequest</code>
0602: * @throws OGCWebServiceException
0603: */
0604: private static OGCWebServiceRequest getWSSRequest(String request,
0605: Map<String, String> kvp) throws OGCWebServiceException {
0606: OGCWebServiceRequest ogcRequest = null;
0607: String id = "" + IDGenerator.getInstance().generateUniqueID();
0608: if (("GetCapabilities").equals(request)) {
0609: ogcRequest = WSSGetCapabilities.create(id, kvp);
0610: } else if (("GetSession").equals(request)) {
0611: ogcRequest = GetSession.create(id, kvp);
0612: } else if (("CloseSession").equals(request)) {
0613: ogcRequest = CloseSession.create(id, kvp);
0614: } else if (("DoService").equals(request)) {
0615: ogcRequest = DoService.create(id, kvp);
0616: } else {
0617: throw new OGCWebServiceException(
0618: "Unknown / unimplemented WSS request type: '"
0619: + request + "'.");
0620: }
0621: return ogcRequest;
0622: }
0623:
0624: /**
0625: * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The returned request
0626: * will be a WAS request. The type of request is determined by also submitted request name. Known requests are:
0627: * <ul>
0628: * <li>GetCapabilities</li>
0629: * <li>GetSession</li>
0630: * <li>CloseSession</li>
0631: * </ul>
0632: * <p>
0633: * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
0634: * </p>
0635: *
0636: * @param request
0637: * @param doc
0638: * @return created <code>OGCWebServiceRequest</code>
0639: * @throws OGCWebServiceException
0640: */
0641: private static OGCWebServiceRequest getWASRequest(String request,
0642: Document doc) throws OGCWebServiceException {
0643: OGCWebServiceRequest ogcRequest = null;
0644: String id = "" + IDGenerator.getInstance().generateUniqueID();
0645: // note: DescribeUser is only supported through KVP
0646: if (("GetCapabilities").equals(request)) {
0647: ogcRequest = WASGetCapabilities.create(id, doc
0648: .getDocumentElement());
0649: } else if (("GetSession").equals(request)) {
0650: ogcRequest = GetSession
0651: .create(id, doc.getDocumentElement());
0652: } else if (("CloseSession").equals(request)) {
0653: ogcRequest = CloseSession.create(id, doc
0654: .getDocumentElement());
0655: } else {
0656: throw new OGCWebServiceException(
0657: "Unknown / unimplemented WAS request type: '"
0658: + request + "'.");
0659: }
0660: return ogcRequest;
0661: }
0662:
0663: /**
0664: * Creates an <code>OGCWebServiceRequest</code> from the passed <code>key value pair</code>. The returned
0665: * request will be a WAS request. The type of request is determined by also submitted request name. Known requests
0666: * are:
0667: * <ul>
0668: * <li>GetCapabilities</li>
0669: * <li>GetSession</li>
0670: * <li>CloseSession</li>
0671: * <li>DescribeUser</li>
0672: * </ul>
0673: * <p>
0674: * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
0675: * </p>
0676: *
0677: * @param request
0678: * @param kvp
0679: * @return created <code>OGCWebServiceRequest</code>
0680: * @throws OGCWebServiceException
0681: */
0682: private static OGCWebServiceRequest getWASRequest(String request,
0683: Map<String, String> kvp) throws OGCWebServiceException {
0684: OGCWebServiceRequest ogcRequest = null;
0685: String id = "" + IDGenerator.getInstance().generateUniqueID();
0686: if (("GetCapabilities").equals(request)) {
0687: ogcRequest = WASGetCapabilities.create(id, kvp);
0688: } else if (("GetSession").equals(request)) {
0689: ogcRequest = GetSession.create(id, kvp);
0690: } else if (("CloseSession").equals(request)) {
0691: ogcRequest = CloseSession.create(id, kvp);
0692: } else if (("DescribeUser").equals(request)) {
0693: ogcRequest = new DescribeUser(id, kvp);
0694: } else {
0695: throw new OGCWebServiceException(
0696: "Unknown / unimplemented WAS request type: '"
0697: + request + "'.");
0698: }
0699: return ogcRequest;
0700: }
0701:
0702: /**
0703: * return the type of service the passed request targets
0704: *
0705: * @param service
0706: * @param request
0707: * @param doc
0708: * @return the type of service the passed request targets
0709: */
0710: public static String getTargetService(String service,
0711: String request, Document doc) {
0712:
0713: if (WMS_SERVICE_NAME.equals(service) || isWMSRequest(request)) {
0714: return WMS_SERVICE_NAME;
0715: } else if (WFS_SERVICE_NAME.equals(service)
0716: || isWFSRequest(request, doc)) {
0717: return WFS_SERVICE_NAME;
0718: } else if (WCS_SERVICE_NAME.equals(service)
0719: || isWCSRequest(request)) {
0720: return WCS_SERVICE_NAME;
0721: } else if (CSW_SERVICE_NAME_EBRIM.equals(service)
0722: || CSW_SERVICE_NAME.equals(service)
0723: || isCSWRequest(request, doc)) {
0724: return CSW_SERVICE_NAME;
0725: } else if (SOS_SERVICE_NAME.equals(service)
0726: || isSOSRequest(request)) {
0727: return SOS_SERVICE_NAME;
0728: } else if (WPVS_SERVICE_NAME.equals(service)
0729: || isWPVSRequest(request)) {
0730: return WPVS_SERVICE_NAME;
0731: } else if (WMPS_SERVICE_NAME.equals(service)
0732: || isWMPSRequest(doc, request)) {
0733: return WMPS_SERVICE_NAME;
0734: } else if (WPS_SERVICE_NAME.equals(service)
0735: || isWPSRequest(request)) {
0736: return WPS_SERVICE_NAME;
0737: } else if (WAS_SERVICE_NAME.equals(service)
0738: || isWASRequest(request)) {
0739: return WAS_SERVICE_NAME;
0740: } else if (WSS_SERVICE_NAME.equals(service)
0741: || isWSSRequest(request)) {
0742: return WSS_SERVICE_NAME;
0743: } else if (WCTS_SERVICE_NAME.equals(service)
0744: || isWCTSRequest(doc)) {
0745: return WCTS_SERVICE_NAME;
0746: } else {
0747: return "unknown";
0748: }
0749:
0750: }
0751:
0752: /**
0753: * @param doc
0754: * to check
0755: * @return true if the namespace of the given dom-xml document equals {@link CommonNamespaces#WCTSNS}.
0756: */
0757: private static boolean isWCTSRequest(Document doc) {
0758: if (doc != null) {
0759: Element root = doc.getDocumentElement();
0760: if (root != null) {
0761: String ns = root.getNamespaceURI();
0762: return CommonNamespaces.WCTSNS.toASCIIString().equals(
0763: ns)
0764: || CommonNamespaces.DEEGREEWCTS.toASCIIString()
0765: .equals(ns);
0766: }
0767: }
0768: return false;
0769: }
0770:
0771: /**
0772: * returns true if the request is a WMPS request
0773: *
0774: * @param request
0775: * name, e.g. 'GetCapabilities' name, e.g. 'PrintMap'
0776: * @return true if the request is a WMPS request
0777: */
0778: private static boolean isWMPSRequest(Document doc, String request) {
0779: if (doc != null) {
0780: Element root = doc.getDocumentElement();
0781: if (root != null) {
0782: String ns = root.getNamespaceURI();
0783: if (CommonNamespaces.WMPSNS.toASCIIString().equals(ns)) {
0784: return true;
0785: }
0786: }
0787: }
0788: if (("PrintMap".equals(request))) {
0789: return true;
0790: }
0791: return false;
0792: }
0793:
0794: /**
0795: * returns true if the request is a WMS request
0796: *
0797: * @param request
0798: * @return true if the request is a WMS request
0799: */
0800: private static boolean isWMSRequest(String request) {
0801: if ("GetMap".equals(request) || "map".equals(request)
0802: || "GetFeatureInfo".equals(request)
0803: || "feature_info".equals(request)
0804: || "GetLegendGraphic".equals(request)
0805: || "GetStyles".equals(request)
0806: || "PutStyles".equals(request)
0807: || "DescribeLayer".equals(request)) {
0808: return true;
0809: }
0810: return false;
0811: }
0812:
0813: /**
0814: * returns true if the request is a WFS request
0815: *
0816: * @param request
0817: * @param doc
0818: * @return true if the request is a WFS request
0819: */
0820: private static boolean isWFSRequest(String request, Document doc) {
0821: if (doc != null) {
0822: String s = doc.getDocumentElement().getNamespaceURI();
0823: if (CommonNamespaces.WFSNS.toString().equals(s)) {
0824: return true;
0825: }
0826: } else {
0827: if ("DescribeFeatureType".equals(request)
0828: || "GetFeature".equals(request)
0829: || "GetFeatureWithLock".equals(request)
0830: || "GetGmlObject".equals(request)
0831: || "Lock".equals(request)
0832: || "Transaction".equals(request)) {
0833: return true;
0834: }
0835: }
0836: return false;
0837: }
0838:
0839: /**
0840: * returns true if the request is a WCS request
0841: *
0842: * @param request
0843: * @return true if the request is a WCS request
0844: */
0845: private static boolean isWCSRequest(String request) {
0846: if ("GetCoverage".equals(request)
0847: || "DescribeCoverage".equals(request)) {
0848: return true;
0849: }
0850: return false;
0851: }
0852:
0853: /**
0854: * returns true if the request is a CSW request
0855: *
0856: * @param request
0857: * @return true if the request is a CSW request
0858: */
0859: private static boolean isCSWRequest(String request, Document doc) {
0860: if (doc != null) {
0861: String s = doc.getDocumentElement().getNamespaceURI();
0862: if (CommonNamespaces.CSWNS.toString().equals(s)
0863: || CommonNamespaces.CSW202NS.toString().equals(s)) {
0864: return true;
0865: }
0866: } else {
0867: if (CatalogueOperationsMetadata.GET_RECORDS_NAME
0868: .equals(request)
0869: || CatalogueOperationsMetadata.DESCRIBE_RECORD_NAME
0870: .equals(request)
0871: || CatalogueOperationsMetadata.GET_RECORD_BY_ID_NAME
0872: .equals(request)
0873: || CatalogueOperationsMetadata.GET_DOMAIN_NAME
0874: .equals(request)
0875: || CatalogueOperationsMetadata.HARVEST_NAME
0876: .equals(request)) {
0877: return true;
0878: }
0879: }
0880: return false;
0881: }
0882:
0883: /**
0884: * returns true if the request is a SOS request
0885: *
0886: * @param request
0887: * @return true if the request is a SOS request
0888: */
0889: private static boolean isSOSRequest(String request) {
0890: if ("GetObservation".equals(request)
0891: || "DescribeSensor".equals(request)
0892: || "DescribePlatform".equals(request)) {
0893: return true;
0894: }
0895: return false;
0896: }
0897:
0898: /**
0899: * returns true if the request is a WPVS request
0900: *
0901: * @param request
0902: * name, e.g. 'GetView'
0903: * @return true if the request is a WPVS request
0904: */
0905: private static boolean isWPVSRequest(String request) {
0906: if ("GetView".equals(request)) {
0907: return true;
0908: }
0909: return false;
0910: }
0911:
0912: /**
0913: * returns true if the request is a WPS request
0914: *
0915: * @param request
0916: * name, e.g. 'GetCapabilities' name, e.g. 'DescribeProcess', e.g. 'Exceute'
0917: * @return true if the request is a WPS request
0918: */
0919: private static boolean isWPSRequest(String request) {
0920: if ("DescribeProcess".equals(request)
0921: || "Execute".equals(request)) {
0922: return true;
0923: }
0924: return false;
0925: }
0926:
0927: /**
0928: * returns true if the request is a WAS request
0929: *
0930: * @param request
0931: * name, e.g. 'GetSession' name, e.g. 'CloseSession', e.g. 'GetSAMLResponse'
0932: * @return true if and only if the request contains one of the above Strings
0933: */
0934: private static boolean isWASRequest(String request) {
0935: if ("GetSession".equals(request)
0936: || "CloseSession".equals(request)
0937: || "GetSAMLResponse".equals(request)
0938: || "DescribeUser".equals(request)) {
0939: return true;
0940: }
0941: return false;
0942: }
0943:
0944: /**
0945: * returns true if the request is a WSS request
0946: *
0947: * @param request
0948: * name, e.g. 'GetSession' name, e.g. 'CloseSession', e.g. 'GetSAMLResponse'
0949: * @return true if and only if the request contains one of the above Strins
0950: */
0951: private static boolean isWSSRequest(String request) {
0952: if ("GetSession".equals(request)
0953: || "CloseSession".equals(request)
0954: || "DoService".equals(request)) {
0955: return true;
0956: }
0957: return false;
0958: }
0959:
0960: /**
0961: * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Object</code>. the returned request will
0962: * be a WCS request. The type of request is determind by the the also passed 'request' parameter. Possible requests
0963: * are:
0964: * <ul>
0965: * <li>GetCapabilities
0966: * <li>GetCoverage
0967: * <li>DescribeCoverage
0968: * </ul>
0969: * <p>
0970: * Any other request passed to the method causes an exception to be thrown.
0971: * </p>
0972: *
0973: * @param request
0974: * @param req
0975: * @return created <code>OGCWebServiceRequest</code>
0976: * @throws OGCWebServiceException
0977: */
0978: private static OGCWebServiceRequest getWMSRequest(String request,
0979: Object req) throws OGCWebServiceException {
0980: OGCWebServiceRequest ogcRequest = null;
0981: String id = "" + IDGenerator.getInstance().generateUniqueID();
0982: try {
0983: Map<String, String> map = null;
0984: if (req instanceof Map) {
0985: map = (Map) req;
0986: map.put("ID", id);
0987: }
0988: if (request.equals("GetCapabilities")
0989: || "capabilities".equals(request)) {
0990: if (map != null) {
0991: // defaulting to 1.1.1 is not possible because of spec requirements
0992: // if( ( map.get( "VERSION" ) == null ) && ( map.get( "WMTVER" ) == null ) )
0993: // {
0994: // map.put( "VERSION", "1.3.0" );
0995: // }
0996: ogcRequest = WMSGetCapabilities.create(map);
0997: }
0998: } else if (request.equals("GetMap")
0999: || request.equals("map")) {
1000: if (map != null) {
1001: ogcRequest = GetMap.create(map);
1002: } else {
1003: ogcRequest = GetMap.create(id, (Document) req);
1004: }
1005: } else if (request.equals("GetFeatureInfo")
1006: || request.equals("feature_info")) {
1007: if (map != null) {
1008: ogcRequest = GetFeatureInfo.create(map);
1009: }
1010: } else if (request.equals("GetLegendGraphic")) {
1011: if (map != null) {
1012: ogcRequest = GetLegendGraphic.create(map);
1013: }
1014: } else if (request.equals("DescribeLayer")) {
1015: if (map != null) {
1016: ogcRequest = DescribeLayer.create(map);
1017: }
1018: } else {
1019: throw new OGCWebServiceException(
1020: "Unknown WMS request type: '" + request + "'.");
1021: }
1022: } catch (MalformedURLException e) {
1023: LOG.logError(e.getLocalizedMessage(), e);
1024: throw new OGCWebServiceException(e.getMessage());
1025: } catch (XMLParsingException e) {
1026: LOG.logError(e.getLocalizedMessage(), e);
1027: throw new OGCWebServiceException(e.getMessage());
1028: }
1029: return ogcRequest;
1030: }
1031:
1032: /**
1033: * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>. the returned
1034: * request will be a WCS request. The type of request is determind by the the also passed 'request' parameter.
1035: * Possible requests are:
1036: * <ul>
1037: * <li>GetCapabilities
1038: * <li>GetCoverage
1039: * <li>DescribeCoverage
1040: * </ul>
1041: * Any other request passed to the method causes an exception to be thrown.
1042: *
1043: * @param request
1044: * a string describing the request type.
1045: * @param req
1046: * the kvp-encoded request
1047: * @return one of the above mentioned Requests.
1048: * @throws OGCWebServiceException
1049: * if the requested operation is not one of the above mentioned, or something went wrong while creating
1050: * the request.
1051: */
1052: private static AbstractOGCWebServiceRequest getWCSRequest(
1053: String request, Map<String, String> req)
1054: throws OGCWebServiceException {
1055: AbstractOGCWebServiceRequest ogcRequest = null;
1056: String id = Long.toString(IDGenerator.getInstance()
1057: .generateUniqueID());
1058: req.put("ID", id);
1059: if (request.equals("GetCapabilities")) {
1060: ogcRequest = WCSGetCapabilities.create(req);
1061: } else if (request.equals("GetCoverage")) {
1062: ogcRequest = GetCoverage.create(req);
1063: } else if (request.equals("DescribeCoverage")) {
1064: ogcRequest = DescribeCoverage.create(req);
1065: } else {
1066: throw new OGCWebServiceException(
1067: "Unknown WCS request type: '" + request + "'.");
1068: }
1069: return ogcRequest;
1070: }
1071:
1072: /**
1073: * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Docuement</code>. the returned
1074: * request will be a WCS request. The type of request is determind by the the also passed 'request' parameter.
1075: * Possible requests are:
1076: * <ul>
1077: * <li>GetCapabilities
1078: * <li>GetCoverage
1079: * <li>DescribeCoverage
1080: * </ul>
1081: * Any other request passed to the method causes an exception to be thrown.
1082: *
1083: * @param request
1084: * a string describing the request type.
1085: * @param req
1086: * the XML-encoded request
1087: * @return one of the above mentioned Requests.
1088: * @throws OGCWebServiceException
1089: * if the requested operation is not one of the above mentioned, or something went wrong while creating
1090: * the request.
1091: */
1092: private static AbstractOGCWebServiceRequest getWCSRequest(
1093: String request, Document req) throws OGCWebServiceException {
1094: AbstractOGCWebServiceRequest ogcRequest = null;
1095: String id = Long.toString(IDGenerator.getInstance()
1096: .generateUniqueID());
1097: if (request.equals("GetCapabilities")) {
1098: ogcRequest = WCSGetCapabilities.create(id, req);
1099: } else if (request.equals("GetCoverage")) {
1100: ogcRequest = GetCoverage.create(id, req);
1101: } else if (request.equals("DescribeCoverage")) {
1102: ogcRequest = DescribeCoverage.create(id, req);
1103: } else {
1104: throw new OGCWebServiceException(
1105: "Unknown WCS request type: '" + request + "'.");
1106: }
1107: return ogcRequest;
1108: }
1109:
1110: /**
1111: * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>. The returned
1112: * request will be a <code>CSW</code> request. The type of request is determined by the the also passed 'request'
1113: * parameter. Allowed values for the request parameter are:
1114: * <ul>
1115: * <li>GetCapabilities</li>
1116: * <li>GetRecords</li>
1117: * <li>GetRecordsByID</li>
1118: * <li>DescribeRecord</li>
1119: * <li>GetDomain, will cause an exception to be thrown</li>
1120: * <li>Transaction, will cause an exception to be thrown</li>
1121: * <li>Harvest</li>
1122: * </ul>
1123: *
1124: * Any other request passed to the method causes an exception to be thrown.
1125: *
1126: * @param request
1127: * a string describing the request type.
1128: * @param req
1129: * the KVP-encoded request
1130: * @return one of the above mentioned Requests.
1131: * @throws OGCWebServiceException
1132: * if the requested operation is not one of the above mentioned, not supported or something went wrong
1133: * while creating the request.
1134: */
1135: private static AbstractOGCWebServiceRequest getCSWRequest(
1136: String request, Map<String, String> req)
1137: throws OGCWebServiceException {
1138: AbstractOGCWebServiceRequest ogcRequest = null;
1139: String id = Long.toString(IDGenerator.getInstance()
1140: .generateUniqueID());
1141: LOG.logDebug(StringTools.concat(200, "Creating CSW request '",
1142: request, "' with ID=", id, "/type:", req.getClass()
1143: .getName()));
1144:
1145: if (OperationsMetadata.GET_CAPABILITIES_NAME.equals(request)) {
1146: req.put("ID", id);
1147: ogcRequest = CatalogueGetCapabilities.create(req);
1148: } else if (CatalogueOperationsMetadata.GET_RECORDS_NAME
1149: .equals(request)) {
1150: req.put("ID", id);
1151: ogcRequest = GetRecords.create(req);
1152: } else if (CatalogueOperationsMetadata.GET_RECORD_BY_ID_NAME
1153: .equals(request)) {
1154: // req.put( "ID", id );
1155: ogcRequest = GetRecordById.create(id, req);
1156: } else if (CatalogueOperationsMetadata.GET_REPOSITORY_ITEM
1157: .equals(request)) {
1158: req.put("REQUESTID", id);
1159: ogcRequest = GetRepositoryItem.create(req);
1160: } else if (CatalogueOperationsMetadata.DESCRIBE_RECORD_NAME
1161: .equals(request)) {
1162: req.put("ID", id);
1163: ogcRequest = DescribeRecord.create(req);
1164: } else if (CatalogueOperationsMetadata.GET_DOMAIN_NAME
1165: .equals(request)) {
1166: // TODO
1167: throw new OGCWebServiceException(
1168: CatalogueOperationsMetadata.TRANSACTION_NAME
1169: + " is not supported.");
1170: } else if (CatalogueOperationsMetadata.TRANSACTION_NAME
1171: .equals(request)) {
1172: throw new OGCWebServiceException(
1173: CatalogueOperationsMetadata.TRANSACTION_NAME
1174: + " through HTTP Get is not supported.");
1175: } else if (CatalogueOperationsMetadata.HARVEST_NAME
1176: .equals(request)) {
1177: req.put("ID", id);
1178: ogcRequest = Harvest.create(req);
1179: } else {
1180: throw new OGCWebServiceException(
1181: "Unknown CSW request type: '" + request + "'.");
1182: }
1183: LOG.logDebug("CSW request created: " + ogcRequest);
1184: return ogcRequest;
1185: }
1186:
1187: /**
1188: * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>. The returned
1189: * request will be a <code>CSW</code> request. The type of request is determined by the the also passed 'request'
1190: * parameter. Allowed values for the request parameter are:
1191: * <ul>
1192: * <li>GetCapabilities</li>
1193: * <li>GetRecords</li>
1194: * <li>GetRecordsByID</li>
1195: * <li>DescribeRecord</li>
1196: * <li>GetDomain, will cause an exception to be thrown</li>
1197: * <li>Transaction</li>
1198: * <li>Harvest, will cause an exception to be thrown</li>
1199: * </ul>
1200: *
1201: * Any other request passed to the method causes an exception to be thrown.
1202: *
1203: * @param request
1204: * a string describing the request type.
1205: * @param req
1206: * the XML-encoded request
1207: * @return one of the above mentioned Requests.
1208: * @throws OGCWebServiceException
1209: * if the requested operation is not one of the above mentioned, or something went wrong while creating
1210: * the request.
1211: */
1212: private static AbstractOGCWebServiceRequest getCSWRequest(
1213: String request, Document req) throws OGCWebServiceException {
1214: AbstractOGCWebServiceRequest ogcRequest = null;
1215: String id = Long.toString(IDGenerator.getInstance()
1216: .generateUniqueID());
1217: LOG.logDebug(StringTools.concat(200, "Creating CSW request '",
1218: request, "' with ID=", id, "/type:", req.getClass()
1219: .getName()));
1220: Element docElem = req.getDocumentElement();
1221: if (OperationsMetadata.GET_CAPABILITIES_NAME.equals(request)) {
1222: ogcRequest = CatalogueGetCapabilities.create(id, docElem);
1223: } else if (CatalogueOperationsMetadata.GET_RECORDS_NAME
1224: .equals(request)) {
1225: ogcRequest = GetRecords.create(id, docElem);
1226: } else if (CatalogueOperationsMetadata.GET_RECORD_BY_ID_NAME
1227: .equals(request)) {
1228: ogcRequest = GetRecordById.create(id, docElem);
1229: } else if (CatalogueOperationsMetadata.GET_REPOSITORY_ITEM
1230: .equals(request)) {
1231: throw new OGCWebServiceException(
1232: CatalogueOperationsMetadata.GET_REPOSITORY_ITEM
1233: + " is not supported.");
1234: } else if (CatalogueOperationsMetadata.DESCRIBE_RECORD_NAME
1235: .equals(request)) {
1236: ogcRequest = DescribeRecord.create(id, docElem);
1237: } else if (CatalogueOperationsMetadata.GET_DOMAIN_NAME
1238: .equals(request)) {
1239: // TODO
1240: throw new OGCWebServiceException(
1241: CatalogueOperationsMetadata.TRANSACTION_NAME
1242: + " is not supported.");
1243: } else if (CatalogueOperationsMetadata.TRANSACTION_NAME
1244: .equals(request)) {
1245: ogcRequest = org.deegree.ogcwebservices.csw.manager.Transaction
1246: .create(id, docElem);
1247: } else if (CatalogueOperationsMetadata.HARVEST_NAME
1248: .equals(request)) {
1249: throw new OGCWebServiceException(
1250: CatalogueOperationsMetadata.HARVEST_NAME
1251: + " through HTTP post is not supported.");
1252: } else {
1253: throw new OGCWebServiceException(
1254: "Unknown CSW request type: '" + request + "'.");
1255: }
1256: LOG.logDebug("CSW request created: " + ogcRequest);
1257: return ogcRequest;
1258: }
1259:
1260: /**
1261: *
1262: * @param request
1263: * @param req
1264: * @return created <code>OGCWebServiceRequest</code>
1265: * @throws OGCWebServiceException
1266: */
1267: private static AbstractOGCWebServiceRequest getSOSRequest(
1268: String request, Object req) throws OGCWebServiceException {
1269:
1270: AbstractOGCWebServiceRequest ogcRequest = null;
1271:
1272: String id = "" + IDGenerator.getInstance().generateUniqueID();
1273:
1274: LOG.logDebug("Creating SOS request '" + request + "' with ID="
1275: + id + "/type:" + req.getClass().getName());
1276:
1277: if (req instanceof Map) {
1278: ((Map) req).put("ID", id);
1279: }
1280:
1281: if (OperationsMetadata.GET_CAPABILITIES_NAME.equals(request)) {
1282: if (req instanceof Map) {
1283: ogcRequest = SOSGetCapabilities.create((Map) req);
1284: } else {
1285: ogcRequest = SOSGetCapabilities.create(id,
1286: (Document) req);
1287: }
1288:
1289: } else if (SOSOperationsMetadata.DESCRIBE_PLATFORM_NAME
1290: .equals(request)) {
1291: if (req instanceof Map) {
1292: ogcRequest = DescribePlatformRequest.create((Map) req);
1293: } else {
1294: ogcRequest = DescribePlatformRequest.create(id,
1295: (Document) req);
1296: }
1297:
1298: } else if (SOSOperationsMetadata.DESCRIBE_SENSOR_NAME
1299: .equals(request)) {
1300: if (req instanceof Map) {
1301: ogcRequest = DescribeSensorRequest.create((Map) req);
1302: } else {
1303: ogcRequest = DescribeSensorRequest.create(id,
1304: (Document) req);
1305: }
1306: } else if (SOSOperationsMetadata.GET_OBSERVATION_NAME
1307: .equals(request)) {
1308: if (req instanceof Map) {
1309: ogcRequest = GetObservationRequest.create((Map) req);
1310: } else {
1311: ogcRequest = GetObservationRequest.create(id,
1312: (Document) req);
1313: }
1314: } else {
1315: throw new OGCWebServiceException(
1316: "Unknown SCS request type: '" + request + "'.");
1317: }
1318: LOG.logDebug("SCS request created: " + ogcRequest);
1319: return ogcRequest;
1320: }
1321:
1322: /**
1323: * Creates an <code>OGCWebServiceRequest</code> from the passed <code>XML-Document</code>. the returned request
1324: * will be a WPVS request. The type of request is determind by the the also passed 'request' parameter. Possible
1325: * requests are:
1326: * <ul>
1327: * <li>GetCapabilities
1328: * <li>GetView
1329: * </ul>
1330: * <p>
1331: * Any other request passed to the method causes an exception to be thrown.
1332: * </p>
1333: *
1334: * @param requestName
1335: * name of the request, one of GetCapabilities or GetView
1336: * @param request
1337: * the request as an xml document
1338: * @return created <code>OGCWebServiceRequest</code>
1339: * @throws OGCWebServiceException
1340: */
1341: @SuppressWarnings("unused")
1342: private static OGCWebServiceRequest getWPVSRequest(
1343: String requestName, Document request)
1344: throws OGCWebServiceException {
1345: OGCWebServiceRequest ogcRequest = null;
1346: String id = Long.toString(IDGenerator.getInstance()
1347: .generateUniqueID());
1348:
1349: if (OperationsMetadata.GET_CAPABILITIES_NAME
1350: .equals(requestName)) {
1351: // ogcRequest = WPVSGetCapabilities.create(id, (Document) req);
1352: } else if ("GetView".equals(requestName)) {
1353: // ogcRequest = GetView.create( req );
1354: } else {
1355: throw new OGCWebServiceException(
1356: "Unknown WPVS request type: '" + requestName + "'.");
1357: }
1358: return ogcRequest;
1359: }
1360:
1361: /**
1362: * Creates an <code>OGCWebServiceRequest</code> from the passed <code>KVP-Map</code>. the returned request will
1363: * be a WPVS request. The type of request is determind by the the also passed 'request' parameter. Possible requests
1364: * are:
1365: * <ul>
1366: * <li>GetCapabilities
1367: * <li>GetView
1368: * </ul>
1369: * <p>
1370: * Any other request passed to the method causes an exception to be thrown.
1371: * </p>
1372: *
1373: * @param requestName
1374: * name of the request, one of GetCapabilities or GetView
1375: * @param request
1376: * the actual parameters of the request
1377: * @return created <code>OGCWebServiceRequest</code>
1378: * @throws OGCWebServiceException
1379: */
1380: private static OGCWebServiceRequest getWPVSRequest(
1381: String requestName, Map<String, String> request)
1382: throws OGCWebServiceException {
1383: OGCWebServiceRequest ogcRequest = null;
1384: String id = Long.toString(IDGenerator.getInstance()
1385: .generateUniqueID());
1386:
1387: if (OperationsMetadata.GET_CAPABILITIES_NAME
1388: .equals(requestName)) {
1389: request.put("ID", id);
1390: ogcRequest = WPVSGetCapabilities.create(request);
1391: } else if ("GetView".equals(requestName)) {
1392: ogcRequest = GetView.create(request);
1393: } else if ("Get3DFeatureInfo".equals(requestName)) {
1394: ogcRequest = Get3DFeatureInfo.create(request);
1395: } else {
1396: throw new OGCWebServiceException(
1397: "Unknown WPVS request type: '" + requestName + "'.");
1398: }
1399: return ogcRequest;
1400: }
1401:
1402: /**
1403: * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>. the returned
1404: * request will be a WMPS request. The type of request is determind by the the also passed 'request' parameter.
1405: * Possible requests are:
1406: * <ul>
1407: * <li>GetCapabilities
1408: * </ul>
1409: * Any other request passed to the method causes an exception to be thrown.
1410: *
1411: * @param request
1412: * @param doc
1413: * @param req
1414: * @return created <code>OGCWebServiceRequest</code>
1415: * @throws OGCWebServiceException
1416: * @throws OGCWebServiceException
1417: */
1418: private static OGCWebServiceRequest getWMPSRequest(String request,
1419: Document doc) throws OGCWebServiceException {
1420: OGCWebServiceRequest ogcRequest = null;
1421:
1422: if (request.equals("PrintMap")) {
1423: try {
1424: ogcRequest = PrintMap.create(doc.getDocumentElement());
1425: } catch (Exception e) {
1426: throw new OGCWebServiceException(
1427: "Error creating a Print Map object for the request '"
1428: + request + "'. " + e.getMessage());
1429: }
1430: } else {
1431: throw new OGCWebServiceException(
1432: "Unknown / unimplemented WMPS request type: '"
1433: + request + "'.");
1434: }
1435: return ogcRequest;
1436: }
1437:
1438: /**
1439: * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>. the returned
1440: * request will be a WMPS request. The type of request is determind by the the also passed 'request' parameter.
1441: * Possible requests are:
1442: * <ul>
1443: * <li>GetCapabilities
1444: * </ul>
1445: * Any other request passed to the method causes an exception to be thrown.
1446: *
1447: * @param request
1448: * @param map
1449: * @param req
1450: * @return OGCWebServiceRequest
1451: * @throws InconsistentRequestException
1452: * @throws InvalidParameterValueException
1453: * @throws OGCWebServiceException
1454: */
1455: private static OGCWebServiceRequest getWMPSRequest(String request,
1456: Map<String, String> map)
1457: throws InconsistentRequestException,
1458: InvalidParameterValueException {
1459: OGCWebServiceRequest ogcRequest = null;
1460: map
1461: .put("ID", ""
1462: + IDGenerator.getInstance().generateUniqueID());
1463: if (request.equals("GetCapabilities")) {
1464: ogcRequest = WMPSGetCapabilities.create(map);
1465: } else if (request.equals("PrintMap")) {
1466: ogcRequest = PrintMap.create(map);
1467: } else {
1468: throw new InvalidParameterValueException(
1469: "Unknown WMPS request type: '" + request + "'.");
1470: }
1471: return ogcRequest;
1472: }
1473:
1474: /**
1475: * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Map</code>. The returned request will be
1476: * a WPS request. The type of request is determined by also submitted request name. Known requests are:
1477: * <ul>
1478: * <li>GetCapabilities</li>
1479: * <li>DescribeProcess</li>
1480: * <li>Execute</li>
1481: * </ul>
1482: * <p>
1483: * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
1484: * </p>
1485: *
1486: * @param request
1487: * @param map
1488: * @return created <code>OGCWebServiceRequest</code>
1489: * @throws OGCWebServiceException
1490: */
1491: private static OGCWebServiceRequest getWPSRequest(String request,
1492: Map<String, String> map) throws OGCWebServiceException {
1493: OGCWebServiceRequest ogcRequest = null;
1494: map
1495: .put("ID", ""
1496: + IDGenerator.getInstance().generateUniqueID());
1497: if ("GetCapabilities".equals(request)) {
1498: ogcRequest = WPSGetCapabilities.create(map);
1499: } else if ("DescribeProcess".equals(request)) {
1500: ogcRequest = DescribeProcessRequest.create(map);
1501: } else if ("Execute".equals(request)) {
1502: ogcRequest = ExecuteRequest.create(map);
1503: } else {
1504: throw new InvalidParameterValueException(
1505: "Unknown WPS request type: '" + request + "'.");
1506: }
1507: return ogcRequest;
1508: }
1509:
1510: /**
1511: * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The returned request
1512: * will be a WPS request. The type of request is determined by also submitted request name. Known requests are:
1513: * <ul>
1514: * <li>GetCapabilities</li>
1515: * <li>DescribeProcess</li>
1516: * <li>Execute</li>
1517: * </ul>
1518: * <p>
1519: * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be thrown.
1520: * </p>
1521: *
1522: * @param request
1523: * @param doc
1524: * @return created <code>OGCWebServiceRequest</code>
1525: * @throws OGCWebServiceException
1526: */
1527: private static OGCWebServiceRequest getWPSRequest(String request,
1528: Document doc) throws OGCWebServiceException {
1529: OGCWebServiceRequest ogcRequest = null;
1530: String id = "" + IDGenerator.getInstance().generateUniqueID();
1531: if ("GetCapabilities".equals(request)) {
1532: ogcRequest = WPSGetCapabilities.create(id, doc
1533: .getDocumentElement());
1534: } else if ("DescribeProcess".equals(request)) {
1535: ogcRequest = DescribeProcessRequest.create(id, doc
1536: .getDocumentElement());
1537:
1538: } else if ("Execute".equals(request)) {
1539: ogcRequest = ExecuteRequest.create(id, doc
1540: .getDocumentElement());
1541:
1542: } else {
1543: throw new OGCWebServiceException(
1544: "Unknown WPS request type: '" + request + "'.");
1545: }
1546: return ogcRequest;
1547: }
1548:
1549: /**
1550: * @param request
1551: * containing the local-name of the top root element.
1552: * @param doc
1553: * @return
1554: * @throws IllegalArgumentException
1555: * @throws OGCWebServiceException
1556: */
1557: private static OGCWebServiceRequest getWCTSRequest(String request,
1558: Document doc) throws OGCWebServiceException,
1559: IllegalArgumentException {
1560: OGCWebServiceRequest result = null;
1561: String requestID = Long.toString(IDGenerator.getInstance()
1562: .generateUniqueID());
1563: if ("GetResourceByID".equals(request)) {
1564: result = new GetResourceByIDDocument(requestID, doc
1565: .getDocumentElement()).getResourceById();
1566: } else if ("GetCapabilities".equals(request)) {
1567: result = new WCTSGetCapabilitiesDocument(requestID, doc
1568: .getDocumentElement()).getGetCapabilities();
1569: } else if ("Transform".equals(request)) {
1570: result = new TransformDocument(requestID, doc
1571: .getDocumentElement()).getTransformRequest();
1572: } else if ("IsTransformable".equals(request)) {
1573: result = new IsTransformableDocument(requestID, doc
1574: .getDocumentElement()).getIsTransformable();
1575: } else if ("GetTransformation".equals(request)) {
1576: throw new OGCWebServiceException(
1577: "GetTransformation requests are currently not supported by the WCTS",
1578: ExceptionCode.OPERATIONNOTSUPPORTED);
1579: // result = new Document(requestID, doc.getDocumentElement() ).getIsTransformable();
1580: } else {
1581: throw new OGCWebServiceException(request
1582: + " is not known to the WCTS",
1583: ExceptionCode.OPERATIONNOTSUPPORTED);
1584: }
1585: return result;
1586: }
1587:
1588: /**
1589: * @param request
1590: * @param map
1591: * @return
1592: * @throws OGCWebServiceException
1593: */
1594: private static OGCWebServiceRequest getWCTSRequest(String request,
1595: Map<String, String> map) throws OGCWebServiceException {
1596: OGCWebServiceRequest result = null;
1597: String requestID = Long.toString(IDGenerator.getInstance()
1598: .generateUniqueID());
1599: if ("GetResourceByID".equals(request)) {
1600: result = GetResourceByID.create(requestID, map);
1601: } else if ("GetCapabilities".equals(request)) {
1602: result = WCTSGetCapabilities.create(requestID, map);
1603: } else if ("Transform".equals(request)) {
1604: result = Transform.create(requestID, map);
1605: } else if ("IsTransformable".equals(request)) {
1606: result = IsTransformable.create(requestID, map);
1607: } else if ("GetTransformation".equals(request)) {
1608: throw new OGCWebServiceException(
1609: "GetTransformation requests are currently not supported by the WCTS",
1610: ExceptionCode.OPERATIONNOTSUPPORTED);
1611: // result = new Document(requestID, doc.getDocumentElement() ).getIsTransformable();
1612: } else {
1613: throw new OGCWebServiceException(request
1614: + " is not known to the WCTS",
1615: ExceptionCode.OPERATIONNOTSUPPORTED);
1616: }
1617: return result;
1618: }
1619:
1620: }
|