pivot.web.server
Class QueryServlet

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

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

Abstract base class for web query servlets. It is the server counterpart to pivot.web.Query.

Author:
tvolkert
See Also:
Serialized Form

Nested Class Summary
 class QueryServlet.ArgumentsDictionary
          Arguments dictionary implementation.
static class QueryServlet.Credentials
          User credentials, which will be made availale if the servlet's authenticationRequired flag is set to true.
protected static class QueryServlet.Method
          The supported HTTP methods.
 class QueryServlet.RequestPropertiesDictionary
          Request properties dictionary implementation.
 class QueryServlet.ResponsePropertiesDictionary
          Response properties dictionary implementation.
 
Constructor Summary
QueryServlet()
           
 
Method Summary
protected  void authorize()
          Authorizes the current request, and throws a LoginException if the request is not authorized.
protected  void doDelete()
           
protected  void doDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  java.lang.Object doGet()
           
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void doHead(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void doOptions(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  java.net.URL doPost(java.lang.Object value)
           
protected  void doPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void doPut(java.lang.Object value)
           
protected  void doTrace(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 QueryServlet.ArgumentsDictionary getArguments()
          Returns the servlet's arguments dictionary, which holds the values passed in the HTTP request query string.
 java.lang.String getContextPath()
          Returns the portion of the request URI that indicates the context of the request.
 QueryServlet.Credentials getCredentials()
          Gets the authentication credentials that were extracted from the request.
 java.lang.String getHostname()
          Gets the host name that was requested.
 QueryServlet.Method getMethod()
          Gets the HTTP method with which the current request was made.
 int getPort()
          Returns the Internet Protocol (IP) port number of the interface on which the request was received.
 java.lang.String getProtocol()
          Returns the name of the HTTP protocol that the request is using.
 java.lang.String getQueryPath()
          Returns the portion of the request URI that occurs after the context path but preceding the query string.
 QueryServlet.RequestPropertiesDictionary getRequestProperties()
          Returns the servlet's request property dictionary, which holds the HTTP request headers.
 QueryServlet.ResponsePropertiesDictionary getResponseProperties()
          Returns the servlet's response property dictionary, which holds the HTTP response headers that will be sent back to the client.
 Serializer<?> getSerializer()
          Returns the serializer used to stream the value passed to or from the web query.
 boolean isAuthenticationRequired()
          Tells whether or not this servlet will require authentication data.
 boolean isDetermineContentLength()
          Tells whether this servlet is configured to always determine the content length of outgoing responses and set the Content-Length HTTP response header accordingly.
 boolean isSecure()
          Tells whether the request has been ecrypted over HTTPS.
protected  void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 void setAuthenticationRequired(boolean authenticationRequired)
          Sets whether or not this servlet will require authentication data.
 void setDetermineContentLength(boolean determineContentLength)
          Sets the value of the determineContentLength flag.
 void setSerializer(Serializer<?> serializer)
          Sets the serializer used to stream the value passed to or from the web query.
 
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
 

Constructor Detail

QueryServlet

public QueryServlet()
Method Detail

getHostname

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


getContextPath

public java.lang.String getContextPath()
Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "".


getQueryPath

public java.lang.String getQueryPath()
Returns the portion of the request URI that occurs after the context path but preceding the query string. It will start with a "/" character. For servlets in the default (root) context, this method returns the full path.


getPort

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


isSecure

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


getProtocol

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


getMethod

public QueryServlet.Method getMethod()
Gets the HTTP method with which the current request was made.


isDetermineContentLength

public boolean isDetermineContentLength()
Tells whether this servlet is configured to always determine the content length of outgoing responses and set the Content-Length HTTP response header accordingly. If this flag is false, it is up to the servlet's discretion as to when to set the Content-Length header (it will do so if it is trivially easy). If this is set to true, it will force the servlet to always set the header, but doing so will incur a performance penalty, as the servlet will be unable to stream the response directly to the HTTP output stream as it gets serialized.


setDetermineContentLength

public void setDetermineContentLength(boolean determineContentLength)
Sets the value of the determineContentLength flag.

See Also:
isDetermineContentLength()

isAuthenticationRequired

public boolean isAuthenticationRequired()
Tells whether or not this servlet will require authentication data. If set to true, and un-authenticated requests are received, the servlet will automatically respond with a request for authentication.


setAuthenticationRequired

public void setAuthenticationRequired(boolean authenticationRequired)
Sets whether or not this servlet will require authentication data. If set to true, and un-authenticated requests are received, the servlet will automatically respond with a request for authentication.


getCredentials

public QueryServlet.Credentials getCredentials()
Gets the authentication credentials that were extracted from the request. These are only available if the authenticationRequired flag is set to true.


getArguments

public QueryServlet.ArgumentsDictionary getArguments()
Returns the servlet's arguments dictionary, which holds the values passed in the HTTP request query string.


getRequestProperties

public QueryServlet.RequestPropertiesDictionary getRequestProperties()
Returns the servlet's request property dictionary, which holds the HTTP request headers.


getResponseProperties

public QueryServlet.ResponsePropertiesDictionary getResponseProperties()
Returns the servlet's response property dictionary, which holds the HTTP response headers that will be sent back to the client.


getSerializer

public Serializer<?> getSerializer()
Returns the serializer used to stream the value passed to or from the web query. By default, an instance of JSONSerializer is used.


setSerializer

public void setSerializer(Serializer<?> serializer)
Sets the serializer used to stream the value passed to or from the web query.

Parameters:
serializer - The serializer (must be non-null).

doGet

protected java.lang.Object doGet()
                          throws javax.servlet.ServletException
Throws:
javax.servlet.ServletException

doPost

protected java.net.URL doPost(java.lang.Object value)
                       throws javax.servlet.ServletException
Throws:
javax.servlet.ServletException

doPut

protected void doPut(java.lang.Object value)
              throws javax.servlet.ServletException
Throws:
javax.servlet.ServletException

doDelete

protected void doDelete()
                 throws javax.servlet.ServletException
Throws:
javax.servlet.ServletException

authorize

protected void authorize()
                  throws javax.servlet.ServletException,
                         javax.security.auth.login.LoginException
Authorizes the current request, and throws a LoginException if the request is not authorized. This method will only be called if the authenticationRequired flag is set to true. Subclasses wishing to authorize the authenticated user credentials may override this method to perform that authorization. On the other hand, the authorize method of QueryServlet does nothing, so subclasses that wish to authenticate the request but not authorization it may simply not override this method.

This method is guaranteed to be called after the arguments and request properties have been made available.

Throws:
javax.security.auth.login.LoginException - Thrown if the request is not authorized
javax.servlet.ServletException

service

protected void service(javax.servlet.http.HttpServletRequest request,
                       javax.servlet.http.HttpServletResponse response)
                throws java.io.IOException,
                       javax.servlet.ServletException
Overrides:
service in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doGet

protected final void doGet(javax.servlet.http.HttpServletRequest request,
                           javax.servlet.http.HttpServletResponse response)
                    throws java.io.IOException,
                           javax.servlet.ServletException
Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doPost

protected final void doPost(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws java.io.IOException,
                            javax.servlet.ServletException
Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doPut

protected final void doPut(javax.servlet.http.HttpServletRequest request,
                           javax.servlet.http.HttpServletResponse response)
                    throws java.io.IOException,
                           javax.servlet.ServletException
Overrides:
doPut in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doDelete

protected final void doDelete(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
                       throws java.io.IOException,
                              javax.servlet.ServletException
Overrides:
doDelete in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doHead

protected final void doHead(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws java.io.IOException,
                            javax.servlet.ServletException
Overrides:
doHead in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doOptions

protected final void doOptions(javax.servlet.http.HttpServletRequest request,
                               javax.servlet.http.HttpServletResponse response)
                        throws java.io.IOException,
                               javax.servlet.ServletException
Overrides:
doOptions in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doTrace

protected final void doTrace(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
                      throws java.io.IOException,
                             javax.servlet.ServletException
Overrides:
doTrace in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException