org.apache.pivot.web.server
Class QueryServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.apache.pivot.web.server.QueryServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public abstract class QueryServlet
extends HttpServlet

Abstract base class for query servlets.

See Also:
Serialized Form

Nested Class Summary
static class QueryServlet.Path
          Immutable string sequence representing a query path.
 
Field Summary
static String CONTENT_LENGTH_HEADER
           
static String CONTENT_TYPE_HEADER
           
static String HTTP_PROTOCOL
           
static String HTTPS_PROTOCOL
           
static String LOCATION_HEADER
           
static String URL_ENCODING
           
 
Constructor Summary
QueryServlet()
           
 
Method Summary
protected abstract  Serializer<?> createSerializer(Query.Method method, QueryServlet.Path path)
          Creates a serializer that will be used to serialize the current request data.
protected  void dispose()
          Disposes any resources allocated in prepare().
protected  void doDelete(HttpServletRequest request, HttpServletResponse response)
           
protected  void doDelete(QueryServlet.Path path)
          Handles an HTTP GET request.
protected  void doGet(HttpServletRequest request, HttpServletResponse response)
           
protected  Object doGet(QueryServlet.Path path)
          Handles an HTTP GET request.
protected  void doHead(HttpServletRequest request, HttpServletResponse response)
           
protected  void doOptions(HttpServletRequest request, HttpServletResponse response)
           
protected  void doPost(HttpServletRequest request, HttpServletResponse response)
           
protected  URL doPost(QueryServlet.Path path, Object value)
          Handles an HTTP POST request.
protected  void doPut(HttpServletRequest request, HttpServletResponse response)
           
protected  boolean doPut(QueryServlet.Path path, Object value)
          Handles an HTTP GET request.
protected  void doTrace(HttpServletRequest request, HttpServletResponse response)
           
 String getContextPath()
          Returns the portion of the request URL representing the context path.
 String getHostname()
          Gets the host name that was requested.
 URL getLocation()
          Returns the location of this servlet.
 QueryDictionary getParameters()
          Returns the servlet's parameter dictionary, which holds the values passed in the HTTP request query string.
 int getPort()
          Returns the Internet Protocol (IP) port number of the interface on which the request was received.
 String getProtocol()
          Returns the name of the HTTP protocol that the request is using.
 QueryDictionary getRequestHeaders()
          Returns the servlet's request header dictionary, which holds the HTTP request headers.
 QueryDictionary getResponseHeaders()
          Returns the servlet's response header dictionary, which holds the HTTP response headers that will be sent back to the client.
 String getServletPath()
          Returns the portion of the request URL representing the servlet path.
 boolean isSecure()
          Tells whether the request has been ecrypted over HTTPS.
protected  void prepare()
          Prepares a servlet for request execution.
protected  void service(HttpServletRequest request, HttpServletResponse response)
           
protected  void validate(Query.Method method, QueryServlet.Path path)
          Validates a servlet for request execution.
 
Methods inherited from class javax.servlet.http.HttpServlet
getLastModified, 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
 

Field Detail

HTTP_PROTOCOL

public static final String HTTP_PROTOCOL
See Also:
Constant Field Values

HTTPS_PROTOCOL

public static final String HTTPS_PROTOCOL
See Also:
Constant Field Values

URL_ENCODING

public static final String URL_ENCODING
See Also:
Constant Field Values

CONTENT_TYPE_HEADER

public static final String CONTENT_TYPE_HEADER
See Also:
Constant Field Values

CONTENT_LENGTH_HEADER

public static final String CONTENT_LENGTH_HEADER
See Also:
Constant Field Values

LOCATION_HEADER

public static final String LOCATION_HEADER
See Also:
Constant Field Values
Constructor Detail

QueryServlet

public QueryServlet()
Method Detail

getHostname

public String getHostname()
Gets the host name that was requested.


getPort

public int getPort()
Returns the Internet Protocol (IP) port number of the interface on which the request was received.


getContextPath

public String getContextPath()
Returns the portion of the request URL representing the context path.


getServletPath

public String getServletPath()
Returns the portion of the request URL representing the servlet path.


isSecure

public boolean isSecure()
Tells whether the request has been ecrypted over HTTPS.


getProtocol

public String getProtocol()
Returns the name of the HTTP protocol that the request is using.


