Package uk.ac.rdg.resc.edal.wms
Class WmsServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- uk.ac.rdg.resc.edal.wms.WmsServlet
-
- All Implemented Interfaces:
Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
public class WmsServlet extends javax.servlet.http.HttpServlet
The main servlet for all WMS operations, including extended behaviour. This servlet can be used as-is by defining it in the usual way in a web.xml file, and injecting aWmsCatalogue
object by calling thesetCatalogue(WmsCatalogue)
. If theWmsCatalogue
is not set, behaviour is undefined. It'll fail in all sorts of ways - nothing will work properly. However, theWmsCatalogue
set insetCatalogue(WmsCatalogue)
is only directly used indispatchWmsRequest(String, RequestParams, HttpServletRequest, HttpServletResponse, WmsCatalogue)
, so if it is not set, a subclass can still override that method and inject aWmsCatalogue
on a per-request basis. The recommended usage is to either subclass this servlet and set a valid instance of aWmsCatalogue
in the constructor/init method or to use Spring to do the wiring for you.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
AXIS_RESOLUTION
protected static String[]
DEFAULT_SUPPORTED_CRS_CODES
protected static String
FEATURE_INFO_HTML_FORMAT
protected static String
FEATURE_INFO_PLAIN_FORMAT
protected static String
FEATURE_INFO_XML_FORMAT
protected org.apache.velocity.app.VelocityEngine
velocityEngine
-
Constructor Summary
Constructors Constructor Description WmsServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.json.JSONArray
addVariablesToArray(Set<VariableMetadata> variables, String datasetId, WmsCatalogue catalogue)
protected void
dispatchWmsRequest(String request, RequestParams params, javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue)
Sends the HTTP request to the appropriate WMS methodprotected void
doGet(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
protected Extent<Double>
extractSectionElevation(String depthString)
protected void
getCapabilities(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, String baseUrl, WmsCatalogue catalogue)
protected WmsCatalogue
getCatalogue()
Gets theWmsCatalogue
used in this servlet.String[]
getCrsCodes()
protected void
getFeatureInfo(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue)
protected FeatureInfoPoint
getFeatureInfoValuesFromFeature(DiscreteFeature<?,?> feature, String variableId, PlottingDomainParams plottingParameters, String layerName, String featureName, VariableMetadata metadata)
Extracts the target value from a featureprotected void
getLegendGraphic(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue)
protected void
getMap(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue)
protected void
getMetadata(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue)
Handles returning metadata about a requested layer.protected void
getTimeseries(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue)
protected void
getTransect(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue)
protected void
getVerticalProfile(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue)
protected void
handleWmsException(EdalException exception, javax.servlet.http.HttpServletResponse httpServletResponse, boolean v130)
WrapsEdalException
s in an XML wrapper and returns them.protected void
setCapabilitiesAdvertisedPalettes(Collection<String> paletteNames)
Sets the palettes to be advertised in the GetCapabilities document.void
setCatalogue(WmsCatalogue catalogue)
Sets aWmsCatalogue
to be used globally for all requests.void
setCrsCodes(String[] SupportedCrsCodes)
protected String
showAnimationTimesteps(RequestParams params, WmsCatalogue catalogue)
protected String
showLayerDetails(RequestParams params, WmsCatalogue catalogue)
protected String
showMenu(RequestParams params, WmsCatalogue catalogue)
protected String
showMinMax(RequestParams params, WmsCatalogue catalogue)
protected String
showTimesteps(RequestParams params, WmsCatalogue catalogue)
-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
-
-
-
-
Field Detail
-
AXIS_RESOLUTION
public static final int AXIS_RESOLUTION
- See Also:
- Constant Field Values
-
FEATURE_INFO_XML_FORMAT
protected static final String FEATURE_INFO_XML_FORMAT
- See Also:
- Constant Field Values
-
FEATURE_INFO_PLAIN_FORMAT
protected static final String FEATURE_INFO_PLAIN_FORMAT
- See Also:
- Constant Field Values
-
FEATURE_INFO_HTML_FORMAT
protected static final String FEATURE_INFO_HTML_FORMAT
- See Also:
- Constant Field Values
-
DEFAULT_SUPPORTED_CRS_CODES
protected static final String[] DEFAULT_SUPPORTED_CRS_CODES
-
velocityEngine
protected final org.apache.velocity.app.VelocityEngine velocityEngine
-
-
Method Detail
-
setCatalogue
public void setCatalogue(WmsCatalogue catalogue)
Sets aWmsCatalogue
to be used globally for all requests. If no catalogue is set and thisServlet
is used then it will fail with aNullPointerException
on the vast majority of calls. Note that thisWmsCatalogue
is only used in theWmsServlet#dispatchWmsRequest(String, RequestParams, HttpServletRequest, HttpServletResponse)
method, which passes it to all of the worker methods. Thus, a differentWmsCatalogue
can be used for each request if required (for example to have dataset/variable defined by the URL) by subclassingWmsServlet
and overridingWmsServlet#dispatchWmsRequest(String, RequestParams, HttpServletRequest, HttpServletResponse)
such that it passes a new catalogue to each of those methods- Parameters:
catalogue
- TheWmsCatalogue
to use.
-
getCatalogue
protected WmsCatalogue getCatalogue()
Gets theWmsCatalogue
used in this servlet. Subclasses may wish to use this method to get direct access to the catalogue if (for example) implementing new, non-WMS extensions.- Returns:
- The
WmsCatalogue
associated with this servlet.
-
setCapabilitiesAdvertisedPalettes
protected void setCapabilitiesAdvertisedPalettes(Collection<String> paletteNames)
Sets the palettes to be advertised in the GetCapabilities document. In the capabilities document, each layer will advertise the available styles. Since some styles can use palettes, this means that the capabilities document can get very large very quickly with the formula: (styles which use palettes) x (number of palettes) x (number of layers) being an approximation of how many Style tags are defined in the document. This is impractical, so we limit the number of advertised palettes. By default, this will only include the default palette name. This method takes aList
of palette names to advertise alongside the default.- Parameters:
paletteNames
- The palettes to advertise alongside the default.
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws javax.servlet.ServletException, IOException
- Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
- See Also:
HttpServlet.doGet(HttpServletRequest request, HttpServletResponse response)
-
dispatchWmsRequest
protected void dispatchWmsRequest(String request, RequestParams params, javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue) throws Exception
Sends the HTTP request to the appropriate WMS method- Parameters:
request
- The URL REQUEST parameterparams
- A map of URL parameters, implemented in a case-insensitive wayhttpServletRequest
- TheHttpServletRequest
object from the GET requesthttpServletResponse
- TheHttpServletResponse
object from the GET requestcatalogue
- TheWmsCatalogue
which should be used to serve datasets.- Throws:
Exception
-
getMap
protected void getMap(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue) throws EdalException
- Throws:
EdalException
-
getCapabilities
protected void getCapabilities(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, String baseUrl, WmsCatalogue catalogue) throws EdalException
- Throws:
EdalException
-
getFeatureInfo
protected void getFeatureInfo(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue) throws EdalException
- Throws:
EdalException
-
getFeatureInfoValuesFromFeature
protected FeatureInfoPoint getFeatureInfoValuesFromFeature(DiscreteFeature<?,?> feature, String variableId, PlottingDomainParams plottingParameters, String layerName, String featureName, VariableMetadata metadata)
Extracts the target value from a feature- Parameters:
feature
- The feature to extract the value fromvariableId
- The name of the variable within the featureplottingParameters
- ThePlottingDomainParams
defining the target value to extractlayerName
- The layer name to add to theFeatureInfoPoint
featureName
- The feature name to add to theFeatureInfoPoint
metadata
- TheVariableMetadata
of the layer being queried- Returns:
- The extracted value and corresponding information collected as a
FeatureInfoPoint
-
getMetadata
protected void getMetadata(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue) throws MetadataException
Handles returning metadata about a requested layer.- Parameters:
params
- The URL parametershttpServletResponse
- The response object to write out tocatalogue2
-- Throws:
MetadataException
- If there are any issues with returning the metadata
-
showMenu
protected String showMenu(RequestParams params, WmsCatalogue catalogue) throws MetadataException
- Throws:
MetadataException
-
addVariablesToArray
protected org.json.JSONArray addVariablesToArray(Set<VariableMetadata> variables, String datasetId, WmsCatalogue catalogue) throws EdalLayerNotFoundException
- Throws:
EdalLayerNotFoundException
-
showLayerDetails
protected String showLayerDetails(RequestParams params, WmsCatalogue catalogue) throws MetadataException
- Throws:
MetadataException
-
showTimesteps
protected String showTimesteps(RequestParams params, WmsCatalogue catalogue) throws MetadataException
- Throws:
MetadataException
-
showMinMax
protected String showMinMax(RequestParams params, WmsCatalogue catalogue) throws MetadataException
- Throws:
MetadataException
-
showAnimationTimesteps
protected String showAnimationTimesteps(RequestParams params, WmsCatalogue catalogue) throws MetadataException
- Throws:
MetadataException
-
getLegendGraphic
protected void getLegendGraphic(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue) throws EdalException
- Throws:
EdalException
-
getTimeseries
protected void getTimeseries(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue) throws EdalException
- Throws:
EdalException
-
getTransect
protected void getTransect(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue) throws EdalException
- Throws:
EdalException
-
getVerticalProfile
protected void getVerticalProfile(RequestParams params, javax.servlet.http.HttpServletResponse httpServletResponse, WmsCatalogue catalogue) throws EdalException
- Throws:
EdalException
-
handleWmsException
protected void handleWmsException(EdalException exception, javax.servlet.http.HttpServletResponse httpServletResponse, boolean v130) throws IOException
WrapsEdalException
s in an XML wrapper and returns them.- Parameters:
exception
- The exception to handlehttpServletResponse
- TheHttpServletResponse
object to write tov130
- Whether this should be handled as a WMS v1.3.0 exception- Throws:
IOException
- If there is a problem writing to the output stream
-
setCrsCodes
public void setCrsCodes(String[] SupportedCrsCodes)
-
getCrsCodes
public String[] getCrsCodes()
-
-