Package org.apache.pivot.web.server
Class QueryServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.apache.pivot.web.server.QueryServlet
-
- All Implemented Interfaces:
java.io.Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public abstract class QueryServlet extends javax.servlet.http.HttpServletAbstract base class for query servlets.Note that for better security, you should only use BinarySerializer in QueryServlet if you're sure the incoming requests will only come from trusted sources.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQueryServlet.PathImmutable string sequence representing a query path.
-
Constructor Summary
Constructors Constructor Description QueryServlet()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Serializer<?>createSerializer(Query.Method method, QueryServlet.Path path)Creates a serializer that will be used to serialize the current request data.protected voiddispose()Disposes any resources allocated inprepare().protected voiddoDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voiddoDelete(QueryServlet.Path path)Handles an HTTP DELETE request.protected voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected java.lang.ObjectdoGet(QueryServlet.Path path)Handles an HTTP GET request.protected voiddoHead(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voiddoOptions(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected java.net.URLdoPost(QueryServlet.Path path, java.lang.Object value)Handles an HTTP POST request.protected voiddoPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected booleandoPut(QueryServlet.Path path, java.lang.Object value)Handles an HTTP GET request.protected voiddoTrace(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)java.lang.StringgetContextPath()Returns the portion of the request URL representing the context path.java.lang.StringgetHostname()Gets the host name that was requested.java.net.URLgetLocation()Returns the location of this servlet.QueryDictionarygetParameters()Returns the servlet's parameter dictionary, which holds the values passed in the HTTP request query string.intgetPort()Returns the Internet Protocol (IP) port number of the interface on which the request was received.java.lang.StringgetProtocol()Returns the name of the HTTP protocol that the request is using.QueryDictionarygetRequestHeaders()Returns the servlet's request header dictionary, which holds the HTTP request headers.QueryDictionarygetResponseHeaders()Returns the servlet's response header dictionary, which holds the HTTP response headers that will be sent back to the client.java.lang.StringgetServletPath()Returns the portion of the request URL representing the servlet path.booleanisSecure()Tells whether the request has been encrypted over HTTPS.protected voidprepare()Prepares a servlet for request execution.protected voidservice(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voidvalidate(Query.Method method, QueryServlet.Path path)Validates a servlet for request execution.
-
-
-
Method Detail
-
getHostname
public java.lang.String getHostname()
Gets the host name that was requested.- Returns:
- The host name from the request.
-
getPort
public int getPort()
Returns the Internet Protocol (IP) port number of the interface on which the request was received.- Returns:
- The port number from the request.
-
getContextPath
public java.lang.String getContextPath()
Returns the portion of the request URL representing the context path.- Returns:
- The context path from the request URL.
-
getServletPath
public java.lang.String getServletPath()
Returns the portion of the request URL representing the servlet path.- Returns:
- The servlet path parsed out of the request URL.
-
isSecure
public boolean isSecure()
Tells whether the request has been encrypted over HTTPS.- Returns:
trueif the request was sent over HTTPS,falseotherwise (regular HTTP).
-
getProtocol
public java.lang.String getProtocol()
Returns the name of the HTTP protocol that the request is using.- Returns:
- The
"http"or"https"protocol string depending on theisSecure()setting.
-
getLocation
public java.net.URL getLocation()
Returns the location of this servlet.- Returns:
- The
URLassociated with this servlet.
-
getParameters
public QueryDictionary getParameters()
Returns the servlet's parameter dictionary, which holds the values passed in the HTTP request query string.- Returns:
- The set of parameters passed in this query.
-
getRequestHeaders
public QueryDictionary getRequestHeaders()
Returns the servlet's request header dictionary, which holds the HTTP request headers.- Returns:
- The set of request headers set in this query.
-
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.- Returns:
- The current set of response headers to return to the client.
-
prepare
protected void prepare() throws javax.servlet.ServletExceptionPrepares a servlet for request execution. This method is called immediately prior to thevalidate(Query.Method, Path)method.The default implementation is a no-op.
- Throws:
javax.servlet.ServletException- on any kind of error.
-
dispose
protected void dispose() throws javax.servlet.ServletExceptionDisposes any resources allocated inprepare(). This method is guaranteed to be called even if the HTTP handler method throws.The default implementation is a no-op.
- Throws:
javax.servlet.ServletException- on any kind of error.
-
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- The type of query this is.path- The path to the server resources.- Throws:
QueryException- if there is a problem, Houston.
-
doGet
protected java.lang.Object doGet(QueryServlet.Path path) throws QueryException
Handles an HTTP GET request. The default implementation throws an HTTP 405 query exception.- Parameters:
path- The request path.- Returns:
- The result of the GET.
- Throws:
QueryException- on any error.
-
doPost
protected java.net.URL doPost(QueryServlet.Path path, java.lang.Object value) throws QueryException
Handles an HTTP POST request. The default implementation throws an HTTP 405 query exception.- Parameters:
path- The path of this request.value- The value parsed from the POST request data.- Returns:
- A URL containing the location of the created resource, or
nullif operation did not result in the creation of a resource. - Throws:
QueryException- on errors.
-
doPut
protected boolean doPut(QueryServlet.Path path, java.lang.Object value) throws QueryException
Handles an HTTP GET request. The default implementation throws an HTTP 405 query exception.- Parameters:
path- The server path for this request.value- The value parsed from the PUT request data.- Returns:
trueif the operation resulted in the creation of a resource;false, otherwise.- Throws:
QueryException- on any error.
-
doDelete
protected void doDelete(QueryServlet.Path path) throws QueryException
Handles an HTTP DELETE request. The default implementation throws an HTTP 405 query exception.- Parameters:
path- The server path for this request.- Throws:
QueryException- if there was a problem.
-
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- Type of query this serializer will apply to.path- The server path this is intended for.- Returns:
- The newly created serializer for this request.
- Throws:
QueryException- if there is a problem.
-
service
protected void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException- Overrides:
servicein classjavax.servlet.http.HttpServlet- Throws:
java.io.IOExceptionjavax.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:
doGetin classjavax.servlet.http.HttpServlet- Throws:
java.io.IOExceptionjavax.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:
doPostin classjavax.servlet.http.HttpServlet- Throws:
java.io.IOExceptionjavax.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:
doPutin classjavax.servlet.http.HttpServlet- Throws:
java.io.IOExceptionjavax.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:
doDeletein classjavax.servlet.http.HttpServlet- Throws:
java.io.IOExceptionjavax.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:
doHeadin classjavax.servlet.http.HttpServlet- Throws:
java.io.IOExceptionjavax.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:
doOptionsin classjavax.servlet.http.HttpServlet- Throws:
java.io.IOExceptionjavax.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:
doTracein classjavax.servlet.http.HttpServlet- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
-