org.restafarian.core.servlets
Class RestServletBase

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.restafarian.core.servlets.RestServletBase
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
ConfigurationInitializationServlet, SelectListServletBase

public abstract class RestServletBase
extends javax.servlet.http.HttpServlet

This is the base class for all of the REST servlets.

See Also:
Serialized Form

Field Summary
protected  javax.servlet.ServletContext context
           
protected  org.apache.commons.logging.Log log
           
 
Constructor Summary
RestServletBase()
           
 
Method Summary
 void destroy()
          Servlet destroy method.
abstract  void doDelete(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          The Servlet "doDelete()" method.
abstract  void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          The Servlet "doGet()" method.
abstract  void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          The Servlet "doPost()" method.
abstract  void doPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          The Servlet "doPut()" method.
protected static java.lang.String filter(java.lang.String value)
          Filter the specified string for characters that are sensitive to HTML interpreters, returning the string with these characters replaced by the corresponding character entities.
protected  java.lang.String getIdFromUrl(javax.servlet.http.HttpServletRequest req, java.lang.String servletPath)
          Returns the id present in the URL, if any.
protected  java.lang.String getNameSpaceUrl(javax.servlet.http.HttpServletRequest req)
          Returns the name space url.
protected  int getNumericIdFromUrl(javax.servlet.http.HttpServletRequest req, java.lang.String servletPath)
          Returns the id present in the URL, if any, as an int.
 void init(javax.servlet.ServletConfig config)
          Servlet init method.
protected  void sendError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int errorCode, java.lang.String errorMessage)
          Sends the HTTP error code and message, and logs the code and message if enabled.
protected  void sendError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int errorCode, java.lang.String errorMessage, java.lang.Throwable throwable)
          Sends the HTTP error code and message, and logs the code and message if enabled.
 void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          The Servlet "service" method.
 
Methods inherited from class javax.servlet.http.HttpServlet
doHead, doOptions, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
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

context

protected javax.servlet.ServletContext context

log

protected org.apache.commons.logging.Log log
Constructor Detail

RestServletBase

public RestServletBase()
Method Detail

service

public void service(javax.servlet.http.HttpServletRequest req,
                    javax.servlet.http.HttpServletResponse res)
             throws javax.servlet.ServletException,
                    java.io.IOException

The Servlet "service" method.

Overrides:
service in class javax.servlet.http.HttpServlet
Parameters:
req - the HttpServletRequest object
res - the HttpServletResponse object
Throws:
javax.servlet.ServletException
java.io.IOException

doGet

public abstract void doGet(javax.servlet.http.HttpServletRequest req,
                           javax.servlet.http.HttpServletResponse res)
                    throws javax.servlet.ServletException,
                           java.io.IOException

The Servlet "doGet()" method.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
req - the HttpServletRequest object
res - the HttpServletResponse object
Throws:
javax.servlet.ServletException
java.io.IOException

doPost

public abstract void doPost(javax.servlet.http.HttpServletRequest req,
                            javax.servlet.http.HttpServletResponse res)
                     throws javax.servlet.ServletException,
                            java.io.IOException

The Servlet "doPost()" method.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
req - the HttpServletRequest object
res - the HttpServletResponse object
Throws:
javax.servlet.ServletException
java.io.IOException

doPut

public abstract void doPut(javax.servlet.http.HttpServletRequest req,
                           javax.servlet.http.HttpServletResponse res)
                    throws javax.servlet.ServletException,
                           java.io.IOException

The Servlet "doPut()" method.

Overrides:
doPut in class javax.servlet.http.HttpServlet
Parameters:
req - the HttpServletRequest object
res - the HttpServletResponse object
Throws:
javax.servlet.ServletException
java.io.IOException

doDelete

public abstract void doDelete(javax.servlet.http.HttpServletRequest req,
                              javax.servlet.http.HttpServletResponse res)
                       throws javax.servlet.ServletException,
                              java.io.IOException

The Servlet "doDelete()" method.

Overrides:
doDelete in class javax.servlet.http.HttpServlet
Parameters:
req - the HttpServletRequest object
res - the HttpServletResponse object
Throws:
javax.servlet.ServletException
java.io.IOException

getNumericIdFromUrl

protected int getNumericIdFromUrl(javax.servlet.http.HttpServletRequest req,
                                  java.lang.String servletPath)

Returns the id present in the URL, if any, as an int.

Parameters:
req - the HttpServletRequest object
servletPath - the path to the servlet, including both the leading and trailing "/"
Returns:
the id present in the URL, if any

getIdFromUrl

protected java.lang.String getIdFromUrl(javax.servlet.http.HttpServletRequest req,
                                        java.lang.String servletPath)

Returns the id present in the URL, if any.

Parameters:
req - the HttpServletRequest object
servletPath - the path to the servlet, including both the leading and trailing "/"
Returns:
the id present in the URL, if any

getNameSpaceUrl

protected java.lang.String getNameSpaceUrl(javax.servlet.http.HttpServletRequest req)

Returns the name space url.

Parameters:
req - the HttpServletRequest object
Returns:
the name space url

filter

protected static java.lang.String filter(java.lang.String value)
Filter the specified string for characters that are sensitive to HTML interpreters, returning the string with these characters replaced by the corresponding character entities. Lifted from Struts ResponseUtils

Parameters:
value - The string to be filtered and returned
Returns:
The filtered string

sendError

protected void sendError(javax.servlet.http.HttpServletRequest req,
                         javax.servlet.http.HttpServletResponse res,
                         int errorCode,
                         java.lang.String errorMessage)
                  throws java.io.IOException

Sends the HTTP error code and message, and logs the code and message if enabled.

Parameters:
req - the HttpServletRequest object
res - the HttpServletResponse object
errorCode - the error code to send
errorMessage - the error message to send
Throws:
java.io.IOException

sendError

protected void sendError(javax.servlet.http.HttpServletRequest req,
                         javax.servlet.http.HttpServletResponse res,
                         int errorCode,
                         java.lang.String errorMessage,
                         java.lang.Throwable throwable)
                  throws java.io.IOException

Sends the HTTP error code and message, and logs the code and message if enabled.

Parameters:
req - the HttpServletRequest object
res - the HttpServletResponse object
errorCode - the error code to send
errorMessage - the error message to send
throwable - an optional exception
Throws:
java.io.IOException

init

public void init(javax.servlet.ServletConfig config)

Servlet init method.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Parameters:
config - the ServletConfig object

destroy

public void destroy()

Servlet destroy method.

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet


Copyright © 2008. All Rights Reserved.