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.Request;
008: import org.vfny.geoserver.Response;
009: import org.vfny.geoserver.ServiceException;
010: import org.vfny.geoserver.global.WMS;
011: import org.vfny.geoserver.util.requests.readers.KvpRequestReader;
012: import org.vfny.geoserver.util.requests.readers.XmlRequestReader;
013: import org.vfny.geoserver.wms.requests.GetMapKvpReader;
014: import org.vfny.geoserver.wms.requests.GetMapXmlReader;
015: import org.vfny.geoserver.wms.responses.GetMapResponse;
016: import java.io.IOException;
017: import java.io.Reader;
018: import java.util.Map;
019: import javax.servlet.ServletException;
020: import javax.servlet.http.HttpServletRequest;
021: import javax.servlet.http.HttpServletResponse;
022:
023: /**
024: * WMS service wich returns request and response handlers to manage a GetMap
025: * request
026: *
027: * @author Gabriel Rold?n
028: * @version $Id: GetMap.java 6326 2007-03-15 18:36:40Z jdeolive $
029: */
030: public class GetMap extends WMService {
031: /**
032: * Part of HTTP content type header.
033: */
034: public static final String URLENCODED = "application/x-www-form-urlencoded";
035:
036: /**
037: * Creates a new GetMap object.
038: *
039: */
040: public GetMap(WMS wms) {
041: super ("GetMap", wms);
042: }
043:
044: protected GetMap(String id, WMS wms) {
045: super (id, wms);
046: }
047:
048: // TODO: check is this override adds any value compared to the superclass one,
049: // remove otherwise
050: public void doPost(HttpServletRequest request,
051: HttpServletResponse response) throws ServletException,
052: IOException {
053: //If the post is of mime-type application/x-www-form-urlencoded
054: //Then the get system can handle it. For all other requests the
055: //post code must handle it.
056: if (isURLEncoded(request)) {
057: doGet(request, response);
058:
059: return;
060: }
061:
062: //DJB: added post support
063: Request serviceRequest = null;
064:
065: // this.curRequest = request;
066: if (!isServiceEnabled(request)) {
067: sendDisabledServiceError(response);
068:
069: return;
070: }
071:
072: //we need to construct an approriate serviceRequest from the GetMap XML POST.
073: try {
074: GetMapXmlReader xmlPostReader = new GetMapXmlReader(this );
075:
076: Reader xml = request.getReader();
077: serviceRequest = xmlPostReader.read(xml, request);
078: } catch (ServiceException se) {
079: sendError(request, response, se);
080:
081: return;
082: } catch (Throwable e) {
083: sendError(request, response, e);
084:
085: return;
086: }
087:
088: doService(request, response, serviceRequest);
089: }
090:
091: /**
092: * DOCUMENT ME!
093: *
094: * @return DOCUMENT ME!
095: */
096: protected Response getResponseHandler() {
097: return new GetMapResponse(getWMS(), getApplicationContext());
098: }
099:
100: /**
101: * DOCUMENT ME!
102: *
103: * @return DOCUMENT ME!
104: *
105: * @throws java.lang.UnsupportedOperationException DOCUMENT ME!
106: */
107: protected XmlRequestReader getXmlRequestReader() {
108: return new GetMapXmlReader(this );
109: }
110:
111: /**
112: * DOCUMENT ME!
113: *
114: * @param params DOCUMENT ME!
115: *
116: * @return DOCUMENT ME!
117: */
118: protected KvpRequestReader getKvpReader(Map params) {
119: Map layers = this .getWMS().getBaseMapLayers();
120: Map styles = this .getWMS().getBaseMapStyles();
121:
122: GetMapKvpReader kvp = new GetMapKvpReader(params, this );
123:
124: // filter layers and styles if the user specified "layers=basemap"
125: // This must happen after the kvp reader has been initially called
126: if ((layers != null) && !layers.equals("")) {
127: kvp.filterBaseMap(layers, styles);
128: }
129:
130: return kvp;
131: }
132:
133: /**
134: * A method that decides if a request is a multipart request.
135: * <p>
136: * <a href="http://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type">w3.org content type</a>
137: * </p>
138: *
139: * @param req the servlet request
140: * @return if this is multipart or not
141: */
142: public boolean isURLEncoded(HttpServletRequest req) {
143: //Get the content type from the request
144: String contentType = req.getContentType();
145:
146: //If there is no content type, then it is not multipart
147: if (contentType == null) {
148: return false;
149: }
150:
151: //If it starts with multipart/ then it is multipart
152: return contentType.toLowerCase().startsWith(URLENCODED);
153: }
154: }
|