|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.servlet.GenericServlet javax.servlet.http.HttpServlet org.vfny.geoserver.servlets.AbstractService
Represents a service that all others extend from. Subclasses should provide response and exception handlers as appropriate.
It is really important to adhere to the following workflow:
If anything goes wrong a ServiceException can be thrown and will be written to the output stream instead.
This is because we have to be sure that no exception have been produced before setting the response's content type, so we can set the exception specific content type; and that Response.getContentType is called AFTER Response.execute, since the MIME type can depend on any request parameter or another kind of desission making during the execute process. (i.e. FORMAT in WMS GetMap)
TODO: We need to call Response.abort() if anything goes wrong to allow the Response a chance to cleanup after itself.
Nested Class Summary | |
static interface |
AbstractService.ServiceStratagy
Interface used for ServiceMode stratagy objects. |
Field Summary | |
static java.util.Map |
serviceStratagys
GR: if SPEED, FILE and BUFFER are static instances, so their methods should be synchronized, ending in a not multiuser server, so I made saftyMode dynamically instantiated in init() and the stratagy choosed at server config level in web.xml. |
Constructor Summary | |
AbstractService()
|
Method Summary | |
protected void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
DOCUMENT ME! |
protected void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
DOCUMENT ME! |
protected void |
doService(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Request serviceRequest)
Peforms service according to ServiceStratagy. |
protected abstract ExceptionHandler |
getExceptionHandler()
DOCUMENT ME! |
protected abstract KvpRequestReader |
getKvpReader(java.util.Map params)
DOCUMENT ME! |
protected java.lang.String |
getMimeType()
DOCUMENT ME! |
protected abstract Response |
getResponseHandler()
DOCUMENT ME! |
protected abstract XmlRequestReader |
getXmlRequestReader()
DOCUMENT ME! |
void |
init(javax.servlet.ServletConfig config)
loads the "serviceStratagy" servlet context parameter and checks it if reffers to a valid ServiceStratagy (by now, one of SPEED, FILE or BUFFER); if no, just sets the stratagy to BUFFER as default |
protected boolean |
requestSupportsGzip(javax.servlet.http.HttpServletRequest request)
Checks if the client requests supports gzipped responses by quering it's 'accept-encoding' header. |
protected void |
send(javax.servlet.http.HttpServletResponse response,
java.lang.CharSequence content)
DOCUMENT ME! |
protected void |
send(javax.servlet.http.HttpServletResponse response,
Response result)
DOCUMENT ME! |
protected void |
sendError(javax.servlet.http.HttpServletResponse response,
ServiceException se)
Send a serviceException produced during getService opperation. |
protected void |
sendError(javax.servlet.http.HttpServletResponse response,
java.lang.Throwable t)
Send error produced during getService opperation. |
Methods inherited from class javax.servlet.http.HttpServlet |
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.util.Map serviceStratagys
Constructor Detail |
public AbstractService()
Method Detail |
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException
config
- the servlet environment
javax.servlet.ServletException
- if the configured stratagy class is not a
derivate of ServiceStratagy or it is thrown by the parent classprotected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
request
- DOCUMENT ME!response
- DOCUMENT ME!
javax.servlet.ServletException
- DOCUMENT ME!
java.io.IOException
- DOCUMENT ME!protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
request
- DOCUMENT ME!response
- DOCUMENT ME!
javax.servlet.ServletException
- DOCUMENT ME!
java.io.IOException
- DOCUMENT ME!protected void doService(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Request serviceRequest) throws javax.servlet.ServletException
This method has very strict requirements, please see the class description for the specifics.
It has a lot of try/catch blocks, but they are fairly necessary to handle things correctly and to avoid as many ugly servlet responses, so that everything is wrapped correctly.
request
- response
- serviceRequest
-
javax.servlet.ServletException
- if the stratagy can't be instantiatedprotected abstract Response getResponseHandler()
protected abstract KvpRequestReader getKvpReader(java.util.Map params)
params
- DOCUMENT ME!
ServiceException
- if the set of key/value pairs of parameters
defined by params
can't be parsed to a valid
RequestKvpReader
protected abstract XmlRequestReader getXmlRequestReader()
protected abstract ExceptionHandler getExceptionHandler()
protected java.lang.String getMimeType()
protected void send(javax.servlet.http.HttpServletResponse response, java.lang.CharSequence content)
response
- DOCUMENT ME!content
- DOCUMENT ME!protected void sendError(javax.servlet.http.HttpServletResponse response, java.lang.Throwable t)
Some errors know how to write themselves out WfsTransactionException for instance. It looks like this might be is handled by getExceptionHandler().newServiceException( t, pre, null ). I still would not mind seeing a check for ServiceConfig Exception here.
This code says that it deals with UNCAUGHT EXCEPTIONS, so I think it would be wise to explicitly catch ServiceExceptions.
response
- DOCUMENT ME!t
- DOCUMENT ME!protected void sendError(javax.servlet.http.HttpServletResponse response, ServiceException se)
response
- DOCUMENT ME!se
- DOCUMENT ME!protected void send(javax.servlet.http.HttpServletResponse response, Response result)
response
- DOCUMENT ME!result
- DOCUMENT ME!protected boolean requestSupportsGzip(javax.servlet.http.HttpServletRequest request)
request
- the request to query the HTTP header from
request
, false otherwise.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |