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.
See Also:
  • 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.
      Returns:
      A new builder.
    • 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.
      Returns:
      This object.
    • 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.
    • 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.
      Returns:
      This object.
    • exception

      Identifies that an exception occurred during this call.
      Parameters:
      value - The thrown exception.
      Returns:
      This object.
    • urlPathMatch

      Sets the URL path pattern match on this call.
      Parameters:
      value - The match pattern.
      Returns:
      This object.
    • 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.
    • 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.
    • getBeanStore

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

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

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

      Returns the exception that occurred during this call.
      Returns:
      The exception that occurred during this call.
    • 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.
    • getServletPath

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

      public UrlPath getUrlPath()
      Returns the request path info as a UrlPath bean.
      Returns:
      The request path info as a UrlPath bean.
    • 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.
    • 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.
    • getMethod

      public String getMethod()
      Returns the HTTP method name.
      Returns:
      The HTTP method name, always uppercased.
    • getStatus

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

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

      public Object getResource()
      Returns the REST object.
      Returns:
      The rest object.
    • 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.
    • 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.