public abstract class RestServlet extends HttpServlet
Constructor and Description |
---|
RestServlet() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
protected RestContext |
getContext()
Returns the read-only context object that contains all the configuration information about this resource.
|
String |
getPath()
Returns the path defined on this servlet if it's defined via
RestResource.path() . |
RestContextProperties |
getProperties()
Convenience method for calling
|
RestRequest |
getRequest()
Returns the current HTTP request.
|
RestResponse |
getResponse()
Returns the current HTTP response.
|
RestContextBuilder |
getServletConfig() |
void |
init(ServletConfig servletConfig) |
void |
log(Level level,
String msg,
Object... args)
Log a message.
|
void |
log(Level level,
Throwable cause,
String msg,
Object... args)
Log a message.
|
void |
log(String msg) |
void |
log(String msg,
Throwable cause) |
void |
logObjects(Level level,
String msg,
Object... args)
Log a message.
|
void |
service(HttpServletRequest r1,
HttpServletResponse r2)
The main service method.
|
void |
setContext(RestContext context)
Sets the context object for this servlet.
|
RestServlet |
setRestResourceResolver(RestResourceResolver resourceResolver)
Sets the resource resolver to use for this servlet and all child servlets.
|
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
getInitParameter, getInitParameterNames, getServletContext, getServletInfo, getServletName, init
public RestServlet()
public final void init(ServletConfig servletConfig) throws ServletException
init
in interface Servlet
init
in class GenericServlet
ServletException
public void setContext(RestContext context) throws ServletException
context
- Sets the context object on this servlet.ServletException
- If error occurred during post-initialiation.public RestServlet setRestResourceResolver(RestResourceResolver resourceResolver)
This method can be called immediately following object construction, but must be called before init(ServletConfig)
is called.
Otherwise calling this method will have no effect.
resourceResolver
- The resolver instance. Can be public String getPath()
RestResource.path()
.public RestContextBuilder getServletConfig()
getServletConfig
in interface Servlet
getServletConfig
in class GenericServlet
protected RestContext getContext()
This object is init(ServletConfig)
but is populated by the time
GenericServlet.init()
is called.
Resource classes that don't extend from RestServlet
can add the following method to their class to get
access to this context object:
public RestContextProperties getProperties()
RestContextProperties
.RestContext.getProperties()
public void log(String msg)
log
in class GenericServlet
public void log(String msg, Throwable cause)
log
in class GenericServlet
public void log(Level level, String msg, Object... args)
level
- The log level.msg
- The message to log.args
- Optional MessageFormat
-style arguments.public void logObjects(Level level, String msg, Object... args)
level
- The log level.msg
- The message to log.args
- Optional MessageFormat
-style arguments.public void log(Level level, Throwable cause, String msg, Object... args)
level
- The log level.cause
- The cause.msg
- The message to log.args
- Optional MessageFormat
-style arguments.public void service(HttpServletRequest r1, HttpServletResponse r2) throws ServletException, InternalServerError, IOException
Subclasses can optionally override this method if they want to tailor the behavior of requests.
service
in class HttpServlet
ServletException
InternalServerError
IOException
public void destroy()
destroy
in interface Servlet
destroy
in class GenericServlet
public RestRequest getRequest()
public RestResponse getResponse()
Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.