001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.servlets;
006:
007: import org.vfny.geoserver.util.requests.readers.DispatcherKvpReader;
008: import org.vfny.geoserver.util.requests.readers.KvpRequestReader;
009: import java.io.IOException;
010: import java.util.Map;
011: import java.util.logging.Logger;
012: import javax.servlet.ServletConfig;
013: import javax.servlet.ServletException;
014: import javax.servlet.http.HttpServlet;
015: import javax.servlet.http.HttpServletRequest;
016: import javax.servlet.http.HttpServletResponse;
017:
018: /**
019: * Routes requests made at the top-level URI to appropriate interface servlet.
020: * Note that the logic of this method could be generously described as
021: * 'loose.' It is not checking for request validity in any way (this is done
022: * by the reqeust- specific servlets). Rather, it is attempting to make a
023: * reasonable guess as to what servlet to call, given that the client is
024: * routing to the top level URI as opposed to the request-specific URI, as
025: * specified in the GetCapabilities response. Thus, this is a convenience
026: * method, which allows for some slight client laziness and helps explain to
027: * lost souls/spiders what lives at the URL. Due to the string parsing, it is
028: * much faster (and recommended) to use the URIs specified in the
029: * GetCapabablities response.
030: *
031: * @author Rob Hranac, Vision for New York
032: * @author Chris Holmes, TOPP
033: * @version $Id: Dispatcher.java 7746 2007-11-13 15:38:35Z aaime $
034: *
035: * @task TODO: rework to work too for WMS servlets, and to get the servlets
036: * from ServletContext instead of having them hardcoded
037: * @task TODO: move the post dispatcher work from WfsDispatcher up here.
038: */
039:
040: //JD: kill this class
041: public class Dispatcher extends HttpServlet {
042: /** Class logger */
043: private static Logger LOGGER = org.geotools.util.logging.Logging
044: .getLogger("org.vfny.geoserver.servlets");
045:
046: /** Map metadata request type */
047: public static String META_REQUEST = "GetMeta";
048:
049: /** Map get capabilities request type */
050: public static final int GET_CAPABILITIES_REQUEST = 1;
051:
052: /** Map describe feature type request type */
053: public static final int DESCRIBE_FEATURE_TYPE_REQUEST = 2;
054:
055: /** Map get feature request type */
056: public static final int GET_FEATURE_REQUEST = 3;
057:
058: /** Map get feature request type */
059: public static final int TRANSACTION_REQUEST = 4;
060:
061: /** Map get feature with lock request type */
062: public static final int GET_FEATURE_LOCK_REQUEST = 5;
063:
064: /** WMS get feature info request type */
065: public static final int GET_FEATURE_INFO_REQUEST = 6;
066:
067: /** int representation of a lock request type */
068: public static final int LOCK_REQUEST = 6;
069:
070: /** Map get capabilities request type */
071: public static final int GET_MAP_REQUEST = 7;
072:
073: /** WMS DescribeLayer request type */
074: public static final int DESCRIBE_LAYER_REQUEST = 8;
075:
076: /** WMS GetLegendGraphic request type */
077: public static final int GET_LEGEND_GRAPHIC_REQUEST = 9;
078: public static final short WMS_SERVICE = 101;
079: public static final short WFS_SERVICE = 102;
080:
081: /** Map get feature request type */
082: public static final int UNKNOWN = -1;
083:
084: /** Map get feature request type */
085: public static final int ERROR = -2;
086: protected ServletConfig servletConfig;
087:
088: //HACK! This is just to fix instances where the first request is a
089: //dispatcher, and the strategy hasn't been inited yet. This can be
090: //fixed in two ways, one by having Dispatcher extend Abstract ServiceConfig,
091: //which it should do, and two by having the configuration of the strategy
092: //done in user configuration instead of in the web.xml file. Both should
093: //be done.
094: public void init(ServletConfig config) throws ServletException {
095: super .init(config);
096: this .servletConfig = config;
097: }
098:
099: /**
100: * Handles all Get requests. This method implements the main matching
101: * logic for the class.
102: *
103: * @param request The servlet request object.
104: * @param response The servlet response object.
105: *
106: * @throws ServletException For any servlet problems.
107: * @throws IOException For any io problems.
108: */
109: public void doGet(HttpServletRequest request,
110: HttpServletResponse response) throws ServletException,
111: IOException {
112: int targetRequest = 0;
113:
114: // Examine the incoming request and create appropriate server objects
115: // to deal with each request
116: // try {
117: if (request.getQueryString() != null) {
118: Map kvPairs = KvpRequestReader.parseKvpSet(request
119: .getQueryString());
120: targetRequest = DispatcherKvpReader.getRequestType(kvPairs);
121: } else {
122: targetRequest = UNKNOWN;
123:
124: //throw exception
125: }
126: }
127: }
|