Esri Geoportal Server
1.0

com.esri.gpt.framework.context
Class BaseServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.esri.gpt.framework.context.BaseServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig
Direct Known Subclasses:
AsnServlet, CswServlet, IndexStatsServlet, ManageDocumentServlet, OpenSearchDescriptionServlet, RepositoriesServlet, RestQueryServlet, RestServlet, ServletConnector, ServletSavedSearch, SitemapServlet, ThumbnailServlet, TocServlet

public abstract class BaseServlet
extends HttpServlet

Super-class for HttpServlet end-points.

See Also:
Serialized Form

Constructor Summary
BaseServlet()
           
 
Method Summary
protected  void authenticate(RequestContext context, Credentials credentials)
          Authenticate credentials found within and HTTP request.
protected  void doGet(HttpServletRequest request, HttpServletResponse response)
          Handles a GET request.
protected  void doPost(HttpServletRequest request, HttpServletResponse response)
          Handles a POST request.
protected abstract  void execute(HttpServletRequest request, HttpServletResponse response, RequestContext context)
          Processes the HTTP request.
protected  UsernamePasswordCredentials getCredentials(HttpServletRequest request)
          Looks for username:password credentials within the Authorization header parameter of the HTTP request.
protected  Logger getLogger()
          Gets the logger.
protected  String getParameterValue(HttpServletRequest request, String name)
          Gets a request parameter value.
protected  String getRealm(RequestContext context)
          Gets the identity store realm (used as an identifier during HTTP 401 credential challenge/response).
protected  String readInputCharacters(HttpServletRequest request)
          Fully reads the characters from the request input stream.
protected  void writeCharacterResponse(HttpServletResponse response, String content, String charset, String contentType)
          Writes characters to the response stream.
protected  void writeHtmlResponse(HttpServletResponse response, String content)
          Convience method for writeCharacterResponse.
protected  void writeXmlResponse(HttpServletResponse response, String content)
          Convience method for writeCharacterResponse.
 
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, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseServlet

public BaseServlet()
Method Detail

authenticate

protected void authenticate(RequestContext context,
                            Credentials credentials)
                     throws CredentialsDeniedException,
                            IdentityException,
                            SQLException
Authenticate credentials found within and HTTP request.

Parameters:
context - the active request context
credentials - the credentials to authenticate
Throws:
CredentialsDeniedException - if credentials are denied
IdentityException - if a system error occurs preventing authentication
SQLException - if a database communication exception occurs

doGet

protected void doGet(HttpServletRequest request,
                     HttpServletResponse response)
              throws ServletException,
                     IOException
Handles a GET request.

The default behavior is the execute the doPost method.

Overrides:
doGet in class HttpServlet
Parameters:
request - the servlet request
response - the servlet response
Throws:
ServletException
IOException

doPost

protected void doPost(HttpServletRequest request,
                      HttpServletResponse response)
               throws ServletException,
                      IOException
Handles a POST request.

The default behavior:

  • set the character encoding (UTF-8) if it is null
  • instantiate a RequestContext
  • authenticate credentials if found within the header
  • invoke the abstract "execute" method
  • release the request context
  • Overrides:
    doPost in class HttpServlet
    Parameters:
    request - the servlet request
    response - the servlet response
    Throws:
    ServletException
    IOException

    execute

    protected abstract void execute(HttpServletRequest request,
                                    HttpServletResponse response,
                                    RequestContext context)
                             throws Exception
    Processes the HTTP request.

    Parameters:
    request - the HTTP request
    response - HTTP response
    context - request context
    Throws:
    Exception - if an exception occurs

    getCredentials

    protected UsernamePasswordCredentials getCredentials(HttpServletRequest request)
                                                  throws IOException,
                                                         CredentialsDeniedException
    Looks for username:password credentials within the Authorization header parameter of the HTTP request.

    Parameters:
    request - the servlet request
    Returns:
    the credentials (null if none were located)
    Throws:
    IOException - if an IO exception occurs
    CredentialsDeniedException - if empty or non-basic credentials were located

    getLogger

    protected Logger getLogger()
    Gets the logger.

    Returns:
    the logger

    getParameterValue

    protected String getParameterValue(HttpServletRequest request,
                                       String name)
    Gets a request parameter value.

    Parameters:
    request - the HTTP request
    name - the parameter name
    Returns:
    ther parameter value

    getRealm

    protected String getRealm(RequestContext context)
    Gets the identity store realm (used as an identifier during HTTP 401 credential challenge/response).

    Parameters:
    context - the active request context
    Returns:
    the identity store realm

    readInputCharacters

    protected String readInputCharacters(HttpServletRequest request)
                                  throws IOException
    Fully reads the characters from the request input stream.

    Parameters:
    request - the HTTP servlet request
    Returns:
    the characters read
    Throws:
    IOException - if an exception occurs

    writeCharacterResponse

    protected void writeCharacterResponse(HttpServletResponse response,
                                          String content,
                                          String charset,
                                          String contentType)
                                   throws IOException
    Writes characters to the response stream.

    Parameters:
    response - the servlet response
    content - the content to write
    charset - the response character encoding
    contentType - the response content type
    Throws:
    IOException - if an IO exception occurs

    writeHtmlResponse

    protected void writeHtmlResponse(HttpServletResponse response,
                                     String content)
                              throws IOException
    Convience method for writeCharacterResponse.
    charset="UTF-8"
    contentType="text/html; charset=UTF-8"

    Parameters:
    response - the servlet response
    content - the content to write
    Throws:
    IOException - if an IO exception occurs

    writeXmlResponse

    protected void writeXmlResponse(HttpServletResponse response,
                                    String content)
                             throws IOException
    Convience method for writeCharacterResponse.
    charset="UTF-8"
    contentType="text/xml; charset=UTF-8"

    Parameters:
    response - the servlet response
    content - the content to write
    Throws:
    IOException - if an IO exception occurs

    Esri Geoportal Server
    1.0

    Copyright 2011 Environmental Systems Research Institute. All rights reserved. Use is subject to license terms.