Betty v1.1.0

christophedelory.servlet
Class AbstractHttpServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by christophedelory.servlet.AbstractHttpServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig
Direct Known Subclasses:
AddBetterHttpServlet, AddPlayerScoreHttpServlet, AddUserHttpServlet, AddXmlHttpServlet, BetHttpServlet, GetChampionshipInfoHttpServlet, ListChampionshipsHttpServlet, ListLocationsHttpServlet, ListPlayersHttpServlet, ListResourcesHttpServlet, ListUsersHttpServlet, LoginHttpServlet, LogoutHttpServlet, ProcessChampionshipHttpServlet, RemoveBetterHttpServlet, RemoveChampionshipHttpServlet, RemoveLocationHttpServlet, RemovePlayerHttpServlet, RemoveResourceHttpServlet, RemoveUserHttpServlet, RSSHttpServlet, UpdateBetterHttpServlet

public abstract class AbstractHttpServlet
extends HttpServlet

The base implementation of an HTTP servlet in our project.

Version:
$Revision: 99 $
Author:
Christophe Delory
See Also:
Serialized Form

Constructor Summary
AbstractHttpServlet()
           
 
Method Summary
protected  void doGet(HttpServletRequest req, HttpServletResponse resp)
           
protected  void doPost(HttpServletRequest req, HttpServletResponse resp)
           
protected  void doPut(HttpServletRequest req, HttpServletResponse resp)
           
protected  Object getEnvEntry(String jndiName, Object defaultValue)
          Returns the servlet environment entry specified through its JNDI name.
protected  String[] getLocales(HttpServletRequest request)
          Returns the preferred locales that the client will accept content in, based first on the "locale" parameter, then on the Accept-Language header.
protected  String getParameter(HttpServletRequest request, String name)
          Returns the value of a request parameter as a String, or null if the parameter does not exist or is empty.
protected  void sendError(HttpServletResponse resp, int sc, String msg)
          Sends an error response to the client using the specified status.
protected  void sendError(HttpServletResponse resp, int sc, Throwable error)
          Sends an error response to the client using the specified exception.
protected  void sendResponse(HttpServletResponse resp, Object xml, String packageName)
          Sends an XML response to the client.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, 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

AbstractHttpServlet

public AbstractHttpServlet()
Method Detail

doPost

protected void doPost(HttpServletRequest req,
                      HttpServletResponse resp)
               throws IOException,
                      ServletException
Overrides:
doPost in class HttpServlet
Throws:
IOException
ServletException

doGet

protected void doGet(HttpServletRequest req,
                     HttpServletResponse resp)
              throws IOException,
                     ServletException
Overrides:
doGet in class HttpServlet
Throws:
IOException
ServletException

doPut

protected void doPut(HttpServletRequest req,
                     HttpServletResponse resp)
              throws IOException,
                     ServletException
Overrides:
doPut in class HttpServlet
Throws:
IOException
ServletException

sendError

protected void sendError(HttpServletResponse resp,
                         int sc,
                         String msg)
                  throws IOException
Sends an error response to the client using the specified status. The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message, setting the content type to "text/html", leaving cookies and other headers unmodified. If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back in preference to the suggested msg parameter.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Parameters:
resp - an HttpServletResponse object that contains the response the servlet sends to the client. Shall not be null.
sc - the error status code.
msg - the descriptive message. Shall not be null.
Throws:
IOException - if an input or output exception occurs.
IllegalStateException - if the response was committed.
NullPointerException - if resp is null.
NullPointerException - if msg is null.
See Also:
HttpServletResponse.sendError(int,String), sendError(HttpServletResponse,int,Throwable)

sendError

protected void sendError(HttpServletResponse resp,
                         int sc,
                         Throwable error)
                  throws IOException
Sends an error response to the client using the specified exception. The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message, setting the content type to "text/html", leaving cookies and other headers unmodified. If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back in preference to the suggested msg parameter.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Parameters:
resp - an HttpServletResponse object that contains the response the servlet sends to the client. Shall not be null.
sc - the error status code.
error - an exception. Shall not be null.
Throws:
IOException - if an input or output exception occurs.
IllegalStateException - if the response was committed.
NullPointerException - if resp is null.
NullPointerException - if error is null.
See Also:
HttpServletResponse.sendError(int,String), sendError(HttpServletResponse,int,String)

sendResponse

protected void sendResponse(HttpServletResponse resp,
                            Object xml,
                            String packageName)
                     throws IOException
Sends an XML response to the client.

Parameters:
resp - an HttpServletResponse object that contains the response the servlet sends to the client. Shall not be null.
xml - the object to serialize. Shall not be null.
packageName - the package name. May be null.
Throws:
NullPointerException - if resp is null.
NullPointerException - if xml is null.
IOException - if an input or output exception occurs.
IllegalStateException - if the response was committed.
UnsupportedEncodingException - if the character encoding returned by ServletResponse.getCharacterEncoding() cannot be used.
IllegalStateException - if the ServletResponse.getOutputStream() method has already been called for this response object.
See Also:
XmlSerializer.getMapping(String), XmlSerializer.marshal(Object,java.io.Writer,boolean)

getParameter

protected String getParameter(HttpServletRequest request,
                              String name)
Returns the value of a request parameter as a String, or null if the parameter does not exist or is empty. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use ServletRequest.getParameterValues(String).
If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned by getParameterValues.
If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body directly via ServletRequest.getInputStream() or ServletRequest.getReader() can interfere with the execution of this method.

Parameters:
request - an HttpServletRequest object that contains the request the client has made of the servlet. Shall not be null.
name - a String specifying the name of the parameter.
Returns:
a String representing the single value of the parameter.
Throws:
NullPointerException - if request is null.

getEnvEntry

protected Object getEnvEntry(String jndiName,
                             Object defaultValue)
                      throws NamingException
Returns the servlet environment entry specified through its JNDI name.

Parameters:
jndiName - the JNDI name to search for. Should not be null.
defaultValue - a default value. May be null.
Returns:
the value found. May be null if missing.
Throws:
NullPointerException - if jndiName is null.
NamingException - if a naming exception is encountered.

getLocales

protected String[] getLocales(HttpServletRequest request)
Returns the preferred locales that the client will accept content in, based first on the "locale" parameter, then on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server.

Parameters:
request - an HttpServletRequest object that contains the request the client has made of the servlet. Shall not be null.
Returns:
the preferred locales for the client. Shall not be null nor empty.
Throws:
NullPointerException - if request is null.
See Also:
ServletRequest.getLocales()

© 2008-2009 Christophe Delory

Copyright © 2008-2009 Christophe Delory. All Rights Reserved.