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.wms.servlets;
006:
007: import org.vfny.geoserver.servlets.Dispatcher;
008: import org.vfny.geoserver.util.requests.readers.DispatcherKvpReader;
009: import org.vfny.geoserver.util.requests.readers.KvpRequestReader;
010: import java.io.IOException;
011: import java.util.Map;
012: import java.util.logging.Logger;
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. Currently does not support post requests, but
030: * most requests for this will likely come with get.
031: *
032: * @author Chris Holmes, TOPP
033: * @version $Id: WmsDispatcher.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: */
038:
039: //JD: kill this class
040: public class WmsDispatcher extends Dispatcher {
041: /** Class logger */
042: private static Logger LOGGER = org.geotools.util.logging.Logging
043: .getLogger("org.vfny.geoserver.servlets.wms");
044:
045: /**
046: * Passes the Post method to the Get method, with no modifications.
047: *
048: * @param request The servlet request object.
049: * @param response The servlet response object.
050: *
051: * @throws ServletException For any servlet problems.
052: * @throws IOException For any io problems.
053: *
054: * @task REVISIT: This is not working yet, as we can't seem to figure out
055: * how to read the reader twice. It must be read once to see what
056: * the request type is, and again to actually analyze it. But we
057: * haven't yet found the way to read it twice. There should be
058: * some way to do this, but it doesn't seem that important, as users
059: * who use post should be able to figure out which servlet to send
060: * it to. I'm removing DispatcherReaderXml and DispatcherHandler
061: * from cvs, so that they don't get in the 1.0 release. If anyone
062: * attempts to implement this there are deleted versions in cvs.
063: * Check the attic on the webcvs, or just do a checkout with the
064: * rel_0_98 tag.
065: */
066: public void doPost(HttpServletRequest request,
067: HttpServletResponse response) throws ServletException,
068: IOException {
069: //BufferedReader tempReader = request.getReader();
070: //String tempResponse = new String();
071: //int targetRequest = 0;
072: LOGGER.finer("got to post request");
073:
074: //DJB: adding parital POST support for SLD-POST.
075: // currently the only type of POST request we support is GetMap
076: // So chris' comments above dont apply - we just assume its GetMap and we dont have to read twice.
077: //
078: int targetRequest = Dispatcher.GET_MAP_REQUEST;
079: doResponse(true, request, response, targetRequest);
080: }
081:
082: /**
083: * Handles all Get requests. This method implements the main matching
084: * logic for the class.
085: *
086: * @param request The servlet request object.
087: * @param response The servlet response object.
088: *
089: * @throws ServletException For any servlet problems.
090: * @throws IOException For any io problems.
091: */
092: public void doGet(HttpServletRequest request,
093: HttpServletResponse response) throws ServletException,
094: IOException {
095: int targetRequest = 0;
096:
097: // Examine the incoming request and create appropriate server objects
098: // to deal with each request
099: // try {
100: if (request.getQueryString() != null) {
101: Map kvPairs = KvpRequestReader.parseKvpSet(request
102: .getQueryString());
103: targetRequest = DispatcherKvpReader.getRequestType(kvPairs);
104: } else {
105: targetRequest = UNKNOWN;
106:
107: //throw exception
108: }
109:
110: doResponse(false, request, response, targetRequest);
111: }
112:
113: protected void doResponse(boolean isPost,
114: HttpServletRequest request, HttpServletResponse response,
115: int req_type) throws ServletException, IOException {
116: HttpServlet dispatched;
117: LOGGER.finer("req_type is " + req_type);
118:
119: //JD: kill this
120: // switch (req_type) {
121: // case GET_CAPABILITIES_REQUEST:
122: // dispatched = new Capabilities();
123: //
124: // break;
125: //
126: // case GET_MAP_REQUEST:
127: // dispatched = new GetMap();
128: //
129: // break;
130: //
131: // case GET_FEATURE_INFO_REQUEST:
132: // dispatched = new GetFeatureInfo();
133: //
134: // break;
135: //
136: // case DESCRIBE_LAYER_REQUEST:
137: // dispatched = new DescribeLayer();
138: //
139: // break;
140: //
141: // case GET_LEGEND_GRAPHIC_REQUEST:
142: // dispatched = new GetLegendGraphic();
143: //
144: // break;
145: // default:
146: // dispatched = null;
147: // }
148: //
149: // if ((dispatched != null)) //DJB: removed "&& !isPost" because we are partially supportin POST now
150: // {
151: // dispatched.init(servletConfig); //only needed for init hack, see
152: // dispatched.service(request, response);
153: // } else
154: // {
155: // String message;
156: //
157: // if (isPost) {
158: // message = "Post requests are not supported with the dispatcher "
159: // + "servlet. Please try the request using the appropriate "
160: // + "request servlet, such as GetCapabilities or GetFeature";
161: // } else {
162: // message = "No wms kvp request recognized. The REQUEST parameter"
163: // + " must be one of GetMap or GetCapabilities";
164: // }
165: //
166: // HttpSession session = request.getSession();
167: // ServletContext context = session.getServletContext();
168: //
169: // GeoServer geoServer = (GeoServer) context.getAttribute(GeoServer.WEB_CONTAINER_KEY);
170: //
171: // WmsException wmse = new WmsException(message);
172: // String tempResponse = wmse.getXmlResponse(geoServer.isVerboseExceptions(), request);
173: //
174: // response.setContentType(geoServer.getCharSet().toString());
175: // response.getWriter().write(tempResponse);
176: // }
177: }
178: }
|