Class RestServlet
- All Implemented Interfaces:
- jakarta.servlet.Servlet,- jakarta.servlet.ServletConfig,- Serializable
- Direct Known Subclasses:
- BasicRestServlet,- LoadConfigResource,- SpringRestServlet
   The RestServlet class is the entry point for your REST resources.
   It extends directly from 
   When the servlet RestContext object that holds all the configuration
   information about your resource in a read-only object.
 
Notes:
- 
      Users will typically extend from BasicRestServletorBasicRestServletGroupinstead of this class directly.
See Also:
- 
Field SummaryFields inherited from class jakarta.servlet.http.HttpServletLEGACY_DO_HEAD
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoiddestroy()protected voidMain logger method.Returns the read-only context object that contains all the configuration information about this resource.getPath()Returns the path for this resource as defined by the @Rest(path) annotation or RestContext.Builder.path(String) method concatenated with those on all parent classes.Returns the current thread-local HTTP request.Returns the current thread-local HTTP response.voidinit(jakarta.servlet.ServletConfig servletConfig) voidLog a message.voidLog a message.voidservice(jakarta.servlet.http.HttpServletRequest r1, jakarta.servlet.http.HttpServletResponse r2) The main service method.protected voidsetContext(RestContext context) Sets the context object for this servlet.Methods inherited from class jakarta.servlet.http.HttpServletdoDelete, doGet, doHead, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, isSensitiveHeader, serviceMethods inherited from class jakarta.servlet.GenericServletgetInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
- 
Constructor Details- 
RestServletpublic RestServlet()
 
- 
- 
Method Details- 
initpublic void init(jakarta.servlet.ServletConfig servletConfig) throws jakarta.servlet.ServletException - Specified by:
- initin interface- jakarta.servlet.Servlet
- Overrides:
- initin class- jakarta.servlet.http.HttpServlet
- Throws:
- jakarta.servlet.ServletException
 
- 
setContextSets the context object for this servlet.This method is effectively a no-op if init(ServletConfig)has already been called.- Parameters:
- context- Sets the context object on this servlet.
- Throws:
- jakarta.servlet.ServletException- If error occurred during initialization.
 
- 
getPathReturns the path for this resource as defined by the @Rest(path) annotation or RestContext.Builder.path(String) method concatenated with those on all parent classes.- Returns:
- The path defined on this servlet, or an empty string if not specified.
 
- 
servicepublic void service(jakarta.servlet.http.HttpServletRequest r1, jakarta.servlet.http.HttpServletResponse r2) throws jakarta.servlet.ServletException, InternalServerError, IOException The main service method.Subclasses can optionally override this method if they want to tailor the behavior of requests. - Overrides:
- servicein class- jakarta.servlet.http.HttpServlet
- Throws:
- jakarta.servlet.ServletException
- InternalServerError
- IOException
 
- 
destroy- Specified by:
- destroyin interface- jakarta.servlet.Servlet
- Overrides:
- destroyin class- jakarta.servlet.GenericServlet
 
- 
getContextReturns the read-only context object that contains all the configuration information about this resource.This object is null during the call toinit(ServletConfig)but is populated by the timeGenericServlet.init()is called.Resource classes that don't extend from RestServletcan add the following method to their class to get access to this context object:public void init(RestServletContextcontext )throws Exception;- Returns:
- The context information on this servlet.
 
- 
logLog a message.Subclasses can intercept the handling of these messages by overriding doLog(Level, Throwable, Supplier).- Parameters:
- level- The log level.
- msg- The message to log.
- args- Optional- MessageFormat-style arguments.
 
- 
logLog a message.Subclasses can intercept the handling of these messages by overriding doLog(Level, Throwable, Supplier).- Parameters:
- level- The log level.
- cause- The cause.
- msg- The message to log.
- args- Optional- MessageFormat-style arguments.
 
- 
doLogMain logger method.The default behavior logs a message to the Java logger of the class name. Subclasses can override this method to implement their own logger handling. - Parameters:
- level- The log level.
- cause- Optional throwable.
- msg- The message to log.
 
- 
getRequestReturns the current thread-local HTTP request.- Returns:
- The current thread-local HTTP request, or null if it wasn't created.
 
- 
getResponseReturns the current thread-local HTTP response.- Returns:
- The current thread-local HTTP response, or null if it wasn't created.
 
 
-