getLocation

public URL getLocation()
Returns the location of this servlet.


getParameters

public QueryDictionary getParameters()
Returns the servlet's parameter dictionary, which holds the values passed in the HTTP request query string.


getRequestHeaders

public QueryDictionary getRequestHeaders()
Returns the servlet's request header dictionary, which holds the HTTP request headers.


getResponseHeaders

public QueryDictionary getResponseHeaders()
Returns the servlet's response header dictionary, which holds the HTTP response headers that will be sent back to the client.


prepare

protected void prepare()
                throws ServletException
Prepares a servlet for request execution. This method is called immediately prior to the validate(Query.Method, Path) method.

The default implementation is a no-op.

Throws:
ServletException

dispose

protected void dispose()
                throws ServletException
Disposes any resources allocated in prepare(). This method is guaranteed to be called even if the HTTP handler method throws.

The default implementation is a no-op.

Throws:
ServletException

validate

protected void validate(Query.Method method,
                        QueryServlet.Path path)
                 throws QueryException
Validates a servlet for request execution. This method is called immediately prior to the HTTP handler method.

The default implementation is a no-op.

Parameters:
method -
path -
Throws:
QueryException

doGet

protected Object doGet(QueryServlet.Path path)
                throws QueryException
Handles an HTTP GET request. The default implementation throws an HTTP 405 query exception.

Parameters:
path -
Returns:
The result of the GET.
Throws:
QueryException

doPost

protected URL doPost(QueryServlet.Path path,
                     Object value)
              throws QueryException
Handles an HTTP POST request. The default implementation throws an HTTP 405 query exception.

Parameters:
path -
value -
Returns:
A URL containing the location of the created resource, or null if operation did not result in the creation of a resource.
Throws:
QueryException

doPut

protected boolean doPut(QueryServlet.Path path,
                        Object value)
                 throws QueryException
Handles an HTTP GET request. The default implementation throws an HTTP 405 query exception.

Parameters:
path -
value -
Returns:
true if the operation resulted in the creation of a resource; false, otherwise.
Throws:
QueryException

doDelete

protected void doDelete(QueryServlet.Path path)
                 throws QueryException
Handles an HTTP GET request. The default implementation throws an HTTP 405 query exception.

Parameters:
path -
Throws:
QueryException

createSerializer

protected abstract Serializer<?> createSerializer(Query.Method method,
                                                  QueryServlet.Path path)
                                           throws QueryException
Creates a serializer that will be used to serialize the current request data.

Parameters:
method -
path -
Throws:
QueryException

service

protected void service(HttpServletRequest request,
                       HttpServletResponse response)
                throws IOException,
                       ServletException
Overrides:
service in class HttpServlet
Throws:
IOException
ServletException

doGet

protected final void doGet(HttpServletRequest request,
                           HttpServletResponse response)
                    throws IOException,
                           ServletException
Overrides:
doGet in class HttpServlet
Throws:
IOException
ServletException

doPost

protected final void doPost(HttpServletRequest request,
                            HttpServletResponse response)
                     throws IOException,
                            ServletException
Overrides:
doPost in class HttpServlet
Throws:
IOException
ServletException

doPut

protected final void doPut(HttpServletRequest request,
                           HttpServletResponse response)
                    throws IOException,
                           ServletException
Overrides:
doPut in class HttpServlet
Throws:
IOException
ServletException

doDelete

protected final void doDelete(HttpServletRequest request,
                              HttpServletResponse response)
                       throws IOException,
                              ServletException
Overrides:
doDelete in class HttpServlet
Throws:
IOException
ServletException

doHead

protected final void doHead(HttpServletRequest request,
                            HttpServletResponse response)
                     throws IOException,
                            ServletException
Overrides:
doHead in class HttpServlet
Throws:
IOException
ServletException

doOptions

protected final void doOptions(HttpServletRequest request,
                               HttpServletResponse response)
                        throws IOException,
                               ServletException
Overrides:
doOptions in class HttpServlet
Throws:
IOException
ServletException

doTrace

protected final void doTrace(HttpServletRequest request,
                             HttpServletResponse response)
                      throws IOException,
                             ServletException
Overrides:
doTrace in class HttpServlet
Throws:
IOException
ServletException