Class RestSession

java.lang.Object
org.apache.juneau.ContextSession
org.apache.juneau.rest.RestSession

public class RestSession extends ContextSession
Represents a single HTTP request.
Notes:
  • This class is not thread safe.
  • Constructor Details

  • Method Details

    • create

      public static RestSession.Builder create(RestContext ctx)
      Creates a builder of this object.
      Parameters:
      ctx - The context creating this builder.
      Cannot be null.
      Returns:
      A new builder.
    • debug

      public RestSession debug(boolean value) throws IOException
      Enables or disabled debug mode on this call.
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
      Throws:
      IOException - Occurs if request content could not be cached into memory.
    • exception

      Identifies that an exception occurred during this call.
      Parameters:
      value - The thrown exception.
      Can be null (will clear the exception attribute and remove the exception from the bean store).
      Returns:
      This object.
    • finish

      public RestSession finish()
      Called at the end of a call to finish any remaining tasks such as flushing buffers and logging the response.
      Returns:
      This object.
    • getBeanStore

      Returns the bean store of this call.
      Returns:
      The bean store of this call.
    • getContext

      Returns the context that created this call.
      Overrides:
      getContext in class ContextSession
      Returns:
      The context that created this call.
    • getException

      Returns the exception that occurred during this call.
      Returns:
      The exception that occurred during this call.
    • getMethod

      public String getMethod() throws NotFound
      Returns the HTTP method name.
      Returns:
      The HTTP method name, always uppercased.
      Throws:
      NotFound - If the method parameter contains invalid/malformed characters.
    • getOpSession

      Returns the operation session of this REST session.

      The operation session is created once the Java method to be invoked has been determined.

      Returns:
      The operation session of this REST session.
      Throws:
      InternalServerError - If operation session has not been created yet.
    • getPathInfo

      public String getPathInfo()
      Shortcut for calling getRequest().getPathInfo().
      Returns:
      The request servlet path info.
    • getPathInfoUndecoded

      Same as getPathInfo() but doesn't decode encoded characters.
      Returns:
      The undecoded request servlet path info.
    • getPathVars

      Returns resolved @Resource(path) variable values on this call.
      Returns:
      Resolved @Resource(path) variable values on this call.
    • getQueryParams

      Returns the query parameters on the request.

      Unlike ServletRequest.getParameterMap(), this doesn't parse the content if it's a POST.

      Returns:
      The query parameters on the request.
    • getRequest

      public jakarta.servlet.http.HttpServletRequest getRequest()
      Returns the HTTP servlet request of this REST call.
      Returns:
      the HTTP servlet request of this REST call.
    • getResource

      public Object getResource()
      Returns the REST object.
      Returns:
      The rest object.
    • getResponse

      public jakarta.servlet.http.HttpServletResponse getResponse()
      Returns the HTTP servlet response of this REST call.
      Returns:
      the HTTP servlet response of this REST call.
    • getServletPath

      Shortcut for calling getRequest().getServletPath().
      Returns:
      The request servlet path.
    • getStatus

      public int getStatus()
      Shortcut for calling getRequest().getStatus().
      Returns:
      The response status code.
    • getUrlPath

      public UrlPath getUrlPath()
      Returns the request path info as a UrlPath bean.
      Returns:
      The request path info as a UrlPath bean.
    • getUrlPathMatch

      Returns the URL path pattern match on this call.
      Returns:
      The URL path pattern match on this call.
    • logger

      public RestSession logger(CallLogger value)
      Sets the logger to use when logging this call.
      Parameters:
      value - The new value for this setting.
      Can be null (will use the default logger from the context if available).
      Returns:
      This object.
    • run

      public void run() throws Throwable
      Runs this session.

      Does the following:

      1. Finds the Java method to invoke and creates a RestOpSession for it.
      2. Invokes RestPreCall methods by calling RestContext.preCall(RestOpSession).
      3. Invokes Java method by calling RestOpSession.run().
      4. Invokes RestPostCall methods by calling RestContext.postCall(RestOpSession).
      5. If the Java method produced output, finds the response processor for it and runs it by calling RestContext.processResponse(RestOpSession).
      6. If no Java method matched, generates a 404/405/412 by calling RestContext.handleNotFound(RestSession).
      Throws:
      Throwable - Any throwable can be thrown.
    • status

      public RestSession status(int value)
      Sets the HTTP status on this call.
      Parameters:
      value - The status code.
      Returns:
      This object.
    • status

      public RestSession status(StatusLine value)
      Sets the HTTP status on this call.
      Parameters:
      value - The status code.
      Can be null (ignored).
      Returns:
      This object.
    • urlPathMatch

      Sets the URL path pattern match on this call.
      Parameters:
      value - The match pattern.
      Can be null.
      Returns:
      This object.
    • properties

      Description copied from class: ContextSession
      Returns the properties on this bean as a map for debugging.
      Overrides:
      properties in class ContextSession
      Returns:
      The properties on this bean as a map for debugging